allow scalar refs to be transferred
Robert 'phaylon' Sedlacek [Mon, 16 Jul 2012 22:07:17 +0000 (22:07 +0000)]
Changes
lib/Object/Remote/Connection.pm
t/lib/ORTestTransfer.pm [new file with mode: 0644]
t/transfer.t [new file with mode: 0644]

diff --git a/Changes b/Changes
index f4f9368..b00d9ea 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,2 +1,4 @@
+  - allow transfer of scalar references
+
 0.001001 - 2012-07-12
   - initial release
index 3c5eb36..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;
+    }
   );
 }
 
@@ -236,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";
     }
diff --git a/t/lib/ORTestTransfer.pm b/t/lib/ORTestTransfer.pm
new file mode 100644 (file)
index 0000000..372c877
--- /dev/null
@@ -0,0 +1,6 @@
+package ORTestTransfer;
+use Moo;
+
+has value => (is => 'rw');
+
+1;
diff --git a/t/transfer.t b/t/transfer.t
new file mode 100644 (file)
index 0000000..d5c6a48
--- /dev/null
@@ -0,0 +1,25 @@
+use strictures 1;
+use Test::More;
+use Test::Fatal;
+
+$ENV{PERL5LIB} = join(
+  ':', ($ENV{PERL5LIB} ? $ENV{PERL5LIB} : ()), qw(lib t/lib)
+);
+
+use Object::Remote;
+
+my $strA = 'foo';
+my $strB = 'bar';
+
+is exception {
+  my $proxy = ORTestTransfer->new::on('-', value => \$strA);
+  is_deeply $proxy->value, \$strA, 'correct value after construction';
+}, undef, 'no errors during construction';
+
+is exception {
+  my $proxy = ORTestTransfer->new::on('-');
+  $proxy->value(\$strB);
+  is_deeply $proxy->value, \$strB, 'correct value after construction';
+}, undef, 'no errors during attribute set';
+
+done_testing;