|
NAMEData::Visitor::Callback - A Data::Visitor with callbacks. VERSIONversion 0.32 SYNOPSIS use Data::Visitor::Callback;
my $v = Data::Visitor::Callback->new(
# you can provide callbacks
# $_ will contain the visited value
value => sub { ... },
array => sub { ... },
# you can also delegate to method names
# this specific example will force traversal on objects, by using the
# 'visit_ref' callback which normally traverse unblessed references
object => "visit_ref",
# you can also use class names as callbacks
# the callback will be invoked on all objects which inherit that class
'Some::Class' => sub {
my ( $v, $obj ) = @_; # $v is the visitor
...
},
);
$v->visit( $some_perl_value );
DESCRIPTIONThis is a Data::Visitor subclass that lets you invoke callbacks instead of needing to subclass yourself. METHODS
CALLBACKSUse these keys for the corresponding callbacks. The callback is in the form: sub {
my ( $visitor, $data ) = @_;
# or you can use $_, it's aliased
return $data; # or modified data
}
Within the callback $_ is aliased to the data, and this is also passed in the parameter list. Any method can also be used as a callback: object => "visit_ref", # visit objects anyway
SUPPORTBugs may be submitted through the RT bug tracker <https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Visitor> (or bug-Data-Visitor@rt.cpan.org <mailto:bug-Data-Visitor@rt.cpan.org>). AUTHORS
COPYRIGHT AND LICENCEThis software is copyright (c) 2023 by Yuval Kogman. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
|