From 1a75c7c53f64d0eec5eb3477900a6cc76aec3281 Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Mon, 23 May 2011 01:40:28 -0700 Subject: Be more paranoid about Config::Simple. --- libpiny/lib/Piny/Config.pm | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'libpiny/lib/Piny/Config.pm') diff --git a/libpiny/lib/Piny/Config.pm b/libpiny/lib/Piny/Config.pm index b949198..aaa415a 100644 --- a/libpiny/lib/Piny/Config.pm +++ b/libpiny/lib/Piny/Config.pm @@ -88,7 +88,12 @@ sub _build__conf { my $conf; if ( $s->has_confpath and -e $s->confpath ) { - $conf = Config::Simple->new( $s->confpath )->vars; + $conf = Config::Simple->new( $s->confpath ); + if ( defined $conf ) { + $conf = $conf->vars; + } else { + $conf = { }; + }; } else { $conf = { }; }; @@ -97,11 +102,15 @@ sub _build__conf { if ( -s $home ) { - my $userconf = Config::Simple->new( $home )->vars; + my $userconf = Config::Simple->new( $home ); + + if ( defined $userconf ) { + $userconf = $userconf->vars; - foreach my $key ( keys %$userconf ) { - if ( not exists $conf->{$key} ) { - $conf->{$key} = $userconf->{$key}; + foreach my $key ( keys %$userconf ) { + if ( not exists $conf->{$key} ) { + $conf->{$key} = $userconf->{$key}; + }; }; }; @@ -109,11 +118,15 @@ sub _build__conf { if ( -s "/etc/piny-default.conf" ) { - my $default = Config::Simple->new( "/etc/piny-default.conf" )->vars; + my $default = Config::Simple->new( "/etc/piny-default.conf" ); - foreach my $key ( keys %$default ) { - if ( not exists $conf->{$key} ) { - $conf->{$key} = $default->{$key}; + if ( defined $default ) { + $default = $default->vars; + + foreach my $key ( keys %$default ) { + if ( not exists $conf->{$key} ) { + $conf->{$key} = $default->{$key}; + }; }; }; @@ -121,10 +134,14 @@ sub _build__conf { if ( -s "/etc/piny-override.conf" ) { - my $override = Config::Simple->new( "/etc/piny-override.conf" )->vars; + my $override = Config::Simple->new( "/etc/piny-override.conf" ); + + if ( defined $override ) { + $override = $override->vars; - foreach my $key ( keys %$override ) { - $conf->{$key} = $override->{$key}; + foreach my $key ( keys %$override ) { + $conf->{$key} = $override->{$key}; + }; }; }; -- cgit v1.2.3