diff options
Diffstat (limited to 'lib/Config/HAProxy')
-rw-r--r-- | lib/Config/HAProxy/Iterator.pm | 68 | ||||
-rw-r--r-- | lib/Config/HAProxy/Node.pm | 137 | ||||
-rw-r--r-- | lib/Config/HAProxy/Node/Comment.pm | 31 | ||||
-rw-r--r-- | lib/Config/HAProxy/Node/Empty.pm | 29 | ||||
-rw-r--r-- | lib/Config/HAProxy/Node/Root.pm | 52 | ||||
-rw-r--r-- | lib/Config/HAProxy/Node/Section.pm | 153 | ||||
-rw-r--r-- | lib/Config/HAProxy/Node/Statement.pm | 45 |
7 files changed, 513 insertions, 2 deletions
diff --git a/lib/Config/HAProxy/Iterator.pm b/lib/Config/HAProxy/Iterator.pm index 6b0208e..6d80dd9 100644 --- a/lib/Config/HAProxy/Iterator.pm +++ b/lib/Config/HAProxy/Iterator.pm | |||
@@ -63,6 +63,74 @@ sub next { | |||
63 | } | 63 | } |
64 | 64 | ||
65 | 1; | 65 | 1; |
66 | __END__ | ||
67 | |||
68 | =head1 NAME | ||
69 | |||
70 | Config::HAProxy::Iterator - Iterate over objects in the parse tree | ||
71 | |||
72 | =head1 SYNOPSIS | ||
73 | |||
74 | $cfg = Config::HAProxy->new->parse; | ||
75 | $itr = $cfg->iterator(inorder => 1); | ||
76 | while (defined(my $node = $itr->next)) { | ||
77 | # Do something with $node | ||
78 | } | ||
79 | |||
80 | =head1 DESCRIPTION | ||
81 | |||
82 | The iterator object provides a method for iterating over all nodes in the | ||
83 | HAProxy parse tree. The object is returned by the B<iterator> method of | ||
84 | B<Config::HAProxy> and B<Config::HAProxy::Node> objects. The method takes | ||
85 | as optional argument the keyword specifying the order in which the tree nodes | ||
86 | should be traversed. This keyword can be one of the following: | ||
87 | |||
88 | =over 4 | ||
89 | |||
90 | =item B<recursive =E<gt> 0> | ||
91 | |||
92 | No recursion. The traversal will not descend into section nodes. This is the | ||
93 | default. | ||
94 | |||
95 | =item B<inorder =E<gt> 1> | ||
96 | |||
97 | The nodes will be traversed in the inorder manner, i.e. the section node | ||
98 | will be visited first, and all its sub-nodes after it. | ||
99 | |||
100 | =item B<postorder =E<gt> 1> | ||
101 | |||
102 | The nodes will be traversed in the postorder manner, i.e. for each section | ||
103 | node, its sub-nodes will be visited first, and the node itself afterward. | ||
104 | |||
105 | =back | ||
106 | |||
107 | =head1 CONSTRUCTOR | ||
108 | |||
109 | Note: This section is informative. You never need to create | ||
110 | B<Config::HAProxy::Iterator> objects explicitly. Please use the B<iterator> | ||
111 | method of B<Config::HAProxy> or B<Config::HAProxy::Node> class objects. | ||
112 | |||
113 | $itr = new Config::HAProxy::Iterator($node, %rec); | ||
114 | |||
115 | Returns new iterator object for traversing the tree starting from B<$node>, | ||
116 | which must be a B<Config::HAProxy::Node> object. Optional B<%rec> is one of | ||
117 | the keywords discussed above, in section B<DESCRIPTION>. | ||
118 | |||
119 | =head1 METHODS | ||
120 | |||
121 | =head2 next | ||
122 | |||
123 | $node = $itr->next; | ||
124 | |||
125 | Returns next node in the traversal sequence. If all nodes were visited, returns | ||
126 | B<undef>. | ||
127 | |||
128 | =head1 SEE ALSO | ||
129 | |||
130 | B<HAProxy::Config>, B<HAProxy::Config::Node>. | ||
131 | |||
132 | =cut | ||
133 | |||
66 | 134 | ||
67 | 135 | ||
68 | 136 | ||
diff --git a/lib/Config/HAProxy/Node.pm b/lib/Config/HAProxy/Node.pm index be09538..8210067 100644 --- a/lib/Config/HAProxy/Node.pm +++ b/lib/Config/HAProxy/Node.pm | |||
@@ -97,3 +97,140 @@ sub is_empty { 0 } | |||
97 | sub is_comment { 0 } | 97 | sub is_comment { 0 } |
98 | 98 | ||
99 | 1; | 99 | 1; |
100 | __END__ | ||
101 | |||
102 | =head1 NAME | ||
103 | |||
104 | Config::HAProxy::Node - Abstract HAProxy configuration node | ||
105 | |||
106 | =head1 DESCRIPTION | ||
107 | |||
108 | The class B<Config::HAProxy::Node> represents an abstract node in the | ||
109 | HAProxy configuration parse tree. It serves as a base class for classes | ||
110 | representing configuration tree, section, simple statement, comment and | ||
111 | empty line. | ||
112 | |||
113 | =head1 CONSTRUCTOR | ||
114 | |||
115 | $obj = new Config::HAProxy::Node(%args); | ||
116 | |||
117 | Returns new object. B<%args> can contain the following keys: | ||
118 | |||
119 | =over 4 | ||
120 | |||
121 | =item B<kw> | ||
122 | |||
123 | Configuration keyword (string), | ||
124 | |||
125 | =item B<argv> | ||
126 | |||
127 | Reference to the list of arguments. | ||
128 | |||
129 | =item B<orig> | ||
130 | |||
131 | Original text as read from the configuration file. | ||
132 | |||
133 | =item B<locus> | ||
134 | |||
135 | Locus (a B<Text::Locus> object) where this statement occurred. | ||
136 | |||
137 | =item B<parent> | ||
138 | |||
139 | Parent node. | ||
140 | |||
141 | =back | ||
142 | |||
143 | =head1 METHODS | ||
144 | |||
145 | =head2 B<kw>, B<argv>, B<orig>, B<locus>, B<parent> | ||
146 | |||
147 | These methods return the corresponding field of the node. When called | ||
148 | with an argument, they set the field prior to returning it. The B<argv> | ||
149 | method returns array of strings and takes as its argument a reference to | ||
150 | the array of strings: | ||
151 | |||
152 | @a = $node->argv; | ||
153 | |||
154 | $node->argv([@a]); | ||
155 | |||
156 | =head2 index | ||
157 | |||
158 | Index (0-based) of this node in the parent node. | ||
159 | |||
160 | =head2 arg | ||
161 | |||
162 | $a = $node->arg($n) | ||
163 | |||
164 | Returns the B<$n>th argument (0-based) from the argument list. | ||
165 | |||
166 | =head2 drop | ||
167 | |||
168 | $node->drop; | ||
169 | |||
170 | Removes this node and destroys it. | ||
171 | |||
172 | =head2 iterator | ||
173 | |||
174 | $itr = $node->iterator(@args); | ||
175 | |||
176 | Returns the iterator for this node. See B<Config::HAProxy::Iterator> for | ||
177 | a detailed discussion. | ||
178 | |||
179 | =head2 depth | ||
180 | |||
181 | $n = $node->depth; | ||
182 | |||
183 | Returns the depth of this node in the configuration tree. Depth is the | ||
184 | number of parent nodes between the root of tree and this node. Top-level | ||
185 | nodes have depth 0. | ||
186 | |||
187 | =head2 root | ||
188 | |||
189 | $root_node = $node->root; | ||
190 | |||
191 | Returns the root node of the parse tree this node belongs to. | ||
192 | |||
193 | =head2 as_string | ||
194 | |||
195 | $s = $node->as_string; | ||
196 | |||
197 | Returns canonical string representation of this node. The canonical | ||
198 | representation consists of the keyword followed by arguments delimited | ||
199 | with horizontal space characters. | ||
200 | |||
201 | =head1 ABSTRACT METHODS | ||
202 | |||
203 | Derived classes must overload at least one of the following methods: | ||
204 | |||
205 | =head2 is_root | ||
206 | |||
207 | True if the node is a root node, false otherwise. | ||
208 | |||
209 | =head2 is_section | ||
210 | |||
211 | True if the node represents a section (i.e. contains subnodes). | ||
212 | |||
213 | =head2 is_statement | ||
214 | |||
215 | True if the node is a simple statement. | ||
216 | |||
217 | =head2 is_empty | ||
218 | |||
219 | True if the node represents an empty line. | ||
220 | |||
221 | =head2 is_comment | ||
222 | |||
223 | True if the node represents a comment. | ||
224 | |||
225 | =head1 SEE ALSO | ||
226 | |||
227 | B<Config::HAProxy::Node::Comment>, | ||
228 | B<Config::HAProxy::Node::Empty>, | ||
229 | B<Config::HAProxy::Node::Root>, | ||
230 | B<Config::HAProxy::Node::Section>, | ||
231 | B<Config::HAProxy::Node::Statement>, | ||
232 | B<Config::HAProxy::Iterator>, | ||
233 | B<Config::HAProxy>, | ||
234 | B<Text::Locus>. | ||
235 | |||
236 | =cut | ||