BoardStreams/Client.pm

filter: Statementstmt 98.9% 188 / 190 Branchbran 89.5% 77 / 86 Conditioncond 72.8% 43 / 59 MC/DCmcdc 51.5% 17 / 33 Subroutinesub 100% 37 / 37 Podpod 100% 3 / 3 totaltotal 89.4% 365 / 408 CC 69 SCAR 18.7
CC
69
Cov
92%
__ANON__
16.3
_lost
11.0
__ANON__
8.2
CRAP 6.5
« BoardStreams/Context.pm ↑ Summary BoardStreams/Update.pm »
1 2 ▶use v5.44;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use experimental 'class';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 # A connection to a BoardStreams server, kept alive by reconnecting: the
5 # Perl counterpart of the JavaScript client, ported from it and meant to
6 # behave identically. See the POD at the end of this file.
7 2 class BoardStreams::Client {
8 2 our $VERSION = "v0.0.60";
9  
10 2 ▶ use Mojo::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶ use RxPerl::Mojo qw(rx_behavior_subject rx_interval rx_observable rx_timer);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶ use Scalar::Util qw(blessed refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶ use Time::HiRes qw(time);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶ use BoardStreams ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶ use BoardStreams::Client::Channel;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶ use BoardStreams::Client::Membership;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶ use BoardStreams::Client::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶ use BoardStreams::Client::Handshake;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 2 field $url :param;
22 2 field $min_delay :param = 0.5; # seconds before the first reconnection attempt; doubles per attempt
23 2 field $max_delay :param = 30; # upper limit for that delay, in seconds
24 2 field $idle_delay :param = 30; # seconds the connection is kept with no channel joined; undef for ever
25 2 field $ua :param = undef; # a Mojo::UserAgent to connect with
26 2 field $headers :param = undef; # headers for the handshake request: a hash, or a sub returning one
27 2 field $on_handshake :param = undef; # sub that is shown the answer to each handshake and judges it
28  
29 2 field $status_subject = rx_behavior_subject->new('connecting');
30 2 field %channels; # memberships by channel name
31 2 field $socket; # the current connection attempt: { tx => ... } once established
32 2 field $open = 0; # true once the server has greeted with the same protocol version
33 2 field $attempt = 0;
34 2 field $timer; # subscription of the pending reconnection
35 2 field $watchdog; # subscription of the periodic silence check
36 2 field $silence_limit = 0;
37 2 field $last_seen = 0;
38 2 field $fatal;
39 2 field $idle_timer; # subscription of the wait before going idle
40 2 field $idle = 0; # true while the connection is closed for lack of channels
41  
42 27 ▶ ADJUST {
Subroutine __ANON__: called CC=2 SCAR=7.0
43 # The server's heartbeats and this client's own check decide when a
44 # connection is dead, whatever the heartbeat interval is.
45 27 ▶ $ua //= Mojo::UserAgent->new->inactivity_timeout(0);
Condition66%2/3
$ua //= "Mojo::UserAgent"->new->inactivity_timeout(0)
l!l&&r!l&&!r
1260
MC/DC0%0/2
$ua //= "Mojo::UserAgent"->new->inactivity_timeout(0)
$ua "Mojo::UserAgent"->new->inactivity_timeout(0)
Truth table66%2/3
A //= B
A= $uaB= "Mojo::UserAgent"->new->inactivity_timeout(0)
ABresult
1X1
011
000
46 27 $self->_connect;
47 27 $self->_rest;
48 }
49  
50 # The state of the connection: 'connecting', 'connected',
51 # 'disconnected', 'idle' or 'closed'. Replays the current value.
52 12 ▶ method status_o {
Subroutine status_o: called CC=1 SCAR=0.0
Pod documented
53 12 ▶ return rx_observable->new(sub ($subscriber) {
Subroutine __ANON__: called CC=1 SCAR=0.0
54 12 $status_subject->subscribe($subscriber);
55 12 return;
56 12 });
57 2 }
58  
59 # Joins a channel. Every call returns a channel object of its own, and
60 # the ones for the same name share one membership on the server, which
61 # lasts until each of them has left.
62 38 ▶ method join ($name) {
Subroutine join: called CC=6 SCAR=17.9
Pod documented
63 38 ▶ $idle_timer->unsubscribe if $idle_timer;
Branch: 1 branch
BranchTrueFalseTotal
if $idle_timer 25 13 38
64 38 undef $idle_timer;
65 38 ▶ return $channels{$name}->open if $channels{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $channels{$name} 4 34 38
66 my $membership = $channels{$name} = BoardStreams::Client::Membership->new(
67 name => $name,
68 link => {
69 66 ▶ send => sub ($message) { $self->_send($message) },
Subroutine __ANON__: called CC=1 SCAR=0.0
70 33 ▶ forget => sub { delete $channels{$name}; $self->_rest },
Subroutine __ANON__: called CC=1 SCAR=0.0
71 1 ▶ reconnect => sub { $self->_lost($socket) },
Subroutine __ANON__: called CC=1 SCAR=0.0
72 },
73 34 );
74 34 my $channel = $membership->open;
75 34 ▶ if ($fatal) { $membership->receive({ type => 'rejected', reason => $fatal->reason, data => $fatal->data }) }
Branch: 3 branches
BranchTrueFalseTotal
if ($fatal) { } 4 30 34
elsif ($idle) { } 1 29 30
elsif ($open) { } 6 23 29
76 1 elsif ($idle) { $self->_wake }
77 6 elsif ($open) { $membership->connected }
78 34 return $channel;
79 2 }
80  
81 # Closes the connection for good and leaves all channels.
82 22 ▶ method close {
Subroutine close: called CC=3 SCAR=11.1
Pod documented
83 22 ▶ return if $status_subject->get_value eq 'closed';
Branch: 1 branch
BranchTrueFalseTotal
if $status_subject->get_value eq "closed" 0 22 22
84 22 $_->leave for values %channels;
85 22 $self->_shutdown;
86 22 return;
87 2 }
88  
89 50 ▶ method _connect {
Subroutine _connect: called CC=4 SCAR=14.0
90 50 my $mine = $socket = {};
91 # Asked for anew at every attempt, so that they can carry a date,
92 # a nonce or a signature.
93 50 ▶ my $sent = eval { ref $headers eq 'CODE' ? $headers->() : $headers };
Branch: 1 branch
BranchTrueFalseTotal
ref $headers eq 'CODE' ? : 3 47 50
94 50 ▶ if (my $error = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 0 50 50
95 0 warn "BoardStreams: the headers callback died, so this connection attempt is abandoned: $error";
96 0 return $self->_lost($mine);
97 }
98 50 ▶ $sent = { %{ $sent // {} } };
Condition100%2/2
$sent // {}
l!l
446
MC/DC100%1/1
$sent // {}
$sent
Truth table100%2/2
A
A= $sent
Aresult
11
00
99 49 ▶ $ua->websocket($url => $sent => sub ($ua, $tx) {
Subroutine __ANON__: called CC=8 SCAR=21.1
100 49 ▶ my $is_current = sub { $socket && refaddr $socket == refaddr $mine };
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
$socket and builtin::refaddr($socket) == builtin::refaddr($mine) 98 0 98
101 # The application judges the answer before anything of this
102 # connection is used.
103 49 ▶ my $verdict = $is_current->() ? $self->_judge($tx, $sent) : 1;
Branch: 1 branch
BranchTrueFalseTotal
&$is_current() ? : 49 0 49
104 49 my $current = $is_current->(); # it may have closed the client meanwhile
105 49 ▶ unless ($tx->is_websocket) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tx->is_websocket) 9 40 49
106 9 ▶ return unless $current;
Branch: 1 branch
BranchTrueFalseTotal
unless $current 0 9 9
107 9 ▶ return $self->_fail($verdict) if ref $verdict;
Branch: 1 branch
BranchTrueFalseTotal
if ref $verdict 1 8 9
108 8 return $self->_lost($mine);
109 }
110 40 ▶ return $tx->finish unless $current; # given up on while it was connecting
Branch: 1 branch
BranchTrueFalseTotal
unless $current 0 40 40
111 40 $mine->{tx} = $tx;
112 40 ▶ return $self->_fail($verdict) if ref $verdict;
Branch: 1 branch
BranchTrueFalseTotal
if ref $verdict 1 39 40
113 39 ▶ return $self->_lost($mine) unless $verdict;
Branch: 1 branch
BranchTrueFalseTotal
unless $verdict 2 37 39
114  
115 # Nothing is sent when the socket opens: the connection counts
116 # as established only once the server's first heartbeat has
117 # shown that it speaks the same protocol version as this client.
118 67 ▶ $tx->on(json => sub ($tx, $message) {
Subroutine __ANON__: called CC=15 SCAR=27.9
119 67 ▶ return unless $socket and refaddr $socket == refaddr $mine and ref $message eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless $socket and builtin::refaddr($socket) == builtin::refaddr($mine) and ref $message eq "HASH" 0 67 67
Condition33%2/6
$socket and builtin::refaddr($socket) == builtin::refaddr($mine) and ref $message eq "HASH"
!ll&&!rl&&r
0067
$socket and builtin::refaddr($socket) == builtin::refaddr($mine)
!ll&&!rl&&r
0067
MC/DC0%0/3
$socket and builtin::refaddr($socket) == builtin::refaddr($mine) and ref $message eq "HASH"
$socket builtin::refaddr($socket) == builtin::refaddr($mine) ref $message eq "HASH"
Truth table25%1/4
A and B and C
A= $socketB= builtin::refaddr($socket) == builtin::refaddr($mine)C= ref $message eq "HASH"
ABCresult
0XX0
10X0
1100
1111
120 67 $attempt = 0;
121 67 $last_seen = time;
122 67 ▶ my $type = $message->{type} // '';
Condition50%1/2
$message->{"type"} // ""
l!l
670
MC/DC0%0/1
$message->{"type"} // ""
$message->{"type"}
Truth table50%1/2
A
A= $message->{"type"}
Aresult
11
00
123 67 ▶ unless ($open) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($open) 27 40 67
124 27 ▶ return unless $type eq 'heartbeat';
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "heartbeat" 0 27 27
125 return $self->_protocol_mismatch($message->{protocol})
126 27 ▶ unless ($message->{protocol} // '') eq BoardStreams::PROTOCOL_VERSION;
Branch: 1 branch
BranchTrueFalseTotal
unless ($message->{"protocol"} // "") eq 2 2 25 27
Condition100%2/2
$message->{"protocol"} // ""
l!l
261
MC/DC100%1/1
$message->{"protocol"} // ""
$message->{"protocol"}
Truth table100%2/2
A
A= $message->{"protocol"}
Aresult
11
00
127 25 $open = 1;
128 25 $status_subject->next('connected');
129 25 $_->connected for values %channels;
130 }
131 65 ▶ return $self->_watch($message->{interval}) if $type eq 'heartbeat';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "heartbeat" 26 39 65
132 # The server is closing this connection on purpose; coming
133 # back uninvited would defeat that.
134 return $self->_fail(BoardStreams::Client::Error->new(
135 39 ▶ reason => $message->{reason}, data => $message->{data})) if $type eq 'disconnect';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "disconnect" 1 38 39
136 my ($channel) = defined $message->{channel} && !ref $message->{channel}
137 32 ? grep { defined } $channels{ $message->{channel} }
138 38 ▶ : grep { $_->owns($message->{id}) } values %channels;
Branch: 1 branch
BranchTrueFalseTotal
defined $message->{'channel'} && !ref($message->{'channel'}) ? : 32 6 38
Condition66%2/3
defined $message->{"channel"} and not ref $message->{"channel"}
!ll&&!rl&&r
6032
MC/DC50%1/2
defined $message->{"channel"} and not ref $message->{"channel"}
defined $message->{"channel"} not ref $message->{"channel"}
Truth table66%2/3
A and not(B)
A= defined $message->{"channel"}B= not ref $message->{"channel"}
ABresult
0X0
100
111
139 38 ▶ $channel->receive($message) if $channel;
Branch: 1 branch
BranchTrueFalseTotal
if $channel 36 2 38
140 37 });
141 37 ▶ $tx->on(finish => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
142 37 $mine->{finished} = 1;
143 37 $self->_lost($mine);
144 37 });
145 50 });
146 2 }
147  
148 # Shows the answer to a handshake to the application. Returns an error
149 # object if the client is to stop for good, false if this connection
150 # is to be dropped and another attempted, and true otherwise.
151 49 ▶ method _judge ($tx, $sent) {
Subroutine _judge: called CC=8 SCAR=20.8
152 49 ▶ return 1 unless $on_handshake and defined $tx->res->code;
Branch: 1 branch
BranchTrueFalseTotal
unless $on_handshake and defined $tx->res->code 39 10 49
Condition66%2/3
$on_handshake and defined $tx->res->code
!ll&&!rl&&r
39010
MC/DC50%1/2
$on_handshake and defined $tx->res->code
$on_handshake defined $tx->res->code
Truth table66%2/3
A and B
A= $on_handshakeB= defined $tx->res->code
ABresult
0X0
100
111
153 10 ▶ my $handshake = BoardStreams::Client::Handshake->new(
Branch: 1 branch
BranchTrueFalseTotal
$tx->is_websocket ? : 6 4 10
154 code => $tx->res->code,
155 accepted => $tx->is_websocket ? 1 : 0,
156 headers => $tx->res->headers,
157 body => $tx->res->body,
158 sent => $sent,
159 );
160 10 my $verdict = eval { $on_handshake->($handshake) };
161 10 ▶ if (my $error = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 1 9 10
162 1 warn "BoardStreams: the on_handshake callback died, so this connection is not used: $error";
163 1 return 0;
164 }
165 9 ▶ return $verdict if blessed $verdict and $verdict->isa('BoardStreams::Client::Error');
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($verdict) and $verdict->isa("BoardStreams::Client::Error") 2 7 9
Condition66%2/3
builtin::blessed($verdict) and $verdict->isa("BoardStreams::Client::Error")
!ll&&!rl&&r
702
MC/DC50%1/2
builtin::blessed($verdict) and $verdict->isa("BoardStreams::Client::Error")
builtin::blessed($verdict) $verdict->isa("BoardStreams::Client::Error")
Truth table66%2/3
A and B
A= builtin::blessed($verdict)B= $verdict->isa("BoardStreams::Client::Error")
ABresult
0X0
100
111
166 7 ▶ return $verdict ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$verdict ? : 6 1 7
167 2 }
168  
169 # The server speaks another version of the protocol; reconnecting would
170 # not help.
171 2 ▶ method _protocol_mismatch ($server_protocol) {
Subroutine _protocol_mismatch: called CC=2 SCAR=6.9
172 2 ▶ warn sprintf "BoardStreams: this client speaks protocol version %s but the server speaks %s; "
Condition100%2/2
$server_protocol // "an unknown (older) one"
l!l
11
MC/DC100%1/1
$server_protocol // "an unknown (older) one"
$server_protocol
Truth table100%2/2
A
A= $server_protocol
Aresult
11
00
173 . "the two must be the same, so no connection is made.\n",
174 BoardStreams::PROTOCOL_VERSION, $server_protocol // 'an unknown (older) one';
175 2 $self->_fail(BoardStreams::Client::Error->new(
176 reason => 'protocol_mismatch',
177 data => { client => BoardStreams::PROTOCOL_VERSION, server => $server_protocol }));
178 2 }
179  
180 # Stops for good, without reconnecting. Every channel, current or
181 # future, is refused with the given error.
182 5 ▶ method _fail ($error) {
Subroutine _fail: called CC=2 SCAR=6.9
183 5 $fatal = $error;
184 5 $_->receive({ type => 'rejected', reason => $error->reason, data => $error->data }) for values %channels;
185 5 $self->_shutdown;
186 2 }
187  
188 27 ▶ method _shutdown {
Subroutine _shutdown: called CC=3 SCAR=11.0
189 27 $status_subject->next('closed');
190 27 ▶ $timer->unsubscribe if $timer;
Branch: 1 branch
BranchTrueFalseTotal
if $timer 10 17 27
191 27 undef $timer;
192 27 ▶ $idle_timer->unsubscribe if $idle_timer;
Branch: 1 branch
BranchTrueFalseTotal
if $idle_timer 24 3 27
193 27 undef $idle_timer;
194 27 $idle = 0;
195 27 $self->_lost($socket);
196 27 $status_subject->complete;
197 2 }
198  
199 # The server says how often it sends heartbeats; from then on, silence
200 # for two and a half intervals means the connection is dead even if
201 # the socket has not noticed.
202 26 ▶ method _watch ($interval) {
Subroutine _watch: called CC=4 SCAR=14.0
203 26 my $limit = $interval * 2.5;
204 26 ▶ return if $watchdog and $limit == $silence_limit;
Branch: 1 branch
BranchTrueFalseTotal
if $watchdog and $limit == $silence_limit 1 25 26
Condition66%2/3
$watchdog and $limit == $silence_limit
!ll&&!rl&&r
2501
MC/DC50%1/2
$watchdog and $limit == $silence_limit
$watchdog $limit == $silence_limit
Truth table66%2/3
A and B
A= $watchdogB= $limit == $silence_limit
ABresult
0X0
100
111
205 25 $silence_limit = $limit;
206 25 ▶ $watchdog->unsubscribe if $watchdog;
Branch: 1 branch
BranchTrueFalseTotal
if $watchdog 0 25 25
207 15 ▶ $watchdog = rx_interval($interval / 2)->subscribe(sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
208 15 ▶ $self->_lost($socket) if $watchdog and time - $last_seen > $silence_limit;
Branch: 1 branch
BranchTrueFalseTotal
if $watchdog and &BoardStreams::Client::time() - $last_seen > $silence_limit 1 14 15
Condition66%2/3
$watchdog and &BoardStreams::Client::time() - $last_seen > $silence_limit
!ll&&!rl&&r
0141
MC/DC50%1/2
$watchdog and &BoardStreams::Client::time() - $last_seen > $silence_limit
$watchdog &BoardStreams::Client::time() - $last_seen > $silence_limit
Truth table66%2/3
A and B
A= $watchdogB= &BoardStreams::Client::time() - $last_seen > $silence_limit
ABresult
0X0
100
111
209 25 });
210 2 }
211  
212 # Gives up on a connection, whether it closed or just went silent, and
213 # schedules a new one. A silent connection is abandoned without
214 # waiting for it to close, which may take very long.
215 79 ▶ method _lost ($lost) {
Subroutine _lost: called CC=11 SCAR=24.0
216 79 ▶ return unless $lost and $socket and refaddr $socket == refaddr $lost;
Branch: 1 branch
BranchTrueFalseTotal
unless $lost and $socket and builtin::refaddr($socket) == builtin::refaddr($lost) 29 50 79
Condition83%5/6
$lost and $socket and builtin::refaddr($socket) == builtin::refaddr($lost)
!ll&&!rl&&r
29050
$lost and $socket
!ll&&!rl&&r
42550
MC/DC66%2/3
$lost and $socket and builtin::refaddr($socket) == builtin::refaddr($lost)
$lost $socket builtin::refaddr($socket) == builtin::refaddr($lost)
Truth table75%3/4
A and B and C
A= $lostB= $socketC= builtin::refaddr($socket) == builtin::refaddr($lost)
ABCresult
0XX0
10X0
1100
1111
217 50 $open = 0;
218 50 undef $socket;
219 50 ▶ $watchdog->unsubscribe if $watchdog;
Branch: 1 branch
BranchTrueFalseTotal
if $watchdog 25 25 50
220 50 undef $watchdog;
221 50 ▶ $lost->{tx}->finish if $lost->{tx} and !$lost->{finished};
Branch: 1 branch
BranchTrueFalseTotal
if $lost->{"tx"} and not $lost->{"finished"} 28 22 50
Condition100%3/3
$lost->{"tx"} and not $lost->{"finished"}
!ll&&!rl&&r
101228
MC/DC100%2/2
$lost->{"tx"} and not $lost->{"finished"}
$lost->{"tx"} not $lost->{"finished"}
Truth table100%3/3
A and not(B)
A= $lost->{"tx"}B= not $lost->{"finished"}
ABresult
0X0
100
111
222 50 $_->disconnected for values %channels;
223 50 ▶ return if $idle or $status_subject->get_value eq 'closed';
Branch: 1 branch
BranchTrueFalseTotal
if $idle or $status_subject->get_value eq "closed" 26 24 50
Condition100%3/3
$idle or $status_subject->get_value eq "closed"
l!l&&r!l&&!r
22424
MC/DC100%2/2
$idle or $status_subject->get_value eq "closed"
$idle $status_subject->get_value eq "closed"
Truth table100%3/3
A or B
A= $idleB= $status_subject->get_value eq "closed"
ABresult
1X1
011
000
224 24 $status_subject->next('disconnected');
225 24 my $nominal = $min_delay * 2**$attempt++;
226 24 ▶ $nominal = $max_delay if $nominal > $max_delay;
Branch: 1 branch
BranchTrueFalseTotal
if $nominal > $max_delay 3 21 24
227 22 ▶ $timer = rx_timer($nominal * $self->_jitter)->subscribe(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
228 22 $status_subject->next('connecting');
229 22 $self->_connect;
230 24 });
231 2 }
232  
233 # Between half and all of the nominal delay, at random, so that the
234 # clients a server lets go of at once do not all come back at once.
235 24 ▶ method _jitter { 0.5 + rand() / 2 }
Subroutine _jitter: called CC=1 SCAR=0.0
236  
237 # With no channel joined there is nothing to receive, so after a while
238 # the connection is closed, until the next join opens one again.
239 60 ▶ method _rest {
Subroutine _rest: called CC=6 SCAR=18.0
240 60 ▶ return if !defined $idle_delay or %channels or $idle or $idle_timer;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $idle_delay or %channels or $idle or $idle_timer 4 56 60
Condition77%7/9
not defined $idle_delay or %channels or $idle or $idle_timer
l!l&&r!l&&!r
4056
not defined $idle_delay or %channels or $idle
l!l&&r!l&&!r
4056
not defined $idle_delay or %channels
l!l&&r!l&&!r
1356
MC/DC50%2/4
not defined $idle_delay or %channels or $idle or $idle_timer
not defined $idle_delay %channels $idle $idle_timer
Truth table60%3/5
not(A) or B or C or D
A= not defined $idle_delayB= %channelsC= $idleD= $idle_timer
ABCDresult
1XXX1
01XX1
001X1
00011
00000
241 56 ▶ return if $status_subject->get_value eq 'closed';
Branch: 1 branch
BranchTrueFalseTotal
if $status_subject->get_value eq "closed" 4 52 56
242 3 ▶ $idle_timer = rx_timer($idle_delay)->subscribe(sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
243 3 undef $idle_timer;
244 3 $idle = 1;
245 3 ▶ $timer->unsubscribe if $timer;
Branch: 1 branch
BranchTrueFalseTotal
if $timer 1 2 3
246 3 undef $timer;
247 3 $self->_lost($socket);
248 3 $status_subject->next('idle');
249 52 });
250 2 }
251  
252 1 ▶ method _wake {
Subroutine _wake: called CC=1 SCAR=0.0
253 1 $idle = 0;
254 1 $attempt = 0;
255 1 $status_subject->next('connecting');
256 1 $self->_connect;
257 2 }
258  
259 66 ▶ method _send ($message) {
Subroutine _send: called CC=4 SCAR=14.3
260 66 ▶ $socket->{tx}->send({ json => $message }) if $open and $socket and $socket->{tx};
Branch: 1 branch
BranchTrueFalseTotal
if $open and $socket and $socket->{"tx"} 65 1 66
Condition66%4/6
$open and $socket and $socket->{"tx"}
!ll&&!rl&&r
1065
$open and $socket
!ll&&!rl&&r
1065
MC/DC33%1/3
$open and $socket and $socket->{"tx"}
$open $socket $socket->{"tx"}
Truth table50%2/4
A and B and C
A= $openB= $socketC= $socket->{"tx"}
ABCresult
0XX0
10X0
1100
1111
261 2 }
262 }
263  
264 2 1;
265 __END__
« BoardStreams/Context.pm ↑ Summary BoardStreams/Update.pm »