Data::Focus::Lens::HashArray::Recurse - recursively traverse a tree of hashes and arrays
use Data::Focus qw(focus); use Data::Focus::Lens::HashArray::Recurse; my $target = [ {foo => 1, bar => 2}, 3, [4, 5, 6], [], {} {hoge => 7} ]; my $lens = Data::Focus::Lens::HashArray::Recurse->new; my $result = focus($target)->over($lens, sub { $_[0] * 100 }); ## $result: ## [ ## {foo => 100, bar => 200}, ## 300, ## [400, 500, 600], ## [], ## {}, ## {hoge => 700} ## ]
Data::Focus::Lens::HashArray::Recurse is a Data::Focus::Lens class that recursively traverses a data structure made of hashes and arrays. It creates focal points on everything it finds on the traversal.
The traversal is depth-first. Siblings in a hash are traversed in random order. Siblings in an array are traversed from the index 0.
The constructor. Fields in %args are:
%args
immutable
If set to true, the target hash/array is treated as immutable. This means every updating operation using the $lens creates a new hash/array in a copy-on-write fashion.
$lens
See Data::Focus::Lens.
Toshio Ito, <toshioito at cpan.org>
<toshioito at cpan.org>
To install Data::Focus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Focus
CPAN shell
perl -MCPAN -e shell install Data::Focus
For more information on module installation, please visit the detailed CPAN module installation guide.