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