.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "Data::Visitor::Callback 3"
.TH Data::Visitor::Callback 3 "2020-08-02" "perl v5.26.3" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
Data::Visitor::Callback \- A Data::Visitor with callbacks.
.SH "VERSION"
.IX Header "VERSION"
version 0.31
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\& 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
\& # \*(Aqvisit_ref\*(Aq 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
\&
\& \*(AqSome::Class\*(Aq => sub {
\& my ( $v, $obj ) = @_; # $v is the visitor
\&
\& ...
\& },
\& );
\&
\& $v\->visit( $some_perl_value );
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
This is a Data::Visitor subclass that lets you invoke callbacks instead of
needing to subclass yourself.
.SH "METHODS"
.IX Header "METHODS"
.ie n .IP "new %opts, %callbacks" 4
.el .IP "new \f(CW%opts\fR, \f(CW%callbacks\fR" 4
.IX Item "new %opts, %callbacks"
Construct a new visitor.
.Sp
The options supported are:
.RS 4
.IP "ignore_return_values" 4
.IX Item "ignore_return_values"
When this is true (off by default) the return values from the callbacks are
ignored, thus disabling the fmapping behavior as documented in
Data::Visitor.
.Sp
This is useful when you want to modify \f(CW$_\fR directly
.IP "tied_as_objects" 4
.IX Item "tied_as_objects"
Whether or not to visit the \*(L"tied\*(R" in perlfunc of a tied structure instead of
pretending the structure is just a normal one.
.Sp
See \*(L"visit_tied\*(R" in Data::Visitor.
.RE
.RS 4
.RE
.SH "CALLBACKS"
.IX Header "CALLBACKS"
Use these keys for the corresponding callbacks.
.PP
The callback is in the form:
.PP
.Vb 2
\& sub {
\& my ( $visitor, $data ) = @_;
\&
\& # or you can use $_, it\*(Aqs aliased
\&
\& return $data; # or modified data
\& }
.Ve
.PP
Within the callback \f(CW$_\fR is aliased to the data, and this is also passed in the
parameter list.
.PP
Any method can also be used as a callback:
.PP
.Vb 1
\& object => "visit_ref", # visit objects anyway
.Ve
.IP "visit" 4
.IX Item "visit"
Called for all values
.IP "value" 4
.IX Item "value"
Called for non objects, non container (hash, array, glob or scalar ref) values.
.IP "ref_value" 4
.IX Item "ref_value"
Called after \f(CW\*(C`value\*(C'\fR, for references to regexes, globs and code.
.IP "plain_value" 4
.IX Item "plain_value"
Called after \f(CW\*(C`value\*(C'\fR for non references.
.IP "object" 4
.IX Item "object"
Called for blessed objects.
.Sp
Since \*(L"visit_object\*(R" in Data::Visitor will not recurse downwards unless you
delegate to \f(CW\*(C`visit_ref\*(C'\fR, you can specify \f(CW\*(C`visit_ref\*(C'\fR as the callback for
\&\f(CW\*(C`object\*(C'\fR in order to enter objects.
.Sp
It is recommended that you specify the classes (or base classes) you want
though, instead of just visiting any object forcefully.
.IP "Some::Class" 4
.IX Item "Some::Class"
You can use any class name as a callback. This is called only after the
\&\f(CW\*(C`object\*(C'\fR callback.
.Sp
If the object \f(CW\*(C`isa\*(C'\fR the class then the callback will fire.
.Sp
These callbacks are called from least derived to most derived by comparing the
classes' \f(CW\*(C`isa\*(C'\fR at construction time.
.IP "object_no_class" 4
.IX Item "object_no_class"
Called for every object that did not have a class callback.
.IP "object_final" 4
.IX Item "object_final"
The last callback called for objects, useful if you want to post process the
output of any class callbacks.
.IP "array" 4
.IX Item "array"
Called for array references.
.IP "hash" 4
.IX Item "hash"
Called for hash references.
.IP "glob" 4
.IX Item "glob"
Called for glob references.
.IP "scalar" 4
.IX Item "scalar"
Called for scalar references.
.IP "tied" 4
.IX Item "tied"
Called on the return value of \f(CW\*(C`tied\*(C'\fR for all tied containers. Also passes in
the variable as the second argument.
.IP "seen" 4
.IX Item "seen"
Called for a reference value encountered a second time.
.Sp
Passes in the result mapping as the second argument.
.SH "SUPPORT"
.IX Header "SUPPORT"
Bugs may be submitted through the \s-1RT\s0 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>).
.SH "AUTHORS"
.IX Header "AUTHORS"
.IP "\(bu" 4
Yuval Kogman <nothingmuch@woobling.org>
.IP "\(bu" 4
Marcel GrĂ¼nauer <marcel@cpan.org>
.SH "COPYRIGHT AND LICENCE"
.IX Header "COPYRIGHT AND LICENCE"
This software is copyright (c) 2020 by Yuval Kogman.
.PP
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.