X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FObject%2FRemote.pm;h=a81550181cc09dd6ffebf4bc8db6e34ad564e77b;hb=8131a88a11a61f4d829e88e609575cf2855f7428;hp=35f5c03171939e2eb9af24dc994e7f1362de2426;hpb=9d804009b5363c739598a9cc4507df57a2d59c55;p=scpubgit%2FObject-Remote.git diff --git a/lib/Object/Remote.pm b/lib/Object/Remote.pm index 35f5c03..a815501 100644 --- a/lib/Object/Remote.pm +++ b/lib/Object/Remote.pm @@ -9,10 +9,12 @@ has connection => (is => 'ro', required => 1); has id => (is => 'rwp'); -has proxy => (is => 'lazy', weak_ref => 1); +has disarmed_free => (is => 'rwp'); -sub _build_proxy { - bless({ remote => $_[0] }, 'Object::Remote::Proxy'); +sub disarm_free { $_[0]->_set_disarmed_free(1); $_[0] } + +sub proxy { + bless({ remote => $_[0], method => 'call' }, 'Object::Remote::Proxy'); } sub BUILD { @@ -25,7 +27,7 @@ sub BUILD { class_call => $args->{class}, $args->{constructor}||'new', @{$args->{args}||[]} ) - ) + )->{remote}->disarm_free->id ); } $self->connection->register_remote($self); @@ -40,17 +42,28 @@ 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 call_discard_free { + my ($self, $method, @args) = @_; + $self->disarm_free; + $self->connection->send_discard(call_free => $self->id, $method, @args); +} + sub _await { my ($self, $future) = @_; my $loop = $self->current_loop; $future->on_ready(sub { $loop->stop }); $loop->run; - $future->get; + ($future->get)[0]; } sub DEMOLISH { my ($self, $gd) = @_; - return if $gd; + return if $gd or $self->disarmed_free; $self->connection->send_free($self->id); }