1Tree::Simple::Visitor::UFsienrdBCyoNnotdreiVbaultueedT(r3Pe)eer:l:SDiomcpulmee:n:tVaitsiiotnor::FindByNodeValue(3)
2
3
4
6 Tree::Simple::Visitor::FindByNodeValue - A Visitor for finding an ele‐
7 ment in a Tree::Simple hierarchy by node value
8
10 use Tree::Simple::Visitor::FindByNodeValue;
11
12 # create a visitor object
13 my $visitor = Tree::Simple::Visitor::FindByNodeValue->new();
14
15 # set the search path for our tree
16 $visitor->searchForNodeValue("My Tree Node");
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
27 Given a node value and Tree::Simple hierarchy, this Visitor will
28 attempt to find the node with the same node value.
29
31 new There are no arguments to the constructor the object will be in its
32 default state. You can use the "setNodeFilter", "setTraversal‐
33 Method", "includeTrunk" and "searchForNodeValue" methods to custom‐
34 ize its behavior.
35
36 includeTrunk ($boolean)
37 Based upon the value of $boolean, this will tell the visitor to
38 include the trunk of the tree in the search as well.
39
40 setTraversalMethod ($visitor)
41 By default we will use Tree::Simple's built in depth-first
42 (pre-order) traverse method. If however, you desire the tree to be
43 search in a different ordering, this can be accomplished using a
44 different traversal method, you can supply a $visitor object imple‐
45 menting that traversal type to this method (See Tree::Simple::Vis‐
46 itor::BreadthFirstTraversal, Tree::Simple::Visitor::PreOrderTraver‐
47 sal and Tree::Simple::Visitor::PostOrderTraversal).
48
49 searchForNodeValue ($node_value)
50 This is the node value we will attempt to find within the tree.
51
52 setNodeFilter ($filter_function)
53 This method accepts a CODE reference as its $filter_function argu‐
54 ment and throws an exception if it is not a code reference. This
55 code reference is used to further check the tree nodes as they are
56 searched and so can be used to customize search behavior. For
57 instance, you could to check against the node value as well as some
58 other criteria. The filter function should accept a single argu‐
59 ment, which is the current Tree::Simple object and return either
60 true (1) on success, or false (0) on failure.
61
62 visit ($tree)
63 This is the method that is used by Tree::Simple's "accept" method.
64 It can also be used on its own, it requires the $tree argument to
65 be a Tree::Simple object (or derived from a Tree::Simple object),
66 and will throw and exception otherwise.
67
68 getResult
69 This method will return the tree found with the specified node
70 value (set by the "searchForNodeValue" method) or "undef" if no
71 tree is found.
72
74 None that I am aware of. Of course, if you find a bug, let me know, and
75 I will be sure to fix it.
76
78 See the CODE COVERAGE section in Tree::Simple::VisitorFactory for more
79 inforamtion.
80
82 These Visitor classes are all subclasses of Tree::Simple::Visitor,
83 which can be found in the Tree::Simple module, you should refer to that
84 module for more information.
85
87 stevan little, <stevan@iinteractive.com>
88
90 Copyright 2004, 2005 by Infinity Interactive, Inc.
91
92 <http://www.iinteractive.com>
93
94 This library is free software; you can redistribute it and/or modify it
95 under the same terms as Perl itself.
96
97
98
99perl v5.8.8 2005T-r0e7e-:1:3Simple::Visitor::FindByNodeValue(3)