1Tree::Simple::Visitor::UGseetrAlCloDnetsrciebnudtTeerndetesP:(e:3rS)limDpolceu:m:eVnitsaittioorn::GetAllDescendents(3)
2
3
4
6 Tree::Simple::Visitor::GetAllDescendents - A Visitor for fetching all
7 the descendents of a Tree::Simple object
8
10 use Tree::Simple::Visitor::GetAllDescendents;
11
12 # create an instance of our visitor
13 my $visitor = Tree::Simple::Visitor::GetAllDescendents->new();
14
15 # pass the visitor to a Tree::Simple object
16 $tree->accept($visitor);
17
18 # you can also get the descendents
19 # back as an array of node values
20 my @descendents = $visitor->getDescendents();
21
22 # for more complex node objects, you can specify
23 # a node filter which will be used to extract the
24 # information desired from each node
25 $visitor->setNodeFilter(sub {
26 my ($t) = @_;
27 return $t->getNodeValue()->description();
28 });
29
31 Given a Tree::Simple instance this Visitor will return all the
32 descendents recursively on down the hierarchy.
33
35 new There are no arguments to the constructor the object will be in its
36 default state. You can use the "setNodeFilter" method to customize
37 its behavior.
38
39 setTraversalMethod ($visitor)
40 By default we will use Tree::Simple's built in depth-first (pre-
41 order) traverse method. If however, you desire the descendents to
42 be returned in a different ordering, this can be accomplished using
43 a different traversal method, you can supply a $visitor object
44 implementing that traversal type to this method (See
45 Tree::Simple::Visitor::BreadthFirstTraversal,
46 Tree::Simple::Visitor::PreOrderTraversal and
47 Tree::Simple::Visitor::PostOrderTraversal).
48
49 setNodeFilter ($filter_function)
50 This method accepts a CODE reference as its $filter_function
51 argument and throws an exception if it is not a code reference.
52 This code reference is used to filter the tree nodes as they are
53 collected. This can be used to customize output, or to gather
54 specific information from a more complex tree node. The filter
55 function should accept a single argument, which is the current
56 Tree::Simple 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 getAllDescendents
65 This method will give back and array of descendents in depth-first
66 order (pre-order) or in the order specified by the
67 "setTraversalMethod". If called in scalar context it will give an
68 array reference, in list context it will return a regular array.
69 This method is the same as calling "getResults".
70
72 None that I am aware of. Of course, if you find a bug, let me know, and
73 I will be sure to fix it.
74
76 See the CODE COVERAGE section in Tree::Simple::VisitorFactory for more
77 information.
78
80 These Visitor classes are all subclasses of Tree::Simple::Visitor,
81 which can be found in the Tree::Simple module, you should refer to that
82 module for more information.
83
85 stevan little, <stevan@iinteractive.com>
86
88 Copyright 2004, 2005 by Infinity Interactive, Inc.
89
90 <http://www.iinteractive.com>
91
92 This library is free software; you can redistribute it and/or modify it
93 under the same terms as Perl itself.
94
95
96
97perl v5.28.1 20T1r6e-e0:5:-S0i3mple::Visitor::GetAllDescendents(3)