package JSON::Conditional;
use 5.006; use strict; use warnings; our $VERSION = '1.02';
use JSON; use base 'Struct::Conditional';
our $JSON;
BEGIN {
$JSON = JSON->new->pretty(1)->allow_blessed->conv
ert_blessed;
}
sub encode {
if ($_[2]) {
$_[0]->encode_file($_[1], $_[2]);
}
$JSON->encode($_[1]);
}
sub encode_file {
open my $file, '>', $_[2] or die "cannot open file $!";
print $file $_[0
le;
}
sub decode {
if ( $_[1] !~ m/\n/ && -f $_[1]) {
return $_[0]->decode_file($_[1]);
}
$JSON->decode($_[1]);
}
sub decode_file {
open my $file, '<', $_[1] or die "cannot open file $!";
my