I am working on the final revisions of the code and fleshing out the POD some more before putting it on CPAN. Any feedback on naming, usefulness, etc would be appreciated. It has similarities to Data::Walk, but I feel it is sufficiently different to justify a separate module.
Data::DeepFilter - Deep modification of structures using callbacks. Optional Copy-On-Write.
use Data::DeepFilter qw(:all); deepfilter( data => \%deep_hash, filter => filter_regex(qr/(abc)/, '\U\1') test => name_in(qw(foo bar)), );
Data::DeepFilter provides a mechanism for performing modifications to nodes within a deep structure. Optional support for Copy-On-Write, which protects the original structure.
my $filtered_copy = deepfilter( data => \%deep_hash, filter => \&filter, test => \&test, safe => 1, );
Applies &filter to every node of $data that &test returns true for.
$data can be an arrayref or hashref.
The default behaviour is destructive in that it changes the structure that was passed. This behaviour can be overridden by specifying 'safe'.
filter => filter_regex(qr/foo/,'bar')
test => name_in(qw(foo bar))
test => name_not_in(qw(foo bar))
test => name_like(qr/foo/)
test => name_not_like(qr/foo/)
sub filter_example { my ($value_ref) = @_; $$value_ref++; }
sub test_example { my ($name,$value_ref) = @_; return 1 if $name eq 'foo'; return 1 if $$value_ref > 5; return; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: RFC - Data::DeepFilter
by BrowserUk (Patriarch) on Aug 23, 2006 at 01:54 UTC | |
by imp (Priest) on Aug 23, 2006 at 02:13 UTC | |
by xdg (Monsignor) on Aug 23, 2006 at 11:32 UTC | |
by bsb (Priest) on Aug 24, 2006 at 01:55 UTC | |
Re: RFC - Data::DeepFilter
by Hofmator (Curate) on Aug 23, 2006 at 09:37 UTC | |
by revdiablo (Prior) on Aug 23, 2006 at 17:05 UTC | |
by imp (Priest) on Aug 23, 2006 at 17:24 UTC |