Skip to content

detect more boolean types for boolean|long api type #246

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

Open
wants to merge 1 commit into
base: master
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
13 changes: 6 additions & 7 deletions lib/Search/Elasticsearch/Role/API.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use Moo::Role;
requires 'api_version';
requires 'api';

use JSON::MaybeXS qw(is_bool);
use Scalar::Util qw(looks_like_number);
use Search::Elasticsearch::Util qw(throw);
use namespace::clean;
Expand Down Expand Up @@ -57,8 +58,8 @@ sub _detect_bool {
return 'false' if $$val eq 0;
return 'true' if $$val eq 1;
}
elsif ( UNIVERSAL::isa( $val, "JSON::PP::Boolean" ) ) {
return "$val" ? 'true' : 'false';
elsif ( is_bool $val ) {
return $val ? 'true' : 'false';
}
return "$val";
}
Expand Down Expand Up @@ -94,11 +95,9 @@ sub _numOrString {
#===================================
sub _booleanOrLong {
#===================================
if (looks_like_number($_[0])) {
return _num($_[0]);
}
my $val = _detect_bool(@_);
return ( $val && $val ne 'false' ) ? 'true' : 'false';
my $val = _detect_bool($_[0]);
return $val || 'false' if !length $val or $val eq 'true' or $val eq 'false';
return _num($_[0]);
}

#===================================
Expand Down