From: Matt S Trout Date: Mon, 14 May 2012 08:16:30 +0000 (+0000) Subject: add ability to do discard sends and make things basically work X-Git-Tag: v0.001001~64 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2065b08ba567dbf8c8370b69e3f5b2aa145efe23;p=scpubgit%2FObject-Remote.git add ability to do discard sends and make things basically work --- diff --git a/lib/Object/Remote.pm b/lib/Object/Remote.pm index 35f5c03..cd3a364 100644 --- a/lib/Object/Remote.pm +++ b/lib/Object/Remote.pm @@ -9,10 +9,8 @@ has connection => (is => 'ro', required => 1); has id => (is => 'rwp'); -has proxy => (is => 'lazy', weak_ref => 1); - -sub _build_proxy { - bless({ remote => $_[0] }, 'Object::Remote::Proxy'); +sub proxy { + bless({ remote => $_[0], method => 'call' }, 'Object::Remote::Proxy'); } sub BUILD { @@ -40,6 +38,11 @@ sub call { $self->_await($self->connection->send(call => $self->id, $method, @args)); } +sub call_discard { + my ($self, $method, @args) = @_; + $self->connection->send_discard(call => $self->id, $method, @args); +} + sub _await { my ($self, $future) = @_; my $loop = $self->current_loop; diff --git a/lib/Object/Remote/Connection.pm b/lib/Object/Remote/Connection.pm index 4e467c9..6ff0b03 100644 --- a/lib/Object/Remote/Connection.pm +++ b/lib/Object/Remote/Connection.pm @@ -31,9 +31,7 @@ has _receive_data_buffer => (is => 'ro', default => sub { my $x = ''; \$x }); has local_objects_by_id => (is => 'ro', default => sub { {} }); -has remote_objects_by_id => ( - is => 'ro', default => sub { { NULL => bless({}, 'Object::Remote::Null') } } -); +has remote_objects_by_id => (is => 'ro', default => sub { {} }); has _json => ( is => 'lazy', @@ -49,6 +47,7 @@ sub _build__json { JSON::PP->new->filter_json_single_key_object( __remote_object__ => sub { my $id = shift; + return bless({}, 'Object::Remote::Null') if $id eq 'NULL'; ( $remotes->{$id} or Object::Remote->new(connection => $self, id => $id) @@ -82,7 +81,7 @@ sub send { sub send_discard { my ($self, $type, @call) = @_; - unshift @call, $type => { __remote_object => 'NULL' }; + unshift @call, $type => { __remote_object__ => 'NULL' }; $self->_send(\@call); } @@ -155,6 +154,7 @@ sub receive_free { sub receive_call { my ($self, $future, $id, @rest) = @_; + $future->{method} = 'call_discard'; my $local = $self->local_objects_by_id->{$id} or do { $future->fail("No such object $id"); return }; $self->_invoke($future, $local, @rest); @@ -162,6 +162,7 @@ sub receive_call { sub receive_class_call { my ($self, $future, $class, @rest) = @_; + $future->{method} = 'call_discard'; eval { use_module($class) } or do { $future->fail("Error loading ${class}: $@"); return }; $self->_invoke($future, $class, @rest); diff --git a/lib/Object/Remote/Proxy.pm b/lib/Object/Remote/Proxy.pm index a3e2a80..8541056 100644 --- a/lib/Object/Remote/Proxy.pm +++ b/lib/Object/Remote/Proxy.pm @@ -5,7 +5,7 @@ use strictures 1; sub AUTOLOAD { my $self = shift; (my $method) = (our $AUTOLOAD =~ /([^:]+)$/); - $self->{remote}->call($method => @_); + $self->{remote}->${\$self->{method}}($method => @_); } sub DESTROY { }