Skip to content

Commit

Permalink
don't skip blessed JSON::PP::Boolean values for expected scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeyn committed Oct 20, 2016
1 parent 104a0bd commit 1487187
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions cpanfile
Expand Up @@ -2,6 +2,7 @@ requires "Carp" => "0";
requires "HTTP::Tiny" => "0.056";
requires "IO::Socket::SSL" => "1.42";
requires "JSON::MaybeXS" => "0";
requires "JSON::PP" => "0";
requires "Moo" => "0";
requires "Moo::Role" => "0";
requires "Net::SSLeay" => "1.49";
Expand Down
8 changes: 7 additions & 1 deletion lib/MetaCPAN/Client/Role/Entity.pm
Expand Up @@ -5,6 +5,7 @@ package MetaCPAN::Client::Role::Entity;

use Moo::Role;

use JSON::PP;
use Ref::Util qw< is_ref is_arrayref is_hashref >;

has data => (
Expand Down Expand Up @@ -32,7 +33,12 @@ sub BUILDARGS {
$args{data}{$k} = $args{data}{$k}->[0]
if is_arrayref( $args{data}{$k} ) and @{$args{data}{$k}} == 1;

delete $args{data}{$k} if is_ref( $args{data}{$k} ); # warn?
if ( JSON::PP::is_bool($args{data}{$k}) ) {
$args{data}{$k} = JSON::PP::true == $args{data}{$k} ? 1 : 0;
}
elsif ( is_ref( $args{data}{$k} ) ) {
delete $args{data}{$k};
}
}

for my $k ( @{ $known_fields->{arrayref} } ) {
Expand Down

0 comments on commit 1487187

Please sign in to comment.