summaryrefslogtreecommitdiff
path: root/lib/Config/HAProxy/Node.pm
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2018-07-08 16:45:32 +0300
committerSergey Poznyakoff <gray@gnu.org>2018-07-08 16:45:32 +0300
commit10897f8a984a6dbc511403ca942fb8c7a8883349 (patch)
tree7740f48950d82cf2561c730384d61180649151b9 /lib/Config/HAProxy/Node.pm
downloadconfig-haproxy-10897f8a984a6dbc511403ca942fb8c7a8883349.tar.gz
config-haproxy-10897f8a984a6dbc511403ca942fb8c7a8883349.tar.bz2
Initial commit
Spawned from the proxyctl project.
Diffstat (limited to 'lib/Config/HAProxy/Node.pm')
-rw-r--r--lib/Config/HAProxy/Node.pm99
1 files changed, 99 insertions, 0 deletions
diff --git a/lib/Config/HAProxy/Node.pm b/lib/Config/HAProxy/Node.pm
new file mode 100644
index 0000000..be09538
--- /dev/null
+++ b/lib/Config/HAProxy/Node.pm
@@ -0,0 +1,99 @@
+package Config::HAProxy::Node;
+use strict;
+use warnings;
+use Carp;
+use Config::HAProxy::Iterator;
+
+sub new {
+ my $class = shift;
+ local %_ = @_;
+ bless {
+ _kw => $_{kw},
+ _argv => $_{argv} // [],
+ _orig => $_{orig},
+ _locus => $_{locus},
+ _parent => $_{parent},
+ _index => -1
+ }, $class;
+}
+
+my @ATTRIBUTES = qw(kw orig locus parent index);
+
+{
+ no strict 'refs';
+ foreach my $attribute (@ATTRIBUTES) {
+ *{ __PACKAGE__ . '::' . $attribute } = sub {
+ my $self = shift;
+ if (defined(my $val = shift)) {
+ croak "too many arguments" if @_;
+ $self->{'_'.$attribute} = $val;
+ }
+ return $self->{'_'.$attribute};
+ }
+ }
+}
+
+sub argv {
+ my $self = shift;
+ if (my $val = shift) {
+ croak "too many arguments" if @_;
+ $self->{_argv} = $val;
+ }
+ 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];
+}
+
+sub drop {
+ my $self = shift;
+ $self->parent->delete_node($self->index);
+}
+
+sub iterator {
+ return new Config::HAProxy::Iterator(@_);
+}
+
+sub depth {
+ my $self = shift;
+ my $n = 0;
+ while ($self = $self->parent) {
+ $n++;
+ }
+ return $n - 1;
+}
+
+sub root {
+ my $self = shift;
+ while ($self->parent()) {
+ $self = $self->parent();
+ }
+ return $self;
+}
+
+sub as_string {
+ my $self = shift;
+ if (defined(my $v = $self->orig)) {
+ return $v;
+ }
+ return '' unless $self->kw;
+ return $self->orig(join(' ', ($self->kw, $self->argv())));
+}
+
+# use overload
+# '""' => sub { shift->as_string };
+
+sub is_root { 0 }
+sub is_section { 0 }
+sub is_statement { 0 }
+sub is_empty { 0 }
+sub is_comment { 0 }
+
+1;

Return to:

Send suggestions and report system problems to the System administrator.