X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=lib%2FCGI%2FEx%2FConf.pm;h=0fdb2f165d9258411d6db0be416c23f556e4f440;hb=6ab8b2e8e8388d1a238148a1ee58e124855f3768;hp=c6e18233f5048a9052179ed8baa62fcbf6dc2861;hpb=f30b8252fcf71659a2fd3b5895e009ff8e39299d;p=chaz%2Fp5-CGI-Ex diff --git a/lib/CGI/Ex/Conf.pm b/lib/CGI/Ex/Conf.pm index c6e1823..0fdb2f1 100644 --- a/lib/CGI/Ex/Conf.pm +++ b/lib/CGI/Ex/Conf.pm @@ -7,7 +7,7 @@ CGI::Ex::Conf - Conf Reader/Writer for many different data format types =cut ###----------------------------------------------------------------### -# Copyright 2007 - Paul Seamons # +# Copyright 2003-2012 - Paul Seamons # # Distributed under the Perl Artistic License without warranty # ###----------------------------------------------------------------### @@ -29,7 +29,7 @@ use vars qw($VERSION ); @EXPORT_OK = qw(conf_read conf_write in_cache); -$VERSION = '2.10'; +$VERSION = '2.37'; $DEFAULT_EXT = 'conf'; @@ -134,7 +134,7 @@ sub conf_read { ### don't die if the file is not found - do die otherwise if (! -e $file) { - eval { die "Conf file $file not found" }; + eval { die "Conf file $file not found\n" }; warn "Conf file $file not found" if ! $args->{'no_warn_on_fail'} && ! $NO_WARN_ON_FAIL; return; } @@ -262,7 +262,9 @@ sub read_handler_json { open (IN, $file) || die "Couldn't open $file: $!"; CORE::read(IN, my $text, -s $file); close IN; - return scalar JSON::jsonToObj($text); + require JSON; + my $decode = JSON->VERSION > 1.98 ? 'decode' : 'jsonToObj'; + return scalar JSON->new->$decode($text); } sub read_handler_storable { @@ -544,7 +546,15 @@ sub write_handler_json { my $file = shift; my $ref = shift; require JSON; - my $str = JSON::objToJson($ref, {pretty => 1, indent => 2}); + my $str; + if (JSON->VERSION > 1.98) { + my $j = JSON->new; + $j->canonical(1); + $j->pretty; + $str = $j->encode($ref); + } else { + $str = JSON->new->objToJSon($ref, {pretty => 1, indent => 2}); + } local *OUT; open (OUT, ">$file") || die $!; print OUT $str; @@ -909,13 +919,13 @@ without even opening the file. Make a similar write method that handles immutability. -=head1 AUTHOR - -Paul Seamons - =head1 LICENSE This module may be distributed under the same terms as Perl itself. +=head1 AUTHOR + +Paul Seamons + =cut