Skip to content

Commit 45184ba

Browse files
committed
detect more boolean types for boolean|long api type
1 parent 0011656 commit 45184ba

File tree

1 file changed

+6
-7
lines changed
  • lib/Search/Elasticsearch/Role

1 file changed

+6
-7
lines changed

lib/Search/Elasticsearch/Role/API.pm

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use Moo::Role;
2121
requires 'api_version';
2222
requires 'api';
2323

24+
use JSON::MaybeXS qw(is_bool);
2425
use Scalar::Util qw(looks_like_number);
2526
use Search::Elasticsearch::Util qw(throw);
2627
use namespace::clean;
@@ -57,8 +58,8 @@ sub _detect_bool {
5758
return 'false' if $$val eq 0;
5859
return 'true' if $$val eq 1;
5960
}
60-
elsif ( UNIVERSAL::isa( $val, "JSON::PP::Boolean" ) ) {
61-
return "$val" ? 'true' : 'false';
61+
elsif ( is_bool $val ) {
62+
return $val ? 'true' : 'false';
6263
}
6364
return "$val";
6465
}
@@ -94,11 +95,9 @@ sub _numOrString {
9495
#===================================
9596
sub _booleanOrLong {
9697
#===================================
97-
if (looks_like_number($_[0])) {
98-
return _num($_[0]);
99-
}
100-
my $val = _detect_bool(@_);
101-
return ( $val && $val ne 'false' ) ? 'true' : 'false';
98+
my $val = _detect_bool($_[0]);
99+
return $val || 'false' if !length $val or $val eq 'true' or $val eq 'false';
100+
return _num($_[0]);
102101
}
103102

104103
#===================================

0 commit comments

Comments
 (0)