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};
24 ref($_) eq 'HASH' and $_ = [ %$_ ] for $args->{args};
27 $self->connection->send(
28 class_call => $args->{class},
29 $args->{constructor}||'new', @{$args->{args}||[]}
31 )->{remote}->disarm_free->id
34 $self->connection->register_remote($self);
38 our $Current_Loop ||= Object::Remote::MiniLoop->new
42 my ($self, $method, @args) = @_;
43 $self->_await($self->connection->send(call => $self->id, $method, @args));
47 my ($self, $method, @args) = @_;
48 $self->connection->send_discard(call => $self->id, $method, @args);
51 sub call_discard_free {
52 my ($self, $method, @args) = @_;
54 $self->connection->send_discard(call_free => $self->id, $method, @args);
58 my ($self, $future) = @_;
59 my $loop = $self->current_loop;
60 $future->on_ready(sub { $loop->stop });
67 return if $gd or $self->disarmed_free;
68 $self->connection->send_free($self->id);