1 package Object::Remote;
3 use Object::Remote::MiniLoop;
4 use Object::Remote::Proxy;
5 use Scalar::Util qw(weaken blessed);
6 use Module::Runtime qw(use_module);
10 my ($class, $on, @args) = @_;
19 is => 'ro', required => 1,
23 : use_module('Object::Remote::Connection')->new_from_spec($_[0])
27 has id => (is => 'rwp');
29 has disarmed_free => (is => 'rwp');
31 sub disarm_free { $_[0]->_set_disarmed_free(1); $_[0] }
34 bless({ remote => $_[0], method => 'call' }, 'Object::Remote::Proxy');
38 my ($self, $args) = @_;
40 die "No id supplied and no class either" unless $args->{class};
41 ref($_) eq 'HASH' and $_ = [ %$_ ] for $args->{args};
44 $self->connection->send(
45 class_call => $args->{class}, 0,
46 $args->{constructor}||'new', @{$args->{args}||[]}
48 )->{remote}->disarm_free->id
51 $self->connection->register_remote($self);
55 our $Current_Loop ||= Object::Remote::MiniLoop->new
59 my ($self, $method, @args) = @_;
61 $self->connection->send(call => $self->id, wantarray, $method, @args)
66 my ($self, $method, @args) = @_;
67 $self->connection->send_discard(call => $self->id, $method, @args);
70 sub call_discard_free {
71 my ($self, $method, @args) = @_;
73 $self->connection->send_discard(call_free => $self->id, $method, @args);
77 my ($self, $future) = @_;
78 my $loop = $self->current_loop;
79 $future->on_ready(sub { $loop->stop });
81 wantarray ? $future->get : ($future->get)[0];
86 return if $gd or $self->disarmed_free;
87 $self->connection->send_free($self->id);