Subject: | Return value from callback always ignored |
http://search.cpan.org/~nuffin/Data-Visitor-0.18/lib/Data/Visitor/Callback.pm#CALLBACKS
contains the following:
sub {
my ( $visitor, $data ) = @_;
# or you can use $_, it's aliased
return $data; # or modified data
}
That implies that returning a value from a callback sub replaces the
original value referenced by $data, but that's not the behaviour I'm seeing:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Visitor::Callback;
use Data::Dumper;
my $data = {
action => 'original'
};
my $callbacks = {
value => sub {
my( $visitor, $data ) = @_;
# program gets to here and $data eq 'original'
return 'modified';
}
};
my $v = Data::Visitor::Callback->new( %$callbacks );
$v->visit( $data );
print Dumper $data;
The above program prints:
$VAR1 = {
'action' => 'original'
};
If I alter "return 'modified';" to either of the following:
s/$data/modified/;
$_ = 'modified';
Then I get the output I expected first time around:
$VAR1 = {
'action' => 'modified'
};
I've noticed that there's a constructor option called
ignore_return_values, but this is documented as being set to 0 by
default and dumping $v confirms this is the case here.
I'm not sure if this is a bug, a documentation issue, a misunderstanding
on my part about how this module is supposed to work, or a combination
of the three.