Teach opensrf object registration how to strip certain object members user/miker/lp-1350457-pass_caller_session
authorMike Rylander <mrylander@gmail.com>
Fri, 22 Aug 2014 17:00:35 +0000 (13:00 -0400)
committerMike Rylander <mrylander@gmail.com>
Fri, 22 Aug 2014 17:00:35 +0000 (13:00 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
src/perl/lib/OpenSRF/Application.pm
src/perl/lib/OpenSRF/Utils/JSON.pm

index d409957..023bb8d 100644 (file)
@@ -437,7 +437,12 @@ sub register_method {
                ($args{object_hint} = $args{package}) =~ s/::/_/go;
        }
 
-       OpenSRF::Utils::JSON->register_class_hint( name => $args{package}, hint => $args{object_hint}, type => "hash" );
+       OpenSRF::Utils::JSON->register_class_hint(
+               strip => ['session'],
+               name => $app,
+               hint => $args{object_hint},
+               type => "hash"
+       );
 
        $_METHODS[$args{api_level}]{$args{api_name}} = bless \%args => $app;
 
@@ -559,7 +564,7 @@ sub method_lookup {
                $meth = $self->method_lookup($method,$proto,1);
        }
 
-       $meth->session($self->session) if $meth; # Pass the caller's session
+       $meth->session($self->session) if $meth && ref($self); # Pass the caller's session
        return $meth;
 }
 
index 6411870..4efa3dc 100644 (file)
@@ -212,7 +212,14 @@ sub perl2JSONObject {
 
     if(UNIVERSAL::isa($obj, 'HASH')) {
         $jsonobj = {};
-        $jsonobj->{$_} = $pkg->perl2JSONObject($obj->{$_}) for (keys %$obj);
+        for my $k (keys %$obj) {
+            next if (
+                $ref ne 'HASH'
+                and exists $_class_map{classes}{$ref}{strip}
+                and grep { $k eq $_ } @{$_class_map{classes}{$ref}{strip}}
+            );
+            $jsonobj->{$k} = $pkg->perl2JSONObject($obj->{$k});
+        }
     } elsif(UNIVERSAL::isa($obj, 'ARRAY')) {
         $jsonobj = [];
         $jsonobj->[$_] = $pkg->perl2JSONObject($obj->[$_]) for(0..scalar(@$obj) - 1);