Exclude vendorarch and sitearch from FatNode and ModuleSender
[scpubgit/Object-Remote.git] / lib / Object / Remote / Handle.pm
CommitLineData
676438a1 1package Object::Remote::Handle;
2
3use Object::Remote::Proxy;
4use Scalar::Util qw(weaken blessed);
5use Object::Remote::Future;
6use Module::Runtime qw(use_module);
7use Moo;
8
9has connection => (
10 is => 'ro', required => 1,
11 coerce => sub {
12 blessed($_[0])
13 ? $_[0]
14 : use_module('Object::Remote::Connection')->new_from_spec($_[0])
15 },
16);
17
18has id => (is => 'rwp');
19
20has disarmed_free => (is => 'rwp');
21
22sub disarm_free { $_[0]->_set_disarmed_free(1); $_[0] }
23
24sub proxy {
25 bless({ remote => $_[0], method => 'call' }, 'Object::Remote::Proxy');
26}
27
28sub BUILD {
29 my ($self, $args) = @_;
1d26d6f9 30 if ($self->id) {
31 $self->disarm_free;
32 } else {
676438a1 33 die "No id supplied and no class either" unless $args->{class};
34 ref($_) eq 'HASH' and $_ = [ %$_ ] for $args->{args};
35 $self->_set_id(
36 await_future(
f7611866 37 $self->connection->send_class_call(
38 0, $args->{class},
676438a1 39 $args->{constructor}||'new', @{$args->{args}||[]}
40 )
41 )->{remote}->disarm_free->id
42 );
43 }
44 $self->connection->register_remote($self);
45}
46
47sub call {
48 my ($self, $method, @args) = @_;
49 my $w = wantarray;
50 $method = "start::${method}" if (caller(0)||'') eq 'start';
51 future {
52 $self->connection->send(call => $self->id, $w, $method, @args)
53 };
54}
55
56sub call_discard {
57 my ($self, $method, @args) = @_;
58 $self->connection->send_discard(call => $self->id, $method, @args);
59}
60
61sub call_discard_free {
62 my ($self, $method, @args) = @_;
63 $self->disarm_free;
64 $self->connection->send_discard(call_free => $self->id, $method, @args);
65}
66
67sub DEMOLISH {
68 my ($self, $gd) = @_;
69 return if $gd or $self->disarmed_free;
70 $self->connection->send_free($self->id);
71}
72
731;