aboutsummaryrefslogtreecommitdiffstats
path: root/AdminPanel
diff options
context:
space:
mode:
authorMatteo Pasotti <matteo.pasotti@gmail.com>2014-01-19 01:10:17 +0100
committerMatteo Pasotti <matteo.pasotti@gmail.com>2014-01-19 01:10:17 +0100
commit03509ca6ac225c921d5f15479198908eac6df605 (patch)
tree8033f2827ac251888c9522685cd28ce19dae1e2d /AdminPanel
parent37603e411c756699854c4657233dca681eb2c27b (diff)
downloadmanatools-03509ca6ac225c921d5f15479198908eac6df605.tar
manatools-03509ca6ac225c921d5f15479198908eac6df605.tar.gz
manatools-03509ca6ac225c921d5f15479198908eac6df605.tar.bz2
manatools-03509ca6ac225c921d5f15479198908eac6df605.tar.xz
manatools-03509ca6ac225c921d5f15479198908eac6df605.zip
- now using Moose (hosts is now a class)
- _insertHost implemented - _writeHosts implemented - configHosts is an instance variable
Diffstat (limited to 'AdminPanel')
-rw-r--r--AdminPanel/Hosts/hosts.pm30
1 files changed, 24 insertions, 6 deletions
diff --git a/AdminPanel/Hosts/hosts.pm b/AdminPanel/Hosts/hosts.pm
index c957ad42..97f9a90e 100644
--- a/AdminPanel/Hosts/hosts.pm
+++ b/AdminPanel/Hosts/hosts.pm
@@ -1,7 +1,6 @@
package AdminPanel::Hosts::hosts;
-use Modern::Perl 2011;
-use autodie;
+use Moose;
use diagnostics;
use local::lib;
use Config::Hosts;
@@ -12,6 +11,10 @@ my $is_ip = 1;
my $is_host = -1;
my $is_none = 0;
+has 'configHosts' => (
+ is => 'rw',
+ init_arg => undef
+);
=pod
@@ -30,13 +33,14 @@ retrieve data from the hosts file (/etc/hosts) using the Config::Hosts module
=cut
sub _getHosts {
- my $configHosts = Config::Hosts->new();
- my $hosts = $configHosts->read_hosts();
+ my $self = shift();
+ $self->configHosts(Config::Hosts->new());
+ my $hosts = $self->configHosts->read_hosts();
my @result = ();
while( my ($key, $value) = each($hosts)){
- if($configHosts->determine_ip_or_host($key) == $is_ip){
+ if($self->configHosts->determine_ip_or_host($key) == $is_ip){
my $tmp = {};
- $tmp = $configHosts->query_host($key);
+ $tmp = $self->configHosts->query_host($key);
$tmp->{'ip'} = $key;
push @result,$tmp;
}
@@ -44,4 +48,18 @@ sub _getHosts {
return @result;
}
+sub _insertHost {
+ my $self = shift();
+ # remember that the order matters!
+ my $ip = shift();
+ my @host_definitions = @_;
+ # $self->configHosts = Config::Hosts->new();
+ return $self->configHosts->insert_host(ip => $ip, hosts => @host_definitions);
+}
+
+sub _writeHosts {
+ my $self = shift();
+ return $self->configHosts->write_hosts();
+}
+
1;