1Tree::Simple::Visitor::UPsaetrhTCooRnotorti(b3u)ted PerlTrDeoec:u:mSeinmtpaltei:o:nVisitor::PathToRoot(3)
2
3
4
6 Tree::Simple::Visitor::PathToRoot - A Visitor for finding the path back
7 a Tree::Simple object's root
8
10 use Tree::Simple::Visitor::PathToRoot;
11
12 # create an instance of our visitor
13 my $visitor = Tree::Simple::Visitor::PathToRoot->new();
14
15 # pass the visitor to a Tree::Simple object
16 $tree->accept($visitor);
17
18 # now get the accumulated path as a string
19 # with the '/' character as the delimiter
20 print $visitor->getPathAsString("/");
21
22 # include the tree's trunk in your
23 # output as well
24 $visitor->includeTrunk();
25
26 # for more complex node objects, you can specify
27 # a node filter which will be used to extract the
28 # information desired from each node
29 $visitor->setNodeFilter(sub {
30 my ($t) = @_;
31 return $t->getNodeValue()->description();
32 });
33
34 # you can also get the path back as an array
35 my @path = $visitor->getPath();
36
38 Given a Tree::Simple object, this Visitor will find the path back to
39 the tree's root node.
40
42 new There are no arguments to the constructor the object will be in its
43 default state. You can use the "includeTrunk" and "setNodeFilter"
44 methods to customize its behavior.
45
46 includeTrunk ($boolean)
47 Based upon the value of $boolean, this will tell the visitor to
48 collect the trunk of the tree as well.
49
50 setNodeFilter ($filter_function)
51 This method accepts a CODE reference as its $filter_function
52 argument and throws an exception if it is not a code reference.
53 This code reference is used to filter the tree nodes as they are
54 collected. This can be used to customize output, or to gather
55 specific information from a more complex tree node. The filter
56 function should accept a single argument, which is the current
57 Tree::Simple object.
58
59 visit ($tree)
60 This is the method that is used by Tree::Simple's "accept" method.
61 It can also be used on its own, it requires the $tree argument to
62 be a Tree::Simple object (or derived from a Tree::Simple object),
63 and will throw and exception otherwise.
64
65 getPath
66 This will return the collected path as an array, or in scalar
67 context, as an array reference.
68
69 getPathAsString ($delimiter)
70 This will return the collected path as a string with the path
71 elements joined by a $delimiter. If no $delimiter is specified, the
72 default (', ') will be used.
73
75 None that I am aware of. Of course, if you find a bug, let me know, and
76 I will be sure to fix it.
77
79 See the CODE COVERAGE section in Tree::Simple::VisitorFactory for more
80 information.
81
83 These Visitor classes are all subclasses of Tree::Simple::Visitor,
84 which can be found in the Tree::Simple module, you should refer to that
85 module for more information.
86
88 stevan little, <stevan@iinteractive.com>
89
91 Copyright 2004, 2005 by Infinity Interactive, Inc.
92
93 <http://www.iinteractive.com>
94
95 This library is free software; you can redistribute it and/or modify it
96 under the same terms as Perl itself.
97
98
99
100perl v5.34.0 2022-01-2T1ree::Simple::Visitor::PathToRoot(3)