From 98da7d8102939b47709cf85c484786e37068538c Mon Sep 17 00:00:00 2001 From: Matteo Pasotti Date: Sat, 25 Jan 2014 00:29:08 +0100 Subject: - initializing configHosts attribute using moose builder - implemented _dropHost method --- AdminPanel/Hosts/hosts.pm | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'AdminPanel') diff --git a/AdminPanel/Hosts/hosts.pm b/AdminPanel/Hosts/hosts.pm index 97f9a90e..6b2264f9 100644 --- a/AdminPanel/Hosts/hosts.pm +++ b/AdminPanel/Hosts/hosts.pm @@ -13,9 +13,15 @@ my $is_none = 0; has 'configHosts' => ( is => 'rw', - init_arg => undef + init_arg => undef, + builder => '_initialize' ); +sub _initialize { + my $self = shift(); + $self->configHosts(Config::Hosts->new()); +} + =pod =head2 _getHosts @@ -34,7 +40,7 @@ retrieve data from the hosts file (/etc/hosts) using the Config::Hosts module sub _getHosts { my $self = shift(); - $self->configHosts(Config::Hosts->new()); + # $self->configHosts(Config::Hosts->new()); my $hosts = $self->configHosts->read_hosts(); my @result = (); while( my ($key, $value) = each($hosts)){ @@ -57,6 +63,12 @@ sub _insertHost { return $self->configHosts->insert_host(ip => $ip, hosts => @host_definitions); } +sub _dropHost { + my $self = shift(); + my $host_ip = shift(); + return $self->configHosts->delete_host($host_ip); +} + sub _writeHosts { my $self = shift(); return $self->configHosts->write_hosts(); -- cgit v1.2.1