Subject: | No longer handles non-existing config files gracefully |
Hi,
I haven't checked to see what version this appeared in, but as reported
in Debian Bug #617305 [0] Config::Auto now barfs out error messages if a
config file isn't found, for example:
Use of uninitialized value $file in open at
/usr/share/perl5/Config/Auto.pm line 394.
Use of uninitialized value $file in concatenation (.) or string at
/usr/share/perl5/Config/Auto.pm line 397.
Use of uninitialized value $fh in <HANDLE> at
/usr/share/perl5/Config/Auto.pm line 353.
readline() on unopened filehandle at /usr/share/perl5/Config/Auto.pm
line 353.
Can't use an undefined value as a symbol reference at
/usr/share/perl5/Config/Auto.pm line 356.
puck@dirk:/tmp$ perl foo.pl
Use of uninitialized value $fh in <HANDLE> at
/usr/share/perl5/Config/Auto.pm line 353.
readline() on unopened filehandle at /usr/share/perl5/Config/Auto.pm
line 353.
Can't use an undefined value as a symbol reference at
/usr/share/perl5/Config/Auto.pm line 356.
puck@dirk:/tmp$ perl foo.pl
Can't use an undefined value as an ARRAY reference at
/usr/share/perl5/Config/Auto.pm line 462.
Whereas in the past it'd croak with a suitable error message.
This has broken at least one package that relied on that behaviour, and
I expect others well. The attached patch restores the previous behaviour.
The attached Perl script tries and triggers the behaviour.
Cheers!
[0] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=617305
Subject: | config-auto_no-file.patch |
diff --git a/Auto.pm.orig b/Auto.pm
index 7086fa2..b1ea19e 100644
--- a/Auto.pm.orig
+++ b/Auto.pm
@@ -207,6 +207,10 @@ sub parse {
or croak( "Could not parse '$self' => @_" );
}
+ my $file = $self->file;
+ croak "No config file found!" unless defined $file;
+ croak "Config file $file not readable!" unless -e $file;
+
### from Toru Marumoto: Config-Auto return undef if -B $file
### <21d48be50604271656n153e6db6m9b059f57548aaa32@mail.gmail.com>
# If a config file "$file" contains multibyte charactors like japanese,
Subject: | test-config-auto.pl |
#!/usr/bin/perl -w
use Config::Auto;
use Data::Dumper;
print "Try and load a file that doesn't exist, you should be told it doesn't exist.\n\n\n";
my $c;
eval {
$c = Config::Auto::parse("i-dont-exist.yml", format => 'yaml');
};
print "$@\n";
print "Try and load a file that does exist, you should be told it does.\n\n\n";
system("echo \"exist: yes\" >> /tmp/i-do-exist.yml");
$c = Config::Auto::parse("/tmp/i-do-exist.yml", format => 'yaml');
print Dumper($c) . "\n";