1Tree::Simple::Visitor::UFsreormNCeosntterdiHbausthe(d3T)Preerel::DSoicmupmleen:t:aVtiisointor::FromNestedHash(3)
2
3
4

NAME

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

SYNOPSIS

10         use Tree::Simple::Visitor::FromNestedHash;
11
12         my $visitor = Tree::Simple::Visitor::FromNestedHash->new();
13
14         # given this nested hash tree
15         my $hash_tree = {
16                       Root => {
17                               Child1 => {
18                                       GrandChild1 => {},
19                                       GrandChild2 => {}
20                                       },
21                               Child2 => {}
22                               }
23                       };
24
25         # set the array tree we
26         # are going to convert
27         $visitor->setHashTree($hash_tree);
28
29         $tree->accept($visitor);
30
31         # this then creates the equivalent Tree::Simple object:
32         # Tree::Simple->new("Root")
33         #     ->addChildren(
34         #         Tree::Simple->new("Child1")
35         #             ->addChildren(
36         #                 Tree::Simple->new("GrandChild1"),
37         #                 Tree::Simple->new("GrandChild2")
38         #             ),
39         #         Tree::Simple->new("Child2"),
40         #     );
41

DESCRIPTION

43       Given a tree constructed from nested hashes, this Visitor will create
44       the equivalent Tree::Simple hierarchy.
45

METHODS

47       new There are no arguments to the constructor the object will be in its
48           default state. You can use the "setNodeFilter" methods to customize
49           its behavior.
50
51       setNodeFilter ($filter_function)
52           This method accepts a CODE reference as its $filter_function
53           argument and throws an exception if it is not a code reference.
54           This code reference is used to filter the tree nodes as they are
55           created, the $filter_function is passed the node value extracted
56           from the hash prior to it being inserted into the tree being built.
57           The $filter_function is expected to return the value desired for
58           inclusion into the tree.
59
60       setHashTree ($hash_tree)
61           This method is used to set the $hash_tree that our Tree::Simple
62           hierarchy will be constructed from. It must be in the following
63           form:
64
65             {
66               Root => {
67                     Child1 => {
68                             GrandChild1 => {},
69                             GrandChild2 => {}
70                             },
71                     Child2 => {}
72                     }
73             }
74
75           Basically each key in the hash is considered a node, values are
76           ignored unless it is a hash reference with at least one key in it,
77           in which case it is interpreted as containing the children of the
78           node created from the key.
79
80           The tree is validated prior being accepted, if it fails validation
81           an exception will be thrown. The rules are as follows;
82
83           The hash tree must not be empty.
84               It makes not sense to create a tree out of nothing, so it is
85               assumed that this is a sign of something wrong.
86
87           The hash tree must be a single rooted tree.
88               The hash tree should have only one key in it's first level, if
89               it has more than one, then it is not a single rooted tree.
90
91           NOTE: Hash keys are sorted ascii-betically before being added to
92           the tree, this results in a somewhat more predictable hierarchy.
93
94       visit ($tree)
95           This is the method that is used by Tree::Simple's "accept" method.
96           It can also be used on its own, it requires the $tree argument to
97           be a Tree::Simple object (or derived from a Tree::Simple object),
98           and will throw and exception otherwise.
99

BUGS

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

CODE COVERAGE

105       See the CODE COVERAGE section in Tree::Simple::VisitorFactory for more
106       information.
107

SEE ALSO

109       These Visitor classes are all subclasses of Tree::Simple::Visitor,
110       which can be found in the Tree::Simple module, you should refer to that
111       module for more information.
112

AUTHOR

114       stevan little, <stevan@iinteractive.com>
115
117       Copyright 2004, 2005 by Infinity Interactive, Inc.
118
119       <http://www.iinteractive.com>
120
121       This library is free software; you can redistribute it and/or modify it
122       under the same terms as Perl itself.
123
124
125
126perl v5.28.0                      2016-T0r5e-e0:3:Simple::Visitor::FromNestedHash(3)
Impressum