LP#1257264: Use the built-in JSON-y test for bools
authorMike Rylander <mrylander@gmail.com>
Tue, 3 Dec 2013 14:57:39 +0000 (09:57 -0500)
committerJeff Godin <jgodin@tadl.org>
Tue, 3 Dec 2013 18:56:11 +0000 (13:56 -0500)
This removes a dependency on internal details of JSON::XS's
implementation of Boolean types which changed with the release
of JSON::XS 3.0.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Jeff Godin <jgodin@tadl.org>

src/perl/lib/OpenSRF/Utils/JSON.pm

index 58a7a02..a83e9d1 100644 (file)
@@ -160,13 +160,13 @@ sub JSONObject2Perl {
         # is a hash, but no class marker; simply revivify innards
         for my $k (keys %$obj) {
             $obj->{$k} = $pkg->JSONObject2Perl($obj->{$k})
-              unless ref $obj->{$k} eq 'JSON::XS::Boolean';
+              unless JSON::XS::is_bool $obj->{$k};
         }
     } elsif ( ref $obj eq 'ARRAY' ) {
         # not a hash; an array. revivify.
         for my $i (0..scalar(@$obj) - 1) {
             $obj->[$i] = $pkg->JSONObject2Perl($obj->[$i])
-              unless (ref $obj->[$i] eq 'JSON::XS::Boolean');
+              unless JSON::XS::is_bool $obj->[$i];
               # FIXME? This does nothing except leave any Booleans in
               # place, without recursively calling this sub on
               # them. I'm not sure if that's what's supposed to
@@ -205,8 +205,7 @@ sub perl2JSONObject {
     my ($pkg, $obj) = @_;
     my $ref = ref $obj;
 
-    return $obj unless $ref;
-    return $obj if $ref eq 'JSON::XS::Boolean';
+    return $obj if !$ref or JSON::XS::is_bool $obj;
 
     my $jsonobj;