1Tree::Simple::Visitor::UTsoeNresCtoendtArrirbauyt(e3d)PTerrele:D:oSciummpelnet:a:tViiosnitor::ToNestedArray(3)
2
3
4

NAME

6       Tree::Simple::Visitor::ToNestedArray - A Visitor for creating nested
7       array trees from Tree::Simple objects.
8

SYNOPSIS

10         use Tree::Simple::Visitor::ToNestedArray;
11
12         my $visitor = Tree::Simple::Visitor::ToNestedArray->new();
13
14         # given this Tree::Simple tree
15         my $tree = Tree::Simple->new("Root")
16                       ->addChildren(
17                           Tree::Simple->new("Child1")
18                               ->addChildren(
19                                   Tree::Simple->new("GrandChild1"),
20                                   Tree::Simple->new("GrandChild2")
21                               ),
22                           Tree::Simple->new("Child2"),
23                       );
24
25         # include the trunk (Root)
26         $visitor->includeTrunk(1);
27
28         # visit the tree
29         $tree->accept($visitor);
30
31         my $array_tree = $visitor->getResults();
32         # this then creates the equivalent nested array tree:
33         # [
34         # 'Root', [
35         #     'Child1', [
36         #             'GrandChild1',
37         #             'GrandChild2'
38         #             ],
39         #     'Child2'
40         #     ]
41         # ]
42
43         # if you don't include the trunk (Root) then ...
44         $tree->accept($visitor);
45
46         my $array_tree = $visitor->getResults();
47         # this then creates the following nested array tree:
48         # [
49         #   'Child1', [
50         #           'GrandChild1',
51         #           'GrandChild2'
52         #           ],
53         #   'Child2'
54         # ]
55

DESCRIPTION

57       Given a tree constructed from a Tree::Simple heirarchy, this Visitor
58       will create the equivalent tree of nested arrays.
59

METHODS

61       new There are no arguments to the constructor the object will be in its
62           default state. You can use the "setNodeFilter" and "includTrunk"
63           methods to customize its behavior.
64
65       includTrunk ($boolean)
66           Setting the $boolean value to true (1) will cause the node value of
67           the tree's root to be included in the nested array output, setting
68           it to false will do the opposite.
69
70       setNodeFilter ($filter_function)
71           This method accepts a CODE reference as its $filter_function
72           argument and throws an exception if it is not a code reference.
73           This code reference is used to filter the tree nodes as they are
74           placed into the array tree. The $filter_function is passed a
75           Tree::Simple object, and is expected to return the value desired
76           for inclusion into the array tree.
77
78       visit ($tree)
79           This is the method that is used by Tree::Simple's "accept" method.
80           It can also be used on its own, it requires the $tree argument to
81           be a Tree::Simple object (or derived from a Tree::Simple object),
82           and will throw and exception otherwise.
83
84       getResults
85           This method will return the array tree constructed.
86

BUGS

88       None that I am aware of. Of course, if you find a bug, let me know, and
89       I will be sure to fix it.
90

CODE COVERAGE

92       See the CODE COVERAGE section in Tree::Simple::VisitorFactory for more
93       inforamtion.
94

SEE ALSO

96       These Visitor classes are all subclasses of Tree::Simple::Visitor,
97       which can be found in the Tree::Simple module, you should refer to that
98       module for more information.
99

AUTHOR

101       stevan little, <stevan@iinteractive.com>
102
104       Copyright 2004, 2005 by Infinity Interactive, Inc.
105
106       <http://www.iinteractive.com>
107
108       This library is free software; you can redistribute it and/or modify it
109       under the same terms as Perl itself.
110
111
112
113perl v5.12.0                      2005-0T7r-e1e4::Simple::Visitor::ToNestedArray(3)
Impressum