diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Config/HAProxy.pm | 29 | ||||
-rw-r--r-- | lib/Config/HAProxy/Node.pm | 1 |
2 files changed, 27 insertions, 3 deletions
diff --git a/lib/Config/HAProxy.pm b/lib/Config/HAProxy.pm index 175e402..f220051 100644 --- a/lib/Config/HAProxy.pm +++ b/lib/Config/HAProxy.pm @@ -13,19 +13,20 @@ use File::Basename; use File::Temp qw(tempfile); use File::stat; use File::Spec; use IPC::Cmd qw(run); use Carp; -our $VERSION = '1.04'; +our $VERSION = '1.08'; my %sections = ( global => 1, defaults => 1, frontend => 1, backend => 1, + resolvers => 1 ); sub new { my $class = shift; my $filename = shift // '/etc/haproxy/haproxy.cfg'; my $self = bless { _filename => $filename, @@ -85,12 +86,22 @@ sub parse { } $self->pop; close $fh; return $self; } +sub declare_section { + my ($class, $name) = @_; + $sections{$name} = 1; +} + +sub undeclare_section { + my ($class, $name) = @_; + $sections{$name} = 0; +} + sub reset { my $self = shift; $self->{_stack} = [ new Config::HAProxy::Node::Root() ]; } sub push { @@ -341,13 +352,15 @@ Represents a comment line. Represents a simple statement. =item Section A container, representing a C<compound statement>, i.e. a statement that contains multiple sub-statements. Compound statements are: B<global>, -B<defaults>, B<frontend>, and B<backend>. +B<defaults>, B<frontend>, B<backend>, and B<resolvers>. The list of +compound statements may be modified using the B<declare_section> and +B<undeclare_section> class methods (see below). =back In addition to these four classes, a special class B<Root> is provided, which represents the topmost node in the parse tree (i.e. the parent of other nodes). @@ -366,13 +379,23 @@ is represented by a node of class B<Config::HAProxy::Node::Statement>, with C<server> as B<kw> and list (C<localhost>, C<127.0.0.1:8080>) as B<argv>. Additionally, section nodes provide methods for accessing their subtrees. For a detailed description of the node class and its methods, please refer to B<Config::HAProxy::Node>. - + +=head1 CLASS METHODS + + $cfg = Config::HAProxy::declare_section($name) + +Declares B<$name> as a top-level section. + + $cfg = Config::HAProxy::undeclare_section($name) + +Cancels declaration of B<$name> as a top-level section. + =head1 CONSTRUCTOR $cfg = new Config::HAProxy($filename); Creates and returns a new object for manipulating the HAProxy configuration. Optional B<$filename> specifies the name of the file to read configuration diff --git a/lib/Config/HAProxy/Node.pm b/lib/Config/HAProxy/Node.pm index 8210067..32e63c0 100644 --- a/lib/Config/HAProxy/Node.pm +++ b/lib/Config/HAProxy/Node.pm @@ -35,12 +35,13 @@ my @ATTRIBUTES = qw(kw orig locus parent index); sub argv { my $self = shift; if (my $val = shift) { croak "too many arguments" if @_; $self->{_argv} = $val; + delete $self->{_orig}; } return @{$self->{_argv}}; } sub arg { my $self = shift; |