1 package Object::Remote;
3 use Object::Remote::MiniLoop;
4 use Object::Remote::Proxy;
5 use Scalar::Util qw(weaken);
8 has connection => (is => 'ro', required => 1);
10 has id => (is => 'rwp');
12 has disarmed_free => (is => 'rwp');
14 sub disarm_free { $_[0]->_set_disarmed_free(1); $_[0] }
17 bless({ remote => $_[0], method => 'call' }, 'Object::Remote::Proxy');
21 my ($self, $args) = @_;
23 die "No id supplied and no class either" unless $args->{class};
26 $self->connection->send(
27 class_call => $args->{class},
28 $args->{constructor}||'new', @{$args->{args}||[]}
30 )->{remote}->disarm_free->id
33 $self->connection->register_remote($self);
37 our $Current_Loop ||= Object::Remote::MiniLoop->new
41 my ($self, $method, @args) = @_;
42 $self->_await($self->connection->send(call => $self->id, $method, @args));
46 my ($self, $method, @args) = @_;
47 $self->connection->send_discard(call => $self->id, $method, @args);
50 sub call_discard_free {
51 my ($self, $method, @args) = @_;
53 $self->connection->send_discard(call_free => $self->id, $method, @args);
57 my ($self, $future) = @_;
58 my $loop = $self->current_loop;
59 $future->on_ready(sub { $loop->stop });
66 return if $gd or $self->disarmed_free;
67 $self->connection->send_free($self->id);