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 the 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 the Tree::Simple "accept"
96           method. It can also be used on its own,  it requires the $tree
97           argument to be a Tree::Simple object (or derived from a
98           Tree::Simple object), and will throw and exception otherwise.
99

Repository

101       <https://github.com/ronsavage/Tree-Simple-VisitorFactory>
102

SUPPORT

104       Bugs should be reported via the CPAN bug tracker at
105
106       <https://github.com/ronsavage/Tree-Simple-VisitorFactory/issues>
107

CODE COVERAGE

109       See the CODE COVERAGE section in Tree::Simple::VisitorFactory for more
110       information.
111

SEE ALSO

113       These Visitor classes are all subclasses of Tree::Simple::Visitor,
114       which can be found in the Tree::Simple module, you should refer to that
115       module for more information.
116

AUTHOR

118       stevan little, <stevan@iinteractive.com>
119
121       Copyright 2004, 2005 by Infinity Interactive, Inc.
122
123       <http://www.iinteractive.com>
124
125       This library is free software; you can redistribute it and/or modify it
126       under the same terms as Perl itself.
127
128
129
130perl v5.36.0                      2022-T0r7e-e2:2:Simple::Visitor::FromNestedHash(3)
Impressum