From 20c694e77d1e179a661f28784b389ac592d0393d Mon Sep 17 00:00:00 2001 From: Angelo Naselli Date: Sat, 26 Dec 2015 22:03:34 +0100 Subject: Acting as ConfigDirRole --- lib/ManaTools/Module/Firewall.pm | 45 +++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/lib/ManaTools/Module/Firewall.pm b/lib/ManaTools/Module/Firewall.pm index 8cfebb8e..0e409310 100644 --- a/lib/ManaTools/Module/Firewall.pm +++ b/lib/ManaTools/Module/Firewall.pm @@ -47,6 +47,32 @@ use XML::Simple; extends qw( ManaTools::Module ); +# configName, configDir as attributes, must be before "with 'ManaTools::ConfigDirRole'" +has 'configName' => ( + is => 'ro', + isa => 'Str', + init_arg => undef, + lazy => 1, + default => 'manawall', +); + +has 'configDir' => ( + is => 'ro', + isa => 'Str', + lazy => 1, + builder => '_configDirBuilder', +); + +sub _configDirBuilder { + my $self = shift(); + my $confDir = $self->commandline()->conf_dir() || $self->defaultConfigDir(); + + return $confDir; +} + +with 'ManaTools::ConfigDirRole'; + + has '+icon' => ( default => File::ShareDir::dist_file(ManaTools::Shared::distName(), 'images/manawall.png'), ); @@ -136,19 +162,19 @@ has 'aboutDialog' => ( builder => '_setupAboutDialog', ); + has 'conf' => ( is => 'ro', isa => 'Str', + lazy => 1, builder => '_confBuilder', ); sub _confBuilder { my $self = shift(); - my $confDir = $self->commandline()->conf_dir() || "/etc/manatools"; - chop $confDir if substr($confDir, -1) eq '/'; - $confDir .= "/manawall/spec.conf"; + my $confDir = $self->configPathName(); - return $confDir; + return $confDir . "/spec.conf"; } sub _setupAboutDialog { @@ -1067,9 +1093,14 @@ sub start { my @server = (); $self->wdg_servers(@server); - # init servers definitions - $self->all_servers($self->_initAllServers()); - + eval { + # init servers definitions + $self->all_servers($self->_initAllServers()); + }; + if ($@) { + warn $@; + return; + } # initialize ifw_rules here $self->ifw_rules($self->_initIFW()); -- cgit v1.2.1