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

SYNOPSIS

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

DESCRIPTION

39       This is a Data::Visitor subclass that lets you invoke callbacks instead
40       of needing to subclass yourself.
41

METHODS

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

CALLBACKS

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

AUTHOR

143       Yuval Kogman <nothingmuch@woobling.org>
144
146               Copyright (c) 2006 Yuval Kogman. All rights reserved
147               This program is free software; you can redistribute
148               it and/or modify it under the same terms as Perl itself.
149
150
151
152perl v5.12.0                      2010-01-02        Data::Visitor::Callback(3)
Impressum