From 8d54e0108503016811b4f4626bb476410b206d21 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sun, 26 Mar 2017 20:47:50 +1300 Subject: Enforce setting of scalar configs --- idalius.pl | 8 +++++--- sb_config.pm | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/idalius.pl b/idalius.pl index fe195dc..cd4bf16 100755 --- a/idalius.pl +++ b/idalius.pl @@ -25,9 +25,11 @@ my $irc = POE::Component::IRC->spawn( ) or die "Failed to create new PoCo-IRC: $!"; # Plugins -$irc->plugin_add('NickServID', POE::Component::IRC::Plugin::NickServID->new( - Password => $config{password} -)); +$config{password} and $irc->plugin_add( + 'NickServID', + POE::Component::IRC::Plugin::NickServID->new( + Password => $config{password} + )); POE::Session->create( package_states => [ diff --git a/sb_config.pm b/sb_config.pm index ee816b0..39e92aa 100644 --- a/sb_config.pm +++ b/sb_config.pm @@ -10,12 +10,17 @@ sub parse_config { my @scalar_configs = ('nick', 'username', 'ircname', 'server', 'port', 'usessl', 'password', 'must_id', 'quit_msg', 'user', 'group'); my @list_configs = ('channels', 'ignore', 'admins'); + my @optional_configs = ('password'); my $file = $_[0]; my %built_config; my $config = Config::Tiny->read($file); # FIXME catch undefined/missing config options foreach my $option (@scalar_configs) { + my $value = $config->{_}->{$option}; + if (! defined $value && ! grep {$_ eq $option} @optional_configs) { + die "Option \"$option\" must be set in $file\n"; + } $built_config{$option} = $config->{_}->{$option}; } -- cgit v1.1