X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fp5-CGI-Ex;a=blobdiff_plain;f=lib%2FCGI%2FEx%2FConf.pm;h=82c76dc5dc35f9d1c658d7499f22a0b1758bc2a6;hp=5bcedfd9356b8c870a4074e0560eb25bce198c83;hb=3fe8e76eb82e9d74f656674c5ba913950e166ab1;hpb=a8620142ba0dcda3f0c5f102f791df944ed2245e diff --git a/lib/CGI/Ex/Conf.pm b/lib/CGI/Ex/Conf.pm index 5bcedfd..82c76dc 100644 --- a/lib/CGI/Ex/Conf.pm +++ b/lib/CGI/Ex/Conf.pm @@ -28,7 +28,7 @@ use vars qw($VERSION ); @EXPORT_OK = qw(conf_read conf_write); -$VERSION = '2.01'; +$VERSION = '2.02'; $DEFAULT_EXT = 'conf'; @@ -131,10 +131,14 @@ sub conf_read { ### determine the handler my $handler = $EXT_READERS{$ext} || croak "Unknown file extension: $ext"; - return eval { scalar $handler->($file, $args) } || do { - warn "Couldn't read $file: $@ " if ! $args->{no_warn_on_fail}; - return undef; - }; + ### don't die if the file is not found - do die otherwise + if (! -e $file) { + eval { die "Conf file $file not found" }; + warn "Conf file $file not found" if ! $args->{'no_warn_on_fail'}; + return; + } + + return eval { scalar $handler->($file, $args) } || die "Error while reading conf file $file\n$@"; } sub read_ref { @@ -419,12 +423,7 @@ sub conf_write { $handler = $EXT_WRITERS{$ext} || croak "Unknown file extension: $ext"; } - return eval { scalar $handler->($file, $conf, $args) } || do { - warn "Couldn't write $file: $@ " if ! $args->{no_warn_on_fail}; - return 0; - }; - - return 1; + return eval { scalar $handler->($file, $conf, $args) } || die "Error while writing conf file $file\n$@"; } sub write_ref { @@ -753,6 +752,8 @@ overwritable) by adding a suffix of _immutable or _immu to the key (ie matches $IMMUTABLE_KEY, the entire file is considered immutable. The immutable defaults may be overriden using $IMMUTABLE_QR and $IMMUTABLE_KEY. +Errors during read die. If the file does not exist undef is returned. + =item C<-Ewrite_ref> Takes a file and the reference to be written. Figures out the type @@ -766,6 +767,8 @@ paths where used - the directive 'FIRST' will write the changes to the first file in the path - otherwise the last path will be used. If ->read had found immutable keys, then those keys are removed before writing. +Errors during write die. + =item C<-Epreload_files> Arguments are file(s) and/or directory(s) to preload. preload_files will