Code Monkey home page Code Monkey logo

data-reach's Introduction

Data-Reach

Data::Reach - Walk down or iterate through a nested Perl datastructure

=head1 SYNOPSIS

    # reach a subtree or a leaf under a nested datastructure
    use Data::Reach;
    my $node = reach $data_tree, @path; # @path may contain a mix of hash keys and array indices

    # do something with all paths through the datastructure ..
    my @result = map_paths {do_something_with(\@_, $_)} $data_tree;

    # .. or loop through all paths
    my $next_path = each_path $data_tree;
    while (my ($path, $val) = $next_path->()) {
      do_something_with($path, $val);
    }

    # import under a different name
    use Data::Reach reach => as => 'walk_down';
    my $node = walk_down $data_tree, @path;

    # optional changes of algorithm, lexically scoped
    { no Data::Reach  qw/peek_blessed use_overloads/;
      use Data::Reach reach_method => [qw/foo bar/];
      my $node = reach $object_tree, @path;
    }
    # after end of scope, back to the regular algorithm

=head1 DESCRIPTION

Perl supports nested datastructures : a hash may contain references to
other hashes or to arrays, which in turn may contain further references
to deeper structures -- see L<perldsc>. Walking down through such
structures usually involves nested loops, and possibly some tests on
C<ref $subtree> for finding out if the next level is an arrayref or a hashref.

The present module offers some utilities for easier handling of nested
datastructures :

=over

=item *

the C<reach> function finds a subtree or a leaf according to a given
C<@path> -- a list of hash keys or array indices. If there is no data
corresponding to that path, C<undef> is returned, without any autovivification
within the tree.

=item *

the C<map_paths> function applies a given code reference to all paths within the nested
datastructure.


=item *

the C<each_path> function returns an iterator over the nested datastructure; it can be
used in the same spirit as an C<each> statement over a simple hash, except that it will
walk through all paths within the nested datastructure

=back



INSTALLATION

To install this module, run the following commands:

	perl Build.PL
        perl Build
        perl Build test
        perl Build install

SUPPORT AND DOCUMENTATION

After installing, you can find documentation for this module with the
perldoc command.

    perldoc Data::Reach

You can also look for information at:

    https://metacpan.org/pod/Data::Reach


LICENSE AND COPYRIGHT

Copyright (C) 2015, 2022 Laurent Dami

This program is free software; you can redistribute it and/or modify it
under the terms of the the Artistic License (2.0). You may obtain a
copy of the full license at:

L<http://www.perlfoundation.org/artistic_license_2_0>


Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.