From f1c4ee8e2dcd561b31bf024d256534a24e797d44 Mon Sep 17 00:00:00 2001 From: sboyette Date: Tue, 15 Sep 2009 16:19:47 +0000 Subject: [PATCH 1/1] WIP git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1789 9efc2488-bf62-4759-914b-345cdb29e865 --- src/perl/lib/OpenSRF/Utils/JSON.pm | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/perl/lib/OpenSRF/Utils/JSON.pm b/src/perl/lib/OpenSRF/Utils/JSON.pm index 6e8e700..723b779 100644 --- a/src/perl/lib/OpenSRF/Utils/JSON.pm +++ b/src/perl/lib/OpenSRF/Utils/JSON.pm @@ -124,7 +124,7 @@ sub rawPerl2JSON { =head2 JSONObject2Perl -Final routine in the object re-vivification chain, called by L. +Intermediate routine called by L. =cut @@ -157,7 +157,12 @@ sub JSONObject2Perl { # 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 (ref $obj->[$i] eq 'JSON::XS::Boolean'); + # 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 + # happen, or if they're supposed to be thrown out of the + # array } } @@ -176,24 +181,24 @@ sub perl2JSONObject { my $ref = ref $obj; return $obj unless $ref; - return $obj if $ref eq 'JSON::XS::Boolean'; - my $newobj; + + my $jsonobj; if(UNIVERSAL::isa($obj, 'HASH')) { - $newobj = {}; - $newobj->{$_} = $pkg->perl2JSONObject($obj->{$_}) for (keys %$obj); + $jsonobj = {}; + $jsonobj->{$_} = $pkg->perl2JSONObject($obj->{$_}) for (keys %$obj); } elsif(UNIVERSAL::isa($obj, 'ARRAY')) { - $newobj = []; - $newobj->[$_] = $pkg->perl2JSONObject($obj->[$_]) for(0..scalar(@$obj) - 1); + $jsonobj = []; + $jsonobj->[$_] = $pkg->perl2JSONObject($obj->[$_]) for(0..scalar(@$obj) - 1); } if($ref ne 'HASH' and $ref ne 'ARRAY') { - $ref = $pkg->lookup_hint($ref) || $ref; - $newobj = {$JSON_CLASS_KEY => $ref, $JSON_PAYLOAD_KEY => $newobj}; + $ref = $pkg->lookup_hint($ref) if $pkg->lookup_hint($ref); + $jsonobj = {$JSON_CLASS_KEY => $ref, $JSON_PAYLOAD_KEY => $jsonobj}; } - return $newobj; + return $jsonobj; } -- 2.43.2