Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make JSON::Validator::Util::is_bool return true when passed perl v5.36+ builtin booleans #275

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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
Loading