=cut
###----------------------------------------------------------------###
-# Copyright 2007 - Paul Seamons #
+# Copyright 2003-2012 - Paul Seamons #
# Distributed under the Perl Artistic License without warranty #
###----------------------------------------------------------------###
);
@EXPORT_OK = qw(conf_read conf_write in_cache);
-$VERSION = '2.16';
+$VERSION = '2.37';
$DEFAULT_EXT = 'conf';
### 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;
}
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 {
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;