summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changes8
-rw-r--r--Makefile.PL4
-rw-r--r--lib/Config/HAProxy.pm29
-rw-r--r--lib/Config/HAProxy/Node.pm1
4 files changed, 39 insertions, 3 deletions
diff --git a/Changes b/Changes
index 0d0a1a9..a7f1b78 100644
--- a/Changes
+++ b/Changes
@@ -1,14 +1,22 @@
Revision history for Perl extension Config::HAProxy.
+1.08 Thu Jun 23 15:21:17 2022
+ - Handle the 'resolvers' section.
+ - New class methods for declaring (and undeclaring) sections.
+ - Fix changing the argv of a Node.
+
+1.06 Fri Feb 12 20:37:32 2021
+ - Change bugtracker address.
+
1.05 Mon May 27 13:59:57 2019
- unlink temporary file on error
1.04 Sun May 26 12:23:54 2019
- fix improper use of IPC::Cmd
1.03 Sun May 26 09:12:10 2019
- implement configuration syntax check
1.02 Mon Jul 16 07:38:31 2018
- remove the leftover use of autodie
diff --git a/Makefile.PL b/Makefile.PL
index 754d3aa..d7c08b9 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -18,18 +18,22 @@ WriteMakefile(
'File::Basename' => 0,
'File::Temp' => 0,
'IPC::Cmd' => 0
},
META_MERGE => {
'meta-spec' => { version => 2 },
resources => {
repository => {
type => 'git',
url => 'git://git.gnu.org.ua/config-haproxy.git',
web => 'http://git.gnu.org.ua/cgit/config-haproxy.git/',
},
+ bugtracker => {
+ web => 'https://puszcza.gnu.org.ua/bugs/?group=config-haproxy',
+ mailto => 'gray+config-haproxy@gnu.org.ua'
+ }
},
provides => Module::Metadata->provides(version => '1.4',
dir => 'lib')
}
);
diff --git a/lib/Config/HAProxy.pm b/lib/Config/HAProxy.pm
index 35e75b9..f220051 100644
--- a/lib/Config/HAProxy.pm
+++ b/lib/Config/HAProxy.pm
@@ -7,31 +7,32 @@ use Config::HAProxy::Node::Root;
use Config::HAProxy::Node::Section;
use Config::HAProxy::Node::Statement;
use Config::HAProxy::Node::Comment;
use Config::HAProxy::Node::Empty;
use Text::ParseWords;
use File::Basename;
use File::Temp qw(tempfile);
use File::stat;
use File::Spec;
use IPC::Cmd qw(run);
use Carp;
-our $VERSION = '1.05';
+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,
_lint => { enable => 1 } }, $class;
$self->reset();
return $self;
}
sub filename { shift->{_filename} }
@@ -79,24 +80,34 @@ sub parse {
$self->tos->append_node(
new Config::HAProxy::Node::Statement(kw => $kw,
argv => \@words,
orig => $orig,
locus => $locus));
}
}
$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 {
my $self = shift;
push @{$self->{_stack}}, @_;
}
sub pop {
my $self = shift;
@@ -335,50 +346,62 @@ Represents an empty line.
=item Comment
Represents a comment line.
=item Statement
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).
A set of attributes is associated with each node. Among these, the B<orig>
attribute contains the original line from the configuration file that triggered
creation of this node, and B<locus> contains the location of this line (or
lines, for sections) in the configuration file (as a B<Text::Locus>) object.
These two attributes are meaningful for all nodes. For statement nodes (simple
statements and sections) the B<kw> attribute contains the statement I<keyword>,
and the B<argv> attribute - its arguments. For example, the statement
server localhost 127.0.0.1:8080
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
from. It defaults to F</etc/haproxy/haproxy.cfg>.
=head2 filename
$s = $cfg->filename;
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
@@ -29,24 +29,25 @@ my @ATTRIBUTES = qw(kw orig locus parent index);
$self->{'_'.$attribute} = $val;
}
return $self->{'_'.$attribute};
}
}
}
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;
my $n = shift;
if (my $val = shift) {
croak "too many arguments" if @_;
$self->{_argv}[$n] = $val;
}
return $self->{_argv}[$n];

Return to:

Send suggestions and report system problems to the System administrator.