summaryrefslogtreecommitdiff
path: root/lib/Config
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2018-07-08 22:16:49 +0300
committerSergey Poznyakoff <gray@gnu.org>2018-07-08 22:16:49 +0300
commit69ff9c1766ed89edf0ffdb63bf487396b6bd081b (patch)
treeef644a810f50d81d3b4e47d7cdbf64df976d8be6 /lib/Config
parent32b6c6394dc6a789826bd51575d9703bb4097f70 (diff)
downloadconfig-haproxy-69ff9c1766ed89edf0ffdb63bf487396b6bd081b.tar.gz
config-haproxy-69ff9c1766ed89edf0ffdb63bf487396b6bd081b.tar.bz2
Add documentationv1.00
Diffstat (limited to 'lib/Config')
-rw-r--r--lib/Config/HAProxy.pm140
-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
8 files changed, 628 insertions, 27 deletions
diff --git a/lib/Config/HAProxy.pm b/lib/Config/HAProxy.pm
index 7938bcb..f99bf33 100644
--- a/lib/Config/HAProxy.pm
+++ b/lib/Config/HAProxy.pm
@@ -182,10 +182,10 @@ sub save {
182 $self->backup; 182 $self->backup;
183 rename($tempfile, $self->filename) 183 rename($tempfile, $self->filename)
184 or croak "can't rename $tempfile to ".$self->tempfile.": $!"; 184 or croak "can't rename $tempfile to ".$self->tempfile.": $!";
185 # This will fail unless we are root, let it be so.
186 chown $sb->uid, $sb->gid, $self->filename;
187 # This will succeed: we've created the file, so we're owning it. 185 # This will succeed: we've created the file, so we're owning it.
188 chmod $sb->mode & 0777, $self->filename; 186 chmod $sb->mode & 0777, $self->filename;
187 # This will fail unless we are root, let it be so.
188 chown $sb->uid, $sb->gid, $self->filename;
189 189
190 $self->tree->clear_dirty 190 $self->tree->clear_dirty
191} 191}
@@ -215,39 +215,90 @@ __END__
215 215
216=head1 NAME 216=head1 NAME
217 217
218Config::HAProxy - HAProxy configuration file 218Config::HAProxy - Parser for HAProxy configuration file
219 219
220=head1 SYNOPSIS 220=head1 SYNOPSIS
221 221
222use Config::HAProxy; 222 use Config::HAProxy;
223$cfg = new Config::HAProxy($filename); 223 $cfg = new Config::HAProxy($filename);
224$cfg->parse; 224 $cfg->parse;
225 225
226$name = $cfg->filename; 226 $name = $cfg->filename;
227 227
228@frontends = $cfg->select(name => 'frontend'); 228 @frontends = $cfg->select(name => 'frontend');
229 229
230$itr = $cfg->iterator(inorder => 1); 230 $itr = $cfg->iterator(inorder => 1);
231while (defined($node = $itr->next)) { 231 while (defined($node = $itr->next)) {
232 # do something with $node 232 # do something with $node
233} 233 }
234 234
235$cfg->save; 235 $cfg->save;
236 236
237$cfg->write($file_or_handle); 237 $cfg->write($file_or_handle);
238 238
239$cfg->backup; 239 $cfg->backup;
240$name = $self->backup_name; 240 $name = $self->backup_name;
241 241
242$cfg->reset; 242 $cfg->reset;
243$cfg->push($node); 243 $cfg->push($node);
244$node = $cfg->pop; 244 $node = $cfg->pop;
245$node = $cfg->tos; 245 $node = $cfg->tos;
246$node = $cfg->tree; 246 $node = $cfg->tree;
247 247
248=head1 DESCRIPTION 248=head1 DESCRIPTION
249 249
250FIXME 250The B<Config::HAProxy> class is a parser that converts the B<HAProxy>
251configuration file to a parse tree and provides methods for various
252operations on this tree, such as: searching, modifying and saving it
253to a file.
254
255An object of this class contains a I<parse tree> representing the
256configuration read from the file (or created from scratch). Nodes in the
257tree can be of four distinct classes:
258
259=over 4
260
261=item Empty
262
263Represents an empty line.
264
265=item Comment
266
267Represents a comment line.
268
269=item Statement
270
271Represents a simple statement.
272
273=item Section
274
275A container, representing a C<compound statement>, i.e. a statement that
276contains multiple sub-statements. Compound statements are: B<global>,
277B<defaults>, B<frontend>, and B<backend>.
278
279=back
280
281In addition to these four classes, a special class B<Root> is provided, which
282represents the topmost node in the parse tree (i.e. the parent of other nodes).
283
284A set of attributes is associated with each node. Among these, the B<orig>
285attribute contains the original line from the configuration file that triggered
286creation of this node, and B<locus> contains the location of this line (or
287lines, for sections) in the configuration file (as a B<Text::Locus>) object.
288
289These two attributes are meaningful for all nodes. For statement nodes (simple
290statements and sections) the B<kw> attribute contains the statement I<keyword>,
291and the B<argv> attribute - its arguments. For example, the statement
292
293 server localhost 127.0.0.1:8080
294
295is represented by a node of class B<Config::HAProxy::Node::Statement>, with
296C<server> as B<kw> and list (C<localhost>, C<127.0.0.1:8080>) as B<argv>.
297
298Additionally, section nodes provide methods for accessing their subtrees.
299
300For a detailed description of the node class and its methods, please refer to
301B<Config::HAProxy::Node>.
251 302
252=head1 CONSTRUCTOR 303=head1 CONSTRUCTOR
253 304
@@ -257,15 +308,23 @@ Creates and returns a new object for manipulating the HAProxy configuration.
257Optional B<$filename> specifies the name of the file to read configuration 308Optional B<$filename> specifies the name of the file to read configuration
258from. It defaults to F</etc/haproxy/haproxy.cfg>. 309from. It defaults to F</etc/haproxy/haproxy.cfg>.
259 310
260=head1 THE PARSE TREE 311=head2 filename
312
313 $s = $cfg->filename;
314
315Returns the configuration file name given when creating the object.
316
317=head1 PARSING
261 318
262=head2 parse 319=head2 parse
263 320
264 $cfg->parse; 321 $cfg->parse;
265 322
266Reads and parses the configuration file. Croaks if the file does not exist. 323Reads and parses the configuration file. Croaks if the file does not exist.
324Returns B<$cfg>.
267 325
268 326=head1 BUILDING THE PARSE TREE
327
269=head2 reset 328=head2 reset
270 329
271 $cfg->reset; 330 $cfg->reset;
@@ -305,7 +364,7 @@ Returns the last node in the tree.
305 364
306 $cfg->save; 365 $cfg->save;
307 366
308Saves the configuration file. 367Saves the parse tree in the configuration file.
309 368
310=head2 write 369=head2 write
311 370
@@ -327,3 +386,34 @@ Normally, comments retain their original indentation. However, if the
327key B<reintent_comments> is present, and its value is evaluated as true, 386key B<reintent_comments> is present, and its value is evaluated as true,
328then comments are reindented following the rules described above. 387then comments are reindented following the rules described above.
329 388
389=head1 SEE ALSO
390
391B<Config::HAProxy::Node>,
392B<Config::HAProxy::Node::Section>,
393B<Config::HAProxy::Node::Statement>,
394B<Config::HAProxy::Iterator>.
395
396=head1 AUTHOR
397
398Sergey Poznyakoff, E<lt>gray@gnu.orgE<gt>
399
400=head1 COPYRIGHT AND LICENSE
401
402Copyright (C) 2018 by Sergey Poznyakoff
403
404This library is free software; you can redistribute it and/or modify it
405under the terms of the GNU General Public License as published by the
406Free Software Foundation; either version 3 of the License, or (at your
407option) any later version.
408
409It is distributed in the hope that it will be useful,
410but WITHOUT ANY WARRANTY; without even the implied warranty of
411MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
412GNU General Public License for more details.
413
414You should have received a copy of the GNU General Public License along
415with this library. If not, see <http://www.gnu.org/licenses/>.
416
417=cut
418
419
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 {