X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=lib%2FCGI%2FEx%2FConf.pm;h=0fd0199bdc41cb9a34c7ba12f0ce5084a51127e8;hb=febed4ec71f803b083c3e61b82b9464e9bfb0992;hp=420f4de459068797a42d32d0ed1dd584c63a582d;hpb=18123183bfb2737ea337306c9d705fca5b5e50d6;p=chaz%2Fp5-CGI-Ex diff --git a/lib/CGI/Ex/Conf.pm b/lib/CGI/Ex/Conf.pm index 420f4de..0fd0199 100644 --- a/lib/CGI/Ex/Conf.pm +++ b/lib/CGI/Ex/Conf.pm @@ -29,7 +29,7 @@ use vars qw($VERSION ); @EXPORT_OK = qw(conf_read conf_write in_cache); -$VERSION = '2.18'; +$VERSION = '2.27'; $DEFAULT_EXT = 'conf'; @@ -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;