Skip to content

Commit c74a688

Browse files
committed
Cpanel::JSON::XS: use Types::Bool
1 parent dc94a6b commit c74a688

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed

XS.pm

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,6 +2203,8 @@ sub allow_bigint {
22032203
Carp::carp("allow_bigint() is obsoleted. use allow_bignum() instead.");
22042204
}
22052205

2206+
use Types::Bool qw(true false);
2207+
22062208
BEGIN {
22072209
package
22082210
JSON::PP::Boolean;
@@ -2211,9 +2213,6 @@ BEGIN {
22112213

22122214
local $^W; # silence redefine warnings. no warnings 'redefine' does not help
22132215
&overload::import( 'overload', # workaround 5.6 reserved keyword warning
2214-
"0+" => sub { ${$_[0]} },
2215-
"++" => sub { $_[0] = ${$_[0]} + 1 },
2216-
"--" => sub { $_[0] = ${$_[0]} - 1 },
22172216
'""' => sub { ${$_[0]} == 1 ? '1' : '0' }, # GH 29
22182217
'eq' => sub {
22192218
my ($obj, $op) = ref ($_[0]) ? ($_[0], $_[1]) : ($_[1], $_[0]);
@@ -2231,30 +2230,12 @@ BEGIN {
22312230
fallback => 1);
22322231
}
22332232

2234-
our ($true, $false);
2235-
BEGIN {
2236-
if ($INC{'JSON/XS.pm'}
2237-
and $INC{'Types/Serialiser.pm'}
2238-
and $JSON::XS::VERSION ge "3.00") {
2239-
$true = $Types::Serialiser::true; # readonly if loaded by JSON::XS
2240-
$false = $Types::Serialiser::false;
2241-
} else {
2242-
$true = do { bless \(my $dummy = 1), "JSON::PP::Boolean" };
2243-
$false = do { bless \(my $dummy = 0), "JSON::PP::Boolean" };
2244-
}
2245-
}
2246-
2247-
BEGIN {
2248-
my $const_true = $true;
2249-
my $const_false = $false;
2250-
*true = sub () { $const_true };
2251-
*false = sub () { $const_false };
2252-
}
2233+
our ($true, $false) = (true, false);
22532234

22542235
sub is_bool($) {
22552236
shift if @_ == 2; # as method call
22562237
(ref($_[0]) and UNIVERSAL::isa( $_[0], JSON::PP::Boolean::))
2257-
or (exists $INC{'Types/Serialiser.pm'} and Types::Serialiser::is_bool($_[0]))
2238+
or Types::Bool::is_bool($_[0])
22582239
}
22592240

22602241
XSLoader::load 'Cpanel::JSON::XS', $XS_VERSION;

0 commit comments

Comments
 (0)