Remote/Handle.pm

filter: Statementstmt 80.3% 53 / 66 Branchbran 78.5% 11 / 14 Conditioncond 66.6% 8 / 12 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 62.5% 15 / 24 Podpod 0.0% 0 / 7 totaltotal 68.4% 89 / 130 CC 26 SCAR 13.3
CC
26
Cov
78%
BUILD
7.6
BUILD
7.6
DEMOLISH
5.5
CRAP 3.8
« Remote/Future.pm ↑ Summary Remote/Logging/Router.pm »
1 package Object::Remote::Handle;
2  
3 30 ▶use Object::Remote::Proxy;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 30 ▶use Scalar::Util qw(weaken blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use Object::Remote::Logging qw ( :log :dlog router );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 15 ▶use Object::Remote::Future;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use Module::Runtime qw(use_module);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 15 ▶BEGIN { router()->exclude_forwarding }
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 has connection => (
13 is => 'ro', required => 1, handles => ['is_valid'],
14 129 ▶ coerce => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
15 129 ▶ blessed($_[0])
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_[0]) ? : 129 0 129
16 ? $_[0]
17 : use_module('Object::Remote::Connection')->new_from_spec($_[0])
18 },
19 );
20  
21 has id => (is => 'rwp');
22  
23 has disarmed_free => (is => 'rwp');
24  
25 168 ▶sub disarm_free { $_[0]->_set_disarmed_free(1); $_[0] }
Subroutine disarm_free: called CC=1 SCAR=0.0
Pod undocumented
26  
27 sub proxy {
28 110 ▶ bless({ remote => $_[0], method => 'call' }, 'Object::Remote::Proxy');
Subroutine proxy: called CC=1 SCAR=0.0
Pod undocumented
29 }
30  
31 sub BUILD {
32 129 ▶ my ($self, $args) = @_;
Subroutine BUILD: called CC=7 SCAR=20.3
Pod undocumented
33 129 ▶ log_trace { "constructing remote handle" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
34 129 ▶ if ($self->id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->id) { } 89 40 129
35 89 ▶ log_trace { "disarming free for this handle" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
36 89 $self->disarm_free;
37 } else {
38 40 ▶ die "No id supplied and no class either" unless $args->{class};
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"class"} 0 40 40
39 40 ▶ ref($_) eq 'HASH' and $_ = [ %$_ ] for $args->{args};
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq "HASH" and $_ = [%$_] 19 21 40
40 40 ▶ log_trace { "fetching id for handle and disarming free on remote side" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
41 $self->_set_id(
42 await_future(
43 $self->connection->send_class_call(
44 0, $args->{class},
45 40 ▶ $args->{constructor}||'new', @{$args->{args}||[]}
Condition100%2/2
$args->{'args'} || []
l!l
391
MC/DC100%1/1
$args->{'args'} || []
$args->{'args'}
Truth table100%2/2
A
A= $args->{'args'}
Aresult
11
00
46 )
47 )->{remote}->disarm_free->id
48 40 ▶ );
Condition50%1/2
$args->{'constructor'} || 'new'
l!l
040
MC/DC0%0/1
$args->{'constructor'} || 'new'
$args->{'constructor'}
Truth table50%1/2
A
A= $args->{'constructor'}
Aresult
11
00
49 }
50 128 ▶ Dlog_trace { "finished constructing remote handle; id is $_" } $self->id;
Subroutine __ANON__: not called CC=1 SCAR=1.2
51 128 $self->connection->register_remote($self);
52 }
53  
54 sub call {
55 87 ▶ my ($self, $method, @args) = @_;
Subroutine call: called CC=3 SCAR=11.3
Pod undocumented
56 87 my $w = wantarray;
57 87 my $id = $self->id;
58  
59 87 ▶ $method = "start::${method}" if (caller(0)||'') eq 'start';
Branch: 1 branch
BranchTrueFalseTotal
if (caller 0 || "") eq "start" 4 83 87
Condition50%1/2
caller 0 || ''
l!l
870
MC/DC0%0/1
caller 0 || ''
caller 0
Truth table50%1/2
A
A= caller 0
Aresult
11
00
60 87 ▶ log_trace { "call('$method') has been invoked on remote handle '$id'; creating future" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
61  
62 future {
63 87 ▶ log_debug { "Invoking send on connection for handle '$id' method '$method'" };
Subroutine __ANON__: called CC=1 SCAR=0.0
64 0 $self->connection->send(call => $id, $w, $method, @args)
65 87 };
66 }
67  
68 sub call_discard {
69 0 ▶ my ($self, $method, @args) = @_;
Subroutine call_discard: not called CC=1 SCAR=6.9
Pod undocumented
70 0 ▶ log_trace { "invoking send_discard() with 'call' for method '$method' on connection for remote handle" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
71 0 $self->connection->send_discard(call => $self->id, $method, @args);
72 }
73  
74 sub call_discard_free {
75 21 ▶ my ($self, $method, @args) = @_;
Subroutine call_discard_free: called CC=1 SCAR=0.1
Pod undocumented
76 21 $self->disarm_free;
77 21 ▶ log_trace { "invoking send_discard() with 'call_free' for method '$method' on connection for remote handle" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
78 21 $self->connection->send_discard(call_free => $self->id, $method, @args);
79 }
80  
81 sub DEMOLISH {
82 127 ▶ my ($self, $gd) = @_;
Subroutine DEMOLISH: called CC=5 SCAR=17.1
Pod undocumented
83 127 ▶ Dlog_trace { "Demolishing remote handle $_" } $self->id;
Subroutine __ANON__: not called CC=1 SCAR=1.2
84 127 ▶ return if $gd or $self->disarmed_free;
Branch: 1 branch
BranchTrueFalseTotal
if $gd or $self->disarmed_free 108 19 127
Condition66%2/3
$gd or $self->disarmed_free
l!l&&r!l&&!r
010819
MC/DC50%1/2
$gd or $self->disarmed_free
$gd $self->disarmed_free
Truth table66%2/3
A or B
A= $gdB= $self->disarmed_free
ABresult
1X1
011
000
85 #this could happen after the connection has gone away
86 19 eval { $self->connection->send_free($self->id) };
87 19 ▶ if ($@ && $@ !~ m/^Attempt to invoke _send on a connection that is not valid/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ and not $@ =~ /^Attempt to invoke _send on a connection that is not valid/) 0 19 19
Condition66%2/3
$@ and not $@ =~ /^Attempt to invoke _send on a connection that is not valid/
!ll&&!rl&&r
1810
MC/DC0%0/2
$@ and not $@ =~ /^Attempt to invoke _send on a connection that is not valid/
$@ not $@ =~ /^Attempt to invoke _send on a connection that is not valid/
Truth table66%2/3
A and not(B)
A= $@B= not $@ =~ /^Attempt to invoke _send on a connection that is not valid/
ABresult
0X0
100
111
88 0 die "Could not invoke send_free on connection for handle " . $self->id;
89 }
90 }
91  
92 1;
« Remote/Future.pm ↑ Summary Remote/Logging/Router.pm »