Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ WriteMakefile(
NAME => "Cpanel::JSON::XS",
PREREQ_PM => {
'Pod::Text' => '2.08',
'Data::Bool' => '0',
},
DEFINE => $define,
LICENSE => 'perl',
Expand Down
28 changes: 4 additions & 24 deletions XS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2203,17 +2203,15 @@ sub allow_bigint {
Carp::carp("allow_bigint() is obsoleted. use allow_bignum() instead.");
}

use Data::Bool qw(true false);

BEGIN {
package
JSON::PP::Boolean;

require overload;

local $^W; # silence redefine warnings. no warnings 'redefine' does not help
&overload::import( 'overload', # workaround 5.6 reserved keyword warning
"0+" => sub { ${$_[0]} },
"++" => sub { $_[0] = ${$_[0]} + 1 },
"--" => sub { $_[0] = ${$_[0]} - 1 },
'""' => sub { ${$_[0]} == 1 ? '1' : '0' }, # GH 29
'eq' => sub {
my ($obj, $op) = ref ($_[0]) ? ($_[0], $_[1]) : ($_[1], $_[0]);
Expand All @@ -2231,29 +2229,11 @@ BEGIN {
fallback => 1);
}

our ($true, $false);
BEGIN {
if ($INC{'JSON/XS.pm'}
and $INC{'Types/Serialiser.pm'}
and $JSON::XS::VERSION ge "3.00") {
$true = $Types::Serialiser::true; # readonly if loaded by JSON::XS
$false = $Types::Serialiser::false;
} else {
$true = do { bless \(my $dummy = 1), "JSON::PP::Boolean" };
$false = do { bless \(my $dummy = 0), "JSON::PP::Boolean" };
}
}

BEGIN {
my $const_true = $true;
my $const_false = $false;
*true = sub () { $const_true };
*false = sub () { $const_false };
}
our ($true, $false) = (true, false);

sub is_bool($) {
shift if @_ == 2; # as method call
(ref($_[0]) and UNIVERSAL::isa( $_[0], JSON::PP::Boolean::))
(ref($_[0]) and UNIVERSAL::isa( $_[0], Data::Bool::BOOL_PACKAGE))
or (exists $INC{'Types/Serialiser.pm'} and Types::Serialiser::is_bool($_[0]))
}

Expand Down