Skip to content

Commit

Permalink
make JSON::Validator::Util::is_bool return true when passed perl v5.3…
Browse files Browse the repository at this point in the history
…6+ builtin booleans
  • Loading branch information
akarelas committed Aug 8, 2024
1 parent f463896 commit 6e08068
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/JSON/Validator/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use Mojo::Util;
use Scalar::Util 'blessed';

use constant SEREAL_SUPPORT => !$ENV{JSON_VALIDATOR_NO_SEREAL} && eval 'use Sereal::Encoder 4.00;1';
use constant CORE_BOOL => defined &builtin::is_bool;

our @EXPORT_OK = (
qw(E data_checksum data_section data_type is_bool is_num is_type),
Expand Down Expand Up @@ -70,7 +71,13 @@ sub data_type {
return $blessed || 'string';
}

sub is_bool { blessed $_[0] && ($_[0]->isa('JSON::PP::Boolean') || "$_[0]" eq "1" || !$_[0]) }
sub is_bool {
if (CORE_BOOL) {
BEGIN { warnings->unimport('experimental::builtin') if CORE_BOOL }
return !!1 if builtin::is_bool $_[0];
}
blessed $_[0] && ($_[0]->isa('JSON::PP::Boolean') || "$_[0]" eq "1" || !$_[0]);
}
sub is_num { B::svref_2object(\$_[0])->FLAGS & (B::SVp_IOK | B::SVp_NOK) && 0 + $_[0] eq $_[0] && $_[0] * 0 == 0 }
sub is_type { blessed $_[0] ? $_[0]->isa($_[1]) : ref $_[0] eq $_[1] }

Expand Down

0 comments on commit 6e08068

Please sign in to comment.