From: Robert 'phaylon' Sedlacek Date: Mon, 16 Jul 2012 22:07:17 +0000 (+0000) Subject: allow scalar refs to be transferred X-Git-Tag: v0.002002~17 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FObject-Remote.git;a=commitdiff_plain;h=6ed5d5804fa1e932a18619c971e4704a34b85dc8;hp=1e3802e134845405a3aa45ec916d9dc6282925cd allow scalar refs to be transferred --- diff --git a/Changes b/Changes index f4f9368..b00d9ea 100644 --- a/Changes +++ b/Changes @@ -1,2 +1,4 @@ + - allow transfer of scalar references + 0.001001 - 2012-07-12 - initial release diff --git a/lib/Object/Remote/Connection.pm b/lib/Object/Remote/Connection.pm index 3c5eb36..4d593b3 100644 --- a/lib/Object/Remote/Connection.pm +++ b/lib/Object/Remote/Connection.pm @@ -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 index 0000000..372c877 --- /dev/null +++ b/t/lib/ORTestTransfer.pm @@ -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 index 0000000..d5c6a48 --- /dev/null +++ b/t/transfer.t @@ -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;