NAME
Data::Focus::Lens::HashArray::Recurse - recursively traverse a tree of hashes and arrays
SYNOPSIS
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}
## ]
DESCRIPTION
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.
CLASS METHODS
$lens = Data::Focus::Lens::HashArray::Recurse->new(%args)
The constructor. Fields in %args
are:
immutable
=> BOOL (optional, default: false)-
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.
OBJECT METHODS
apply_lens
See Data::Focus::Lens.
AUTHOR
Toshio Ito, <toshioito at cpan.org>