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');
13 bless({ remote => $_[0], method => 'call' }, 'Object::Remote::Proxy');
17 my ($self, $args) = @_;
19 die "No id supplied and no class either" unless $args->{class};
22 $self->connection->send(
23 class_call => $args->{class},
24 $args->{constructor}||'new', @{$args->{args}||[]}
29 $self->connection->register_remote($self);
33 our $Current_Loop ||= Object::Remote::MiniLoop->new
37 my ($self, $method, @args) = @_;
38 $self->_await($self->connection->send(call => $self->id, $method, @args));
42 my ($self, $method, @args) = @_;
43 $self->connection->send_discard(call => $self->id, $method, @args);
47 my ($self, $future) = @_;
48 my $loop = $self->current_loop;
49 $future->on_ready(sub { $loop->stop });
57 $self->connection->send_free($self->id);