1Tree::Simple::Visitor::UFsienrdBCyoPnattrhi(b3u)ted PerlTrDeoec:u:mSeinmtpaltei:o:nVisitor::FindByPath(3)
2
3
4
6 Tree::Simple::Visitor::FindByPath - A Visitor for finding an element in
7 a Tree::Simple hierarchy with a path
8
10 use Tree::Simple::Visitor::FindByPath;
11
12 # create a visitor object
13 my $visitor = Tree::Simple::Visitor::FindByPath->new();
14
15 # set the search path for our tree
16 $visitor->setSearchPath(qw(1 1.2 1.2.2));
17
18 # pass the visitor to a tree
19 $tree->accept($visitor);
20
21 # fetch the result, which will
22 # be the Tree::Simple object that
23 # we have found, or undefined
24 my $result = $visitor->getResult() ⎪⎪ die "No Tree found";
25
26 # our result's node value should match
27 # the last element in our path
28 print $result->getNodeValue(); # this should print 1.2.2
29
31 Given a path and Tree::Simple hierarchy, this Visitor will attempt to
32 find the node specified by the path.
33
35 new There are no arguments to the constructor the object will be in its
36 default state. You can use the "setSearchPath" and "setNodeFilter"
37 methods to customize its behavior.
38
39 includeTrunk ($boolean)
40 Based upon the value of $boolean, this will tell the visitor to
41 include the trunk of the tree in the search as well.
42
43 setSearchPath (@path)
44 This is the path we will attempt to follow down the tree. We will
45 do a stringified comparison of each element of the path and the
46 current tree's node (or the value returned by the node filter if it
47 is set).
48
49 setNodeFilter ($filter_function)
50 This method accepts a CODE reference as its $filter_function argu‐
51 ment and throws an exception if it is not a code reference. This
52 code reference is used to filter the tree nodes as they are col‐
53 lected. This can be used to customize output, or to gather specific
54 information from a more complex tree node. The filter function
55 should accept a single argument, which is the current Tree::Simple
56 object.
57
58 visit ($tree)
59 This is the method that is used by Tree::Simple's "accept" method.
60 It can also be used on its own, it requires the $tree argument to
61 be a Tree::Simple object (or derived from a Tree::Simple object),
62 and will throw and exception otherwise.
63
64 getResult
65 This method will return the tree found at the specified path (set
66 by the "setSearchPath" method) or "undef" if no tree is found.
67
68 getResults
69 This method will return the tree's that make up the path specified
70 in "setSearchPath". In the case of a failed search, this can be
71 used to find the elements which did successfully match along the
72 way.
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 inforamtion.
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.8.8 2005-07-1T3ree::Simple::Visitor::FindByPath(3)