1Data::Visitor::CallbackU(s3e)r Contributed Perl DocumentaDtaitoan::Visitor::Callback(3)
2
3
4

NAME

6       Data::Visitor::Callback - A Data::Visitor with callbacks.
7

VERSION

9       version 0.32
10

SYNOPSIS

12               use Data::Visitor::Callback;
13
14               my $v = Data::Visitor::Callback->new(
15                       # you can provide callbacks
16                       # $_ will contain the visited value
17
18                       value => sub { ... },
19                       array => sub { ... },
20
21
22                       # you can also delegate to method names
23                       # this specific example will force traversal on objects, by using the
24                       # 'visit_ref' callback which normally traverse unblessed references
25
26                       object => "visit_ref",
27
28
29                       # you can also use class names as callbacks
30                       # the callback will be invoked on all objects which inherit that class
31
32                       'Some::Class' => sub {
33                               my ( $v, $obj ) = @_; # $v is the visitor
34
35                               ...
36                       },
37               );
38
39               $v->visit( $some_perl_value );
40

DESCRIPTION

42       This is a Data::Visitor subclass that lets you invoke callbacks instead
43       of needing to subclass yourself.
44

METHODS

46       new %opts, %callbacks
47           Construct a new visitor.
48
49           The options supported are:
50
51           ignore_return_values
52               When this is true (off by default) the return values from the
53               callbacks are ignored, thus disabling the fmapping behavior as
54               documented in Data::Visitor.
55
56               This is useful when you want to modify $_ directly
57
58           tied_as_objects
59               Whether or not to visit the "tied" in perlfunc of a tied
60               structure instead of pretending the structure is just a normal
61               one.
62
63               See "visit_tied" in Data::Visitor.
64

CALLBACKS

66       Use these keys for the corresponding callbacks.
67
68       The callback is in the form:
69
70               sub {
71                       my ( $visitor, $data ) = @_;
72
73                       # or you can use $_, it's aliased
74
75                       return $data; # or modified data
76               }
77
78       Within the callback $_ is aliased to the data, and this is also passed
79       in the parameter list.
80
81       Any method can also be used as a callback:
82
83               object => "visit_ref", # visit objects anyway
84
85       visit
86           Called for all values
87
88       value
89           Called for non objects, non container (hash, array, glob or scalar
90           ref) values.
91
92       ref_value
93           Called after "value", for references to regexes, globs and code.
94
95       plain_value
96           Called after "value" for non references.
97
98       object
99           Called for blessed objects.
100
101           Since "visit_object" in Data::Visitor will not recurse downwards
102           unless you delegate to "visit_ref", you can specify "visit_ref" as
103           the callback for "object" in order to enter objects.
104
105           It is recommended that you specify the classes (or base classes)
106           you want though, instead of just visiting any object forcefully.
107
108       Some::Class
109           You can use any class name as a callback. This is called only after
110           the "object" callback.
111
112           If the object "isa" the class then the callback will fire.
113
114           These callbacks are called from least derived to most derived by
115           comparing the classes' "isa" at construction time.
116
117       object_no_class
118           Called for every object that did not have a class callback.
119
120       object_final
121           The last callback called for objects, useful if you want to post
122           process the output of any class callbacks.
123
124       array
125           Called for array references.
126
127       hash
128           Called for hash references.
129
130       glob
131           Called for glob references.
132
133       scalar
134           Called for scalar references.
135
136       tied
137           Called on the return value of "tied" for all tied containers. Also
138           passes in the variable as the second argument.
139
140       seen
141           Called for a reference value encountered a second time.
142
143           Passes in the result mapping as the second argument.
144

SUPPORT

146       Bugs may be submitted through the RT bug tracker
147       <https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Visitor> (or
148       bug-Data-Visitor@rt.cpan.org <mailto:bug-Data-Visitor@rt.cpan.org>).
149

AUTHORS

151       •   Yuval Kogman <nothingmuch@woobling.org>
152
153       •   Marcel Grünauer <marcel@cpan.org>
154
156       This software is copyright (c) 2023 by Yuval Kogman.
157
158       This is free software; you can redistribute it and/or modify it under
159       the same terms as the Perl 5 programming language system itself.
160
161
162
163perl v5.38.0                      2023-07-20        Data::Visitor::Callback(3)
Impressum