Add built local::lib
[catagits/Gitalist.git] / local-lib5 / man / man3 / Tree::Simple::Visitor.3pm
1 .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.3
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
5 .de Sh \" Subsection heading
6 .br
7 .if t .Sp
8 .ne 5
9 .PP
10 \fB\\$1\fR
11 .PP
12 ..
13 .de Sp \" Vertical space (when we can't use .PP)
14 .if t .sp .5v
15 .if n .sp
16 ..
17 .de Vb \" Begin verbatim text
18 .ft CW
19 .nf
20 .ne \\$1
21 ..
22 .de Ve \" End verbatim text
23 .ft R
24 .fi
25 ..
26 .\" Set up some character translations and predefined strings.  \*(-- will
27 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28 .\" double quote, and \*(R" will give a right double quote.  | will give a
29 .\" real vertical bar.  \*(C+ will give a nicer C++.  Capital omega is used to
30 .\" do unbreakable dashes and therefore won't be available.  \*(C` and \*(C'
31 .\" expand to `' in nroff, nothing in troff, for use with C<>.
32 .tr \(*W-|\(bv\*(Tr
33 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34 .ie n \{\
35 .    ds -- \(*W-
36 .    ds PI pi
37 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
39 .    ds L" ""
40 .    ds R" ""
41 .    ds C` ""
42 .    ds C' ""
43 'br\}
44 .el\{\
45 .    ds -- \|\(em\|
46 .    ds PI \(*p
47 .    ds L" ``
48 .    ds R" ''
49 'br\}
50 .\"
51 .\" If the F register is turned on, we'll generate index entries on stderr for
52 .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53 .\" entries marked with X<> in POD.  Of course, you'll have to process the
54 .\" output yourself in some meaningful fashion.
55 .if \nF \{\
56 .    de IX
57 .    tm Index:\\$1\t\\n%\t"\\$2"
58 ..
59 .    nr % 0
60 .    rr F
61 .\}
62 .\"
63 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
64 .\" way too many mistakes in technical documents.
65 .hy 0
66 .if n .na
67 .\"
68 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
70 .    \" fudge factors for nroff and troff
71 .if n \{\
72 .    ds #H 0
73 .    ds #V .8m
74 .    ds #F .3m
75 .    ds #[ \f1
76 .    ds #] \fP
77 .\}
78 .if t \{\
79 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80 .    ds #V .6m
81 .    ds #F 0
82 .    ds #[ \&
83 .    ds #] \&
84 .\}
85 .    \" simple accents for nroff and troff
86 .if n \{\
87 .    ds ' \&
88 .    ds ` \&
89 .    ds ^ \&
90 .    ds , \&
91 .    ds ~ ~
92 .    ds /
93 .\}
94 .if t \{\
95 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101 .\}
102 .    \" troff and (daisy-wheel) nroff accents
103 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110 .ds ae a\h'-(\w'a'u*4/10)'e
111 .ds Ae A\h'-(\w'A'u*4/10)'E
112 .    \" corrections for vroff
113 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115 .    \" for low resolution devices (crt and lpr)
116 .if \n(.H>23 .if \n(.V>19 \
117 \{\
118 .    ds : e
119 .    ds 8 ss
120 .    ds o a
121 .    ds d- d\h'-1'\(ga
122 .    ds D- D\h'-1'\(hy
123 .    ds th \o'bp'
124 .    ds Th \o'LP'
125 .    ds ae ae
126 .    ds Ae AE
127 .\}
128 .rm #[ #] #H #V #F C
129 .\" ========================================================================
130 .\"
131 .IX Title "Tree::Simple::Visitor 3"
132 .TH Tree::Simple::Visitor 3 "2007-11-11" "perl v5.8.7" "User Contributed Perl Documentation"
133 .SH "NAME"
134 Tree::Simple::Visitor \- Visitor object for Tree::Simple objects
135 .SH "SYNOPSIS"
136 .IX Header "SYNOPSIS"
137 .Vb 2
138 \&  use Tree::Simple;
139 \&  use Tree::Simple::Visitor;
140 .Ve
141 .PP
142 .Vb 2
143 \&  # create a visitor instance
144 \&  my $visitor = Tree::Simple::Visitor\->new();
145 .Ve
146 .PP
147 .Vb 10
148 \&  # create a tree to visit
149 \&  my $tree = Tree::Simple\->new(Tree::Simple\->ROOT)
150 \&                         \->addChildren(
151 \&                             Tree::Simple\->new("1.0"),
152 \&                             Tree::Simple\->new("2.0")
153 \&                                         \->addChild(
154 \&                                             Tree::Simple\->new("2.1.0")
155 \&                                             ),
156 \&                             Tree::Simple\->new("3.0")
157 \&                             );
158 .Ve
159 .PP
160 .Vb 4
161 \&  # by default this will collect all the 
162 \&  # node values in depth\-first order into 
163 \&  # our results 
164 \&  $tree\->accept($visitor);
165 .Ve
166 .PP
167 .Vb 2
168 \&  # get our results and print them
169 \&  print join ", ", $visitor\->getResults();  # prints "1.0, 2.0, 2.1.0, 3.0"
170 .Ve
171 .PP
172 .Vb 7
173 \&  # for more complex node objects, you can specify 
174 \&  # a node filter which will be used to extract the
175 \&  # information desired from each node
176 \&  $visitor\->setNodeFilter(sub { 
177 \&                my ($t) = @_;
178 \&                return $t\->getNodeValue()\->description();
179 \&                });
180 .Ve
181 .PP
182 .Vb 3
183 \&  # NOTE: this object has changed, but it still remains
184 \&  # backwards compatible to the older version, see the
185 \&  # DESCRIPTION section below for more details
186 .Ve
187 .SH "DESCRIPTION"
188 .IX Header "DESCRIPTION"
189 This object has been revised into what I think is more intelligent approach to Visitor objects. This is now a more suitable base class for building your own Visitors. It is also the base class for the visitors found in the \fBTree::Simple::VisitorFactory\fR distribution, which includes a number of useful pre-built Visitors.
190 .PP
191 While I have changed a number of things about this module, I have kept it backwards compatible to the old way of using it. So the original example code still works:
192 .PP
193 .Vb 6
194 \&  my @accumulator;
195 \&  my $visitor = Tree::Simple::Visitor\->new(sub {
196 \&                        my ($tree) = @_;  
197 \&                        push @accumlator, $tree\->getNodeValue();
198 \&                        }, 
199 \&                        Tree::Simple::Visitor\->RECURSIVE);
200 .Ve
201 .PP
202 .Vb 1
203 \&  $tree\->accept($visitor);
204 .Ve
205 .PP
206 .Vb 1
207 \&  print join ", ", @accumulator;  # prints "1.0, 2.0, 2.1.0, 3.0"
208 .Ve
209 .PP
210 But is better expressed as this:
211 .PP
212 .Vb 3
213 \&  my $visitor = Tree::Simple::Visitor\->new();                                                    
214 \&  $tree\->accept($visitor);        
215 \&  print join ", ", $visitor\->getResults();  # prints "1.0, 2.0, 2.1.0, 3.0"
216 .Ve
217 .PP
218 This object is still pretty much a wrapper around the Tree::Simple \f(CW\*(C`traverse\*(C'\fR method, and can be thought of as a depth-first traversal Visitor object.  
219 .SH "METHODS"
220 .IX Header "METHODS"
221 .ie n .IP "\fBnew ($func, \fB$depth\fB)\fR" 4
222 .el .IP "\fBnew ($func, \f(CB$depth\fB)\fR" 4
223 .IX Item "new ($func, $depth)"
224 The new style interface means that all arguments to the constructor are now optional. As a means of defining the usage of the old and new, when no arguments are sent to the constructor, it is assumed that the new style interface is being used. In the new style, the \f(CW$depth\fR is always assumed to be equivalent to \f(CW\*(C`RECURSIVE\*(C'\fR and the \f(CW$func\fR argument can be set with \f(CW\*(C`setNodeFilter\*(C'\fR instead. This is the recommended way of doing things now. If you have been using the old way, it is still there, and I will maintain backwards compatability for a few more version before removing it entirely. If you are using this module (and I don't even know if anyone actually is) you have been warned. Please contact me if this will be a problem.
225 .Sp
226 The old style constructor documentation is retained her for reference:
227 .Sp
228 The first argument to the constructor is a code reference to a function which expects a \fBTree::Simple\fR object as its only argument. The second argument is optional, it can be used to set the depth to which the function is applied. If no depth is set, the function is applied to the current \fBTree::Simple\fR instance. If \f(CW$depth\fR is set to \f(CW\*(C`CHILDREN_ONLY\*(C'\fR, then the function will be applied to the current \fBTree::Simple\fR instance and all its immediate children. If \f(CW$depth\fR is set to \f(CW\*(C`RECURSIVE\*(C'\fR, then the function will be applied to the current \fBTree::Simple\fR instance and all its immediate children, and all of their children recursively on down the tree. If no \f(CW$depth\fR is passed to the constructor, then the function will only be applied to the current \fBTree::Simple\fR object and none of its children.
229 .IP "\fBincludeTrunk ($boolean)\fR" 4
230 .IX Item "includeTrunk ($boolean)"
231 Based upon the value of \f(CW$boolean\fR, this will tell the visitor to collect the trunk of the tree as well. It is defaulted to false (\f(CW0\fR) in the new style interface, but is defaulted to true (\f(CW1\fR) in the old style interface.
232 .IP "\fBgetNodeFilter\fR" 4
233 .IX Item "getNodeFilter"
234 This method returns the \s-1CODE\s0 reference set with \f(CW\*(C`setNodeFilter\*(C'\fR argument.
235 .IP "\fBclearNodeFilter\fR" 4
236 .IX Item "clearNodeFilter"
237 This method clears node filter field.
238 .IP "\fBsetNodeFilter ($filter_function)\fR" 4
239 .IX Item "setNodeFilter ($filter_function)"
240 This method accepts a \s-1CODE\s0 reference as its \f(CW$filter_function\fR argument. This code reference is used to filter the tree nodes as they are collected. This can be used to customize output, or to gather specific information from a more complex tree node. The filter function should accept a single argument, which is the current Tree::Simple object.
241 .IP "\fBgetResults\fR" 4
242 .IX Item "getResults"
243 This method returns the accumulated results of the application of the node filter to the tree.
244 .IP "\fBsetResults\fR" 4
245 .IX Item "setResults"
246 This method should not really be used outside of this class, as it just would not make any sense to. It is included in this class and in this documenation to facilitate subclassing of this class for your own needs. If you desire to clear the results, then you can simply call \f(CW\*(C`setResults\*(C'\fR with no argument.
247 .IP "\fBvisit ($tree)\fR" 4
248 .IX Item "visit ($tree)"
249 The \f(CW\*(C`visit\*(C'\fR method accepts a \fBTree::Simple\fR and applies the function set in \f(CW\*(C`new\*(C'\fR or \f(CW\*(C`setNodeFilter\*(C'\fR appropriately. The results of this application can be retrieved with \f(CW\*(C`getResults\*(C'\fR
250 .SH "CONSTANTS"
251 .IX Header "CONSTANTS"
252 These constants are part of the old-style interface, and therefore will eventually be deprecated.
253 .IP "\fB\s-1RECURSIVE\s0\fR" 4
254 .IX Item "RECURSIVE"
255 If passed this constant in the constructor, the function will be applied recursively down the hierarchy of \fBTree::Simple\fR objects. 
256 .IP "\fB\s-1CHILDREN_ONLY\s0\fR" 4
257 .IX Item "CHILDREN_ONLY"
258 If passed this constant in the constructor, the function will be applied to the immediate children of the \fBTree::Simple\fR object. 
259 .SH "BUGS"
260 .IX Header "BUGS"
261 None that I am aware of. The code is pretty thoroughly tested (see \fB\s-1CODE\s0 \s-1COVERAGE\s0\fR section in \fBTree::Simple\fR) and is based on an (non\-publicly released) module which I had used in production systems for about 2 years without incident. Of course, if you find a bug, let me know, and I will be sure to fix it. 
262 .SH "SEE ALSO"
263 .IX Header "SEE ALSO"
264 I have written a set of pre-built Visitor objects, available on \s-1CPAN\s0 as \fBTree::Simple::VisitorFactory\fR.
265 .SH "AUTHOR"
266 .IX Header "AUTHOR"
267 stevan little, <stevan@iinteractive.com>
268 .SH "COPYRIGHT AND LICENSE"
269 .IX Header "COPYRIGHT AND LICENSE"
270 Copyright 2004\-2006 by Infinity Interactive, Inc.
271 .PP
272 <http://www.iinteractive.com>
273 .PP
274 This library is free software; you can redistribute it and/or modify
275 it under the same terms as Perl itself.