Data::FetchPath - "eval"able paths to your complex data values
Version 0.02
Quick summary of what the module does.
use Data::FetchPath 'path'; use Test::Most; my $data = { foo => 3, bar => [qw/ this that 3 /], 3 => undef, baz => { trois => 3, quatre => [qw/ 1 2 3 4 /], } }; my $target_value = 3; ok $paths = path( $data, $target_value ), 'Fetching paths for matching data should succeed'; my @expected = sort qw( {bar}[2] {baz}{trois} {baz}{quatre}[2] {foo} ); eq_or_diff $path, \@expected, '... and it should return all paths to data values found'; for ( 0 .. $#expected ) { my $found_value = eval "\$data->$expected[$_]"; is $found_value, $target_value, '... and all values should match the value you looked for'; } }
path
Exported on demand via:
use Data::FetchPath 'path'; my $paths = path($data_structure, $value); my $paths = path($data_structure, $regex);
Passed a data structure and either a scalar value or a regex (qr/foo.*bar/), this function will return an array reference to the paths to said value. Each path is suitable for using eval against said data structure:
qr/foo.*bar/
eval
my %data = ( one => 'uno', two => 'dos', three => 'tres', ); # find values with the letter 'o' in them my $paths = path(\%data, qr/o/); foreach my $path (@$data) { print eval "\$data$path\n"; } __END__ uno dos
Currently the data structure must be an array or hash reference. The value must be a scalar or a regular expression.
Curtis "Ovid" Poe, <ovid at cpan.org>
<ovid at cpan.org>
Please report any bugs or feature requests to bug-data-fetchpath at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data-FetchPath. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-data-fetchpath at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Data::FetchPath
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Data-FetchPath
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Data-FetchPath
CPAN Ratings
http://cpanratings.perl.org/d/Data-FetchPath
Search CPAN
http://search.cpan.org/dist/Data-FetchPath
Copyright 2008 Curtis "Ovid" Poe, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Data::FetchPath, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::FetchPath
CPAN shell
perl -MCPAN -e shell install Data::FetchPath
For more information on module installation, please visit the detailed CPAN module installation guide.