Subject: | is_bool() incompatible with JSON::XS |
Given a JSON object created via JSON::XS, JSON::PP::is_bool() cannot recognize a boolean. I found this while testing an existing script like so:
% myScript.pl
foo=bar
this=true!
Config/Any/JSON.pm /Users/kstar/perl5/perlbrew/perls/perl-5.19.0/lib/site_perl/5.19.0/Config/Any/JSON.pm
JSON.pm /Users/kstar/perl5/perlbrew/perls/perl-5.19.0/lib/site_perl/5.19.0/JSON.pm
JSON/MaybeXS.pm /Users/kstar/perl5/perlbrew/perls/perl-5.19.0/lib/site_perl/5.19.0/JSON/MaybeXS.pm
JSON/XS.pm /Users/kstar/perl5/perlbrew/perls/perl-5.19.0/lib/site_perl/5.19.0/darwin-2level/JSON/XS.pm
$JSON::VERSION 2.59
$JSON::MaybeXS::VERSION 1.002002
$JSON::PP::VERSION <undef>
$JSON::XS::VERSION 2.34
% PERL_JSON_BACKEND=0 myScript.pl
foo=bar
this=true (ref JSON::XS::Boolean)
Config/Any/JSON.pm /Users/kstar/perl5/perlbrew/perls/perl-5.19.0/lib/site_perl/5.19.0/Config/Any/JSON.pm
JSON.pm /Users/kstar/perl5/perlbrew/perls/perl-5.19.0/lib/site_perl/5.19.0/JSON.pm
JSON/MaybeXS.pm /Users/kstar/perl5/perlbrew/perls/perl-5.19.0/lib/site_perl/5.19.0/JSON/MaybeXS.pm
JSON/PP.pm /Users/kstar/perl5/perlbrew/perls/perl-5.19.0/lib/site_perl/5.19.0/JSON/PP.pm
JSON/XS.pm /Users/kstar/perl5/perlbrew/perls/perl-5.19.0/lib/site_perl/5.19.0/darwin-2level/JSON/XS.pm
$JSON::VERSION 2.59
$JSON::MaybeXS::VERSION 1.002002
$JSON::PP::VERSION 2.27300
$JSON::XS::VERSION 2.34
myScript.pl and file.json attached.
Subject: | file.json |
{
"foo": "bar",
"this": true
}
Subject: | myScript.pl |
#!/usr/bin/env perl
require Config::Any::JSON;
require JSON;
my $config = Config::Any::JSON->load('file.json');
show($_, $$config{$_}) for sort keys %$config;
printf(" %-25s %s\n", $_, $INC{$_}) for sort grep { /JSON/ } keys %INC;
foreach my $var (
'$JSON::VERSION',
'$JSON::MaybeXS::VERSION',
'$JSON::PP::VERSION',
'$JSON::XS::VERSION',
) {
printf " %-25s %s\n", $var, eval $var // '<undef>';
}
sub show {
my ($key, $val) = @_;
my $ref = ref $val;
if (not $ref) {
print "$key=$val\n";
} elsif (JSON::is_bool($ref)) {
printf "%s=%s\n", $key, ($val eq JSON::true() ? 'true!' : 'false!');
} else {
printf "%s=%s (ref %s)\n", $key, $val, $ref;
}
}