use warnings FATAL => 'all';
use base qw(Exporter);
-our $VERSION = '1.003008';
+our $VERSION = '1.004000';
$VERSION = eval $VERSION;
sub _choose_json_module {
BEGIN {
our $JSON_Class = _choose_json_module();
$JSON_Class->import(qw(encode_json decode_json));
+ no strict 'refs';
+ *$_ = $JSON_Class->can($_)
+ for qw(true false);
}
our @EXPORT = qw(encode_json decode_json JSON);
my $json_output = encode_json($data_structure);
- my $json = JSON->new;
+ my $json = JSON()->new;
my $json_with_args = JSON::MaybeXS->new(utf8 => 1); # or { utf8 => 1 }
The C<JSON> constant returns the selected implementation module's name for
use as a class name - so:
- my $json_obj = JSON->new; # returns a Cpanel::JSON::XS or JSON::PP object
+ my $json_obj = JSON()->new; # returns a Cpanel::JSON::XS or JSON::PP object
and that object can then be used normally:
my $data_structure = $json_obj->decode($json_text); # etc.
+The use of parentheses here is optional, and only used as a hint to the reader
+that this use of C<JSON> is a I<subroutine> call, I<not> a class name.
+
=head2 is_bool
$is_boolean = is_bool($scalar)
To include JSON-aware booleans (C<true>, C<false>) in your data, just do:
use JSON::MaybeXS;
- my $true = JSON->true;
- my $false = JSON->false;
+ my $true = JSON()->true;
+ my $false = JSON()->false;
+
+The booleans are also available as subs or methods on JSON::MaybeXS.
+
+ use JSON::MaybeXS ();
+ my $true = JSON::MaybeXS::true;
+ my $true = JSON::MaybeXS->true;
+ my $false = JSON::MaybeXS::false;
+ my $false = JSON::MaybeXS->false;
=head1 CONVERTING FROM JSON::Any