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 proxy => (is => 'lazy', weak_ref => 1);
15 bless({ handle => $_[0] }, 'Object::Remote::Proxy');
19 my ($self, $args) = @_;
21 die "No id supplied and no class either" unless $args->{class};
24 $self->connection->send(
25 class_call => $args->{class},
26 $args->{constructor}||'new', @{$args->{args}||[]}
31 $self->connection->register_remote($self);
35 our $Current_Loop ||= Object::Remote::MiniLoop->new
39 my ($self, $id, $method, @args) = @_;
40 $self->_await($self->connection->send(call => $self->id, $method, @args));
44 my ($self, $future) = @_;
45 my $loop = $self->current_loop;
46 $future->on_ready(sub { $loop->stop });
54 $self->connection->send_free($self->id);