Data::V...Callback(3)
π NAME π
okay so you're reading the Data::V...Callback(3) page from User Contributed Perl Documentation, and it's all about Data::Visitor::Callback β literally a Data::Visitor with callbacks. That's the whole vibe, bestie. β¨
π VERSION π
version 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 );
π¦ DESCRIPTION π¦
This is a subclass of Data::Visitor that lets you invoke callbacks instead of needing to subclass it yourself. No cap β that's the entire point, and it's giving "convenient" in the best way. π
π οΈ METHODS π οΈ
β¨ new %opts, %callbacks β¨
Construct a new visitor. Fresh visitor, main character energy. π
The options supported are:
ignore_return_valuesβ When this is true (off by default), the return values from the callbacks are ignored, which disables thefmappingbehavior as documented inData::Visitor. This is useful when you want to modify$_directly.tied_as_objectsβ Whether or not to visit the"tied" in perlfuncof a tied structure instead of pretending the structure is just a normal one. See"visit_tied" in Data::Visitor.
πͺ CALLBACKS πͺ
Use 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
visitβ Called for all values.valueβ Called for non objects, non container (hash, array, glob or scalar ref) values.ref_valueβ Called aftervalue, for references to regexes, globs and code.plain_valueβ Called aftervaluefor non references.objectβ Called for blessed objects. Since"visit_object" in Data::Visitorwill not recurse downwards unless you delegate tovisit_ref, you can specifyvisit_refas the callback forobjectin order to enter objects. It is recommended that you specify the classes (or base classes) you want though, instead of just visiting any object forcefully.Some::Classβ You can use any class name as a callback. This is called only after theobjectcallback. If the objectisathe class then the callback will fire. These callbacks are called from least derived to most derived by comparing the classes'isaat construction time.object_no_classβ Called for every object that did not have a class callback.object_finalβ The last callback called for objects, useful if you want to post process the output of any class callbacks.arrayβ Called for array references.hashβ Called for hash references.globβ Called for glob references.scalarβ Called for scalar references.tiedβ Called on the return value oftiedfor all tied containers. Also passes in the variable as the second argument.seenβ Called for a reference value encountered a second time. Passes in the result mapping as the second argument.
π«Ά SUPPORT π«Ά
Bugs 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 π
- Yuval Kogman
<nothingmuch@woobling.org> - Marcel GrΓΌnauer
<marcel@cpan.org>
πΈ COPYRIGHT AND LICENCE πΈ
This 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.
mwah π β this page came from perl v5.42.0 and is dated 2023-04-30; now go be iconic with your callbacks π«Άβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Data-Visitor 0.32-bp160.1.11 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms