1 package Object::Remote::Handle;
3 use Object::Remote::Proxy;
4 use Scalar::Util qw(weaken blessed);
5 use Object::Remote::Future;
6 use Module::Runtime qw(use_module);
10 is => 'ro', required => 1,
14 : use_module('Object::Remote::Connection')->new_from_spec($_[0])
18 has id => (is => 'rwp');
20 has disarmed_free => (is => 'rwp');
22 sub disarm_free { $_[0]->_set_disarmed_free(1); $_[0] }
25 bless({ remote => $_[0], method => 'call' }, 'Object::Remote::Proxy');
29 my ($self, $args) = @_;
31 die "No id supplied and no class either" unless $args->{class};
32 ref($_) eq 'HASH' and $_ = [ %$_ ] for $args->{args};
35 $self->connection->send(
36 class_call => $args->{class}, 0,
37 $args->{constructor}||'new', @{$args->{args}||[]}
39 )->{remote}->disarm_free->id
42 $self->connection->register_remote($self);
46 my ($self, $method, @args) = @_;
48 $method = "start::${method}" if (caller(0)||'') eq 'start';
50 $self->connection->send(call => $self->id, $w, $method, @args)
55 my ($self, $method, @args) = @_;
56 $self->connection->send_discard(call => $self->id, $method, @args);
59 sub call_discard_free {
60 my ($self, $method, @args) = @_;
62 $self->connection->send_discard(call_free => $self->id, $method, @args);
67 return if $gd or $self->disarmed_free;
68 $self->connection->send_free($self->id);