allow scalar refs to be transferred
[scpubgit/Object-Remote.git] / lib / Object / Remote / Connection.pm
index 8f4d443..4d593b3 100644 (file)
@@ -81,6 +81,11 @@ sub _build__json {
       my $code_container = $self->_id_to_remote_object(@_);
       sub { $code_container->call(@_) };
     }
+  )->filter_json_single_key_object(
+    __scalar_ref__ => sub {
+      my $value = shift;
+      return \$value;
+    }
   );
 }
 
@@ -165,12 +170,16 @@ sub send {
   my ($self, $type, @call) = @_;
 
   my $future = CPS::Future->new;
+  my $remote = $self->remote_objects_by_id->{$call[0]};
 
   unshift @call, $type => $self->_local_object_to_id($future);
 
   my $outstanding = $self->outstanding_futures;
   $outstanding->{$future} = $future;
-  $future->on_ready(sub { delete $outstanding->{$future} });
+  $future->on_ready(sub {
+    undef($remote);
+    delete $outstanding->{$future}
+  });
 
   $self->_send(\@call);
 
@@ -232,6 +241,8 @@ sub _deobjectify {
                  Object::Remote::CodeContainer->new(code => $data)
                );
       return +{ __remote_code__ => $id };
+    } elsif ($ref eq 'SCALAR') {
+      return +{ __scalar_ref__ => $$data };
     } else {
       die "Can't collapse reftype $ref";
     }
@@ -333,3 +344,13 @@ sub DEMOLISH {
 }
 
 1;
+
+=head1 NAME
+
+Object::Remote::Connection - An underlying connection for L<Object::Remote>
+
+=head1 LAME
+
+Shipping prioritised over writing this part up. Blame mst.
+
+=cut