Client.pm

filter: Statementstmt 19.8% 52 / 262 Branchbran 3.7% 6 / 162 Conditioncond 12.5% 4 / 32 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 35.7% 15 / 42 Podpod 100% 27 / 27 totaltotal 19.1% 104 / 543 CC 97 SCAR 39.2
CC
97
Cov
14%
_interact
199.2
put
110.0
watch_only
72.0
CRAP 50.3
↑ Summary Stats.pm »
1 package Beanstalk::Client;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use base qw(Class::Accessor::Fast);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use YAML::Syck;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 ▶use Beanstalk::Job;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Beanstalk::Stats;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 our $VERSION = "1.07";
16  
17 # use namespace::clean;
18  
19 3 our $CRLF = "\015\012";
20 3 ▶our $MSG_NOSIGNAL = eval { Socket::MSG_NOSIGNAL() } || 0;
Condition50%1/2
eval { do { 16384 } } || 0
l!l
30
MC/DC0%0/1
eval { do { 16384 } } || 0
eval { do { 16384 } }
Truth table50%1/2
A
A= eval { do { 16384 } }
Aresult
11
00
21  
22 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
23 3 __PACKAGE__->mk_accessors(
24 qw(
25 connect_timeout
26 debug
27 decoder
28 default_tube
29 delay
30 encoder
31 error
32 priority
33 server
34 socket
35 ttr
36 _watching
37 _using
38 )
39 );
40 }
41  
42 # no namespace::clean;
43  
44 1 ▶sub _interact {
Subroutine _interact: called CC=15 SCAR=52.9
45 1 my ($self, $cmd, $data) = @_;
46 1 ▶ my $sock = $self->socket || $self->connect
Branch: 1 branch
BranchTrueFalseTotal
my $sock = $self->socket || $self->connect or return 0 1 1
Condition33%1/3
$self->socket || $self->connect
l!l&&r!l&&!r
001
MC/DC0%0/2
$self->socket || $self->connect
$self->socket $self->connect
Truth table33%1/3
A || B
A= $self->socketB= $self->connect
ABresult
1X1
011
000
47 or return;
48  
49 0 ▶ local $SIG{PIPE} = "IGNORE" unless $MSG_NOSIGNAL;
Branch: 1 branch
BranchTrueFalseTotal
unless $Beanstalk::Client::MSG_NOSIGNAL 0 0 0
50  
51 0 my $debug = $self->debug;
52 0 ▶ warn $cmd ."\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
53  
54 0 $cmd .= $CRLF;
55 0 ▶ $cmd .= $data . $CRLF if defined $data;
Branch: 1 branch
BranchTrueFalseTotal
if defined $data 0 0 0
56  
57 0 my $offset = 0;
58 WRITE: {
59 0 my $sent = send($sock, substr($cmd, $offset), $MSG_NOSIGNAL);
60 0 ▶ if ($sent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sent) { } 0 0 0
61 0 $offset += $sent;
62 0 ▶ redo WRITE if $offset < length($cmd);
Branch: 1 branch
BranchTrueFalseTotal
if $offset < length $cmd 0 0 0
63 }
64 else {
65 0 $self->error("$!");
66 0 ▶ redo WRITE if $!{EINTR} and fileno($sock);
Branch: 1 branch
BranchTrueFalseTotal
if $!{"EINTR"} and fileno $sock 0 0 0
Condition0%0/3
$!{"EINTR"} and fileno $sock
!ll&&!rl&&r
000
MC/DC0%0/2
$!{"EINTR"} and fileno $sock
$!{"EINTR"} fileno $sock
Truth table0%0/3
A and B
A= $!{"EINTR"}B= fileno $sock
ABresult
0X0
100
111
67 0 return $self->disconnect;
68 }
69 }
70  
71 0 my $buffer;
72 0 $offset = 0;
73 READ: {
74 0 my $read = sysread($sock, $buffer, 1024, $offset);
75 0 ▶ if ($read) {
Branch: 1 branch
BranchTrueFalseTotal
if ($read) { } 0 0 0
76 0 ▶ if ($buffer =~ /^([^\015\012]+)\015\012/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buffer =~ /^([^\015\012]+)\015\012/) 0 0 0
77 0 $self->{_recv_buffer} = substr($buffer, 2 + length($1));
78 0 ▶ warn $1,"\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
79 0 return split(' ', $1);
80 }
81 0 $offset += length $buffer;
82 0 redo READ;
83 }
84 else {
85 0 $self->error("$!");
86 0 ▶ redo READ if $!{EINTR} and fileno($sock);
Branch: 1 branch
BranchTrueFalseTotal
if $!{"EINTR"} and fileno $sock 0 0 0
Condition0%0/3
$!{"EINTR"} and fileno $sock
!ll&&!rl&&r
000
MC/DC0%0/2
$!{"EINTR"} and fileno $sock
$!{"EINTR"} fileno $sock
Truth table0%0/3
A and B
A= $!{"EINTR"}B= fileno $sock
ABresult
0X0
100
111
87 }
88 }
89 0 $self->disconnect;
90 0 return;
91 }
92  
93  
94 0 ▶sub _recv_data {
Subroutine _recv_data: not called CC=6 SCAR=37.4
95 0 my ($self, $bytes) = @_;
96 0 my $sock = $self->socket;
97  
98 0 my $need = $bytes + 2; # count CRLF
99 0 my $offset = length($self->{_recv_buffer});
100 0 my $more = $need - $offset;
101  
102 0 ▶READ: while ($more > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($more > 0) 0 0 0
103 0 my $read = sysread($sock, $self->{_recv_buffer}, $more, $offset);
104 0 ▶ if ($read) {
Branch: 1 branch
BranchTrueFalseTotal
if ($read) { } 0 0 0
105 0 $offset += $read;
106 0 $more -= $read;
107 0 ▶ last if $more == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $more == 0 0 0 0
108 0 redo READ;
109 }
110 else {
111 0 ▶ redo READ if $!{EINTR};
Branch: 1 branch
BranchTrueFalseTotal
if $!{"EINTR"} 0 0 0
112 0 $self->error("$!");
113 0 return $self->disconnect;
114 }
115 }
116 0 ▶ warn substr($self->{_recv_buffer}, 0, $bytes),"\n" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
117 0 return substr($self->{_recv_buffer}, 0, $bytes);
118 }
119  
120  
121 1 ▶sub _interact_yaml_resp {
Subroutine _interact_yaml_resp: called CC=4 SCAR=24.2
122 1 my ($self, $cmd) = @_;
123  
124 1 ▶ my @resp = _interact($self, $cmd)
Branch: 1 branch
BranchTrueFalseTotal
my(@resp) = _interact($self, $cmd) or return 0 1 1
125 or return;
126  
127 0 ▶ if ($resp[0] eq 'OK') {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp[0] eq "OK") 0 0 0
128 0 ▶ my $data = _recv_data($self, $resp[1])
Branch: 1 branch
BranchTrueFalseTotal
my $data = _recv_data($self, $resp[1]) or return undef 0 0 0
129 or return undef;
130 0 return YAML::Syck::Load($data);
131 }
132  
133 0 $self->error(join ' ', @resp);
134 0 return undef;
135 }
136  
137  
138 0 ▶sub _interact_stats {
Subroutine _interact_stats: not called CC=2 SCAR=17.9
139 0 ▶ my $ret = _interact_yaml_resp(@_)
Branch: 1 branch
BranchTrueFalseTotal
my $ret = _interact_yaml_resp(@_) or return undef 0 0 0
140 or return undef;
141 0 return Beanstalk::Stats->new($ret);
142 }
143  
144  
145 0 ▶sub _peek {
Subroutine _peek: not called CC=4 SCAR=30.0
146 0 my $self = shift;
147 0 my $cmd = shift;
148  
149 0 ▶ my @resp = _interact($self, $cmd)
Branch: 1 branch
BranchTrueFalseTotal
my(@resp) = _interact($self, $cmd) or return undef 0 0 0
150 or return undef;
151  
152 0 ▶ if ($resp[0] eq 'FOUND') {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp[0] eq "FOUND") 0 0 0
153 0 my $data = _recv_data($self, $resp[2]);
154 0 ▶ return undef unless defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 0 0 0
155 0 return Beanstalk::Job->new(
156 { id => $resp[1],
157 client => $self,
158 data => $data,
159 }
160 );
161 }
162  
163 0 $self->error(join ' ', @resp);
164 0 return undef;
165 }
166  
167 0 ▶sub __watching {
Subroutine __watching: not called CC=2 SCAR=17.9
168 0 my $self = shift;
169 0 my $watching = $self->_watching;
170 0 ▶ return $watching if $watching;
Branch: 1 branch
BranchTrueFalseTotal
if $watching 0 0 0
171 0 $self->list_tubes_watched;
172 0 $self->_watching;
173 }
174  
175 # use namespace::clean;
176  
177 4 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
178 4 my $proto = shift;
179 4 ▶ my $fields = shift || {};
Condition50%1/2
shift() || {}
l!l
04
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
180 4 my $self = $proto->SUPER::new(
181 { delay => 0,
182 ttr => 120,
183 priority => 10_000,
184 encoder => \&YAML::Syck::Dump,
185 decoder => \&YAML::Syck::Load,
186 %$fields,
187 }
188 );
189 4 $self->{_recv_buffer} = '';
190 4 $self;
191 }
192  
193  
194 3 ▶sub connect {
Subroutine connect: called CC=11 SCAR=40.2
Pod documented
195 3 my $self = shift;
196 3 ▶ my $server = $self->server || "127.0.0.1";
Condition50%1/2
$self->server || '127.0.0.1'
l!l
03
MC/DC0%0/1
$self->server || '127.0.0.1'
$self->server
Truth table50%1/2
A
A= $self->server
Aresult
11
00
197  
198 3 ▶ $server .= ":11300" unless $server =~ /:/;
Branch: 1 branch
BranchTrueFalseTotal
unless $server =~ /:/ 3 0 3
199  
200 3 my $timeout = $self->connect_timeout;
201  
202 3 my $sock = IO::Socket::INET->new(
203 PeerAddr => $server,
204 Timeout => $timeout,
205 );
206  
207 3 ▶ unless ($sock) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sock) 3 0 3
208 3 $self->error("connect: $@");
209 3 return $self->disconnect;
210 }
211  
212 0 $self->socket($sock);
213  
214 0 my $was_watching = $self->_watching;
215 0 my $was_using = $self->_using;
216  
217 0 $self->list_tubes_watched;
218 0 ▶ if ($was_watching) {
Branch: 2 branches
BranchTrueFalseTotal
if ($was_watching) { } 0 0 0
elsif (my $default_tube = $self->default_tube) { } 0 0 0
219 0 ▶ $self->watch_only(keys %$was_watching)
Branch: 1 branch
BranchTrueFalseTotal
$self->watch_only(keys %$was_watching) or return $self->disconnect 0 0 0
220 or return $self->disconnect;
221 }
222 elsif (my $default_tube = $self->default_tube) {
223 0 ▶ $self->use($default_tube) && $self->watch_only($default_tube)
Branch: 1 branch
BranchTrueFalseTotal
$self->use($default_tube) and $self->watch_only($default_tube) or return $self->disconnect 0 0 0
Condition0%0/3
$self->use($default_tube) and $self->watch_only($default_tube)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->use($default_tube) and $self->watch_only($default_tube)
$self->use($default_tube) $self->watch_only($default_tube)
Truth table0%0/3
A and B
A= $self->use($default_tube)B= $self->watch_only($default_tube)
ABresult
0X0
100
111
224 or return $self->disconnect;
225 }
226  
227 0 ▶ if (defined $was_using) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $was_using) 0 0 0
228 0 ▶ $self->use($was_using)
Branch: 1 branch
BranchTrueFalseTotal
$self->use($was_using) or return $self->disconnect 0 0 0
229 or return $self->disconnect;
230 }
231  
232 0 $sock;
233 }
234  
235  
236 3 ▶sub disconnect {
Subroutine disconnect: called CC=2 SCAR=7.6
Pod documented
237 3 my $self = shift;
238 3 ▶ if (my $sock = $self->socket) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sock = $self->socket) 0 3 3
239 0 close($sock);
240 }
241 3 $self->socket(undef);
242 }
243  
244 0 ▶sub quit {
Subroutine quit: not called CC=1 SCAR=6.9
Pod documented
245 0 shift->disconnect;
246 0 return 1;
247 }
248  
249  
250 0 ▶sub put {
Subroutine put: not called CC=10 SCAR=47.0
Pod documented
251 0 my $self = shift;
252 0 ▶ my $opt = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
253  
254 0 ▶ my $pri = exists $opt->{priority} ? $opt->{priority} : $self->priority;
Branch: 1 branch
BranchTrueFalseTotal
exists $opt->{'priority'} ? : 0 0 0
255 0 ▶ my $ttr = exists $opt->{ttr} ? $opt->{ttr} : $self->ttr;
Branch: 1 branch
BranchTrueFalseTotal
exists $opt->{'ttr'} ? : 0 0 0
256 0 ▶ my $delay = exists $opt->{delay} ? $opt->{delay} : $self->delay;
Branch: 1 branch
BranchTrueFalseTotal
exists $opt->{'delay'} ? : 0 0 0
257 0 ▶ my $data = exists $opt->{data} ? $opt->{data} : $self->encoder->(@_);
Branch: 1 branch
BranchTrueFalseTotal
exists $opt->{'data'} ? : 0 0 0
258  
259 0 ▶ utf8::encode($data) if utf8::is_utf8($data); # need bytes
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($data) 0 0 0
260  
261 0 my $bytes = length($data);
262  
263 0 ▶ my @resp = _interact($self, "put $pri $delay $ttr $bytes", $data)
Branch: 1 branch
BranchTrueFalseTotal
my(@resp) = _interact($self, "put $pri $delay $ttr $bytes", $data) or return undef 0 0 0
264 or return undef;
265  
266 0 ▶ if ($resp[0] =~ /( INSERTED | BURIED )/x) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp[0] =~ /( INSERTED | BURIED )/x) 0 0 0
267 0 ▶ return Beanstalk::Job->new(
Branch: 1 branch
BranchTrueFalseTotal
$1 eq 'BURIED' ? : 0 0 0
268 { id => $resp[1],
269 client => $self,
270 buried => $1 eq 'BURIED' ? 1 : 0,
271 data => $data,
272 }
273 );
274 }
275  
276 0 $self->error(join ' ', @resp);
277  
278 0 return undef;
279 }
280  
281  
282 0 ▶sub stats {
Subroutine stats: not called CC=1 SCAR=6.9
Pod documented
283 0 my $self = shift;
284 0 _interact_stats($self, "stats");
285 }
286  
287  
288 0 ▶sub stats_tube {
Subroutine stats_tube: not called CC=2 SCAR=17.9
Pod documented
289 0 my $self = shift;
290 0 ▶ my $tube = @_ ? shift: 'default';
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
291 0 _interact_stats($self, "stats-tube $tube");
292 }
293  
294  
295 0 ▶sub stats_job {
Subroutine stats_job: not called CC=2 SCAR=17.9
Pod documented
296 0 my $self = shift;
297 0 ▶ my $id = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
298 0 _interact_stats($self, "stats-job $id");
299 }
300  
301  
302 0 ▶sub kick {
Subroutine kick: not called CC=4 SCAR=30.0
Pod documented
303 0 my $self = shift;
304 0 ▶ my $bound = shift || 1;
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
305  
306 0 ▶ my @resp = _interact($self, "kick $bound")
Branch: 1 branch
BranchTrueFalseTotal
my(@resp) = _interact($self, "kick $bound") or return undef 0 0 0
307 or return undef;
308  
309 0 ▶ return $resp[1] if $resp[0] eq 'KICKED';
Branch: 1 branch
BranchTrueFalseTotal
if $resp[0] eq "KICKED" 0 0 0
310  
311 0 $self->error(join ' ', @resp);
312 0 return undef;
313 }
314  
315  
316 0 ▶sub kick_job {
Subroutine kick_job: not called CC=3 SCAR=24.8
Pod documented
317 0 my $self = shift;
318 0 my $job = shift;
319  
320 0 ▶ my @resp = _interact($self, "kick-job $job")
Branch: 1 branch
BranchTrueFalseTotal
my(@resp) = _interact($self, "kick-job $job") or return undef 0 0 0
321 or return undef;
322  
323 0 ▶ return 1 if $resp[0] eq 'KICKED';
Branch: 1 branch
BranchTrueFalseTotal
if $resp[0] eq "KICKED" 0 0 0
324  
325 0 $self->error(join ' ', @resp);
326 0 return undef;
327 }
328  
329  
330 0 ▶sub use {
Subroutine use: not called CC=3 SCAR=24.8
Pod documented
331 0 my $self = shift;
332 0 my $tube = shift;
333  
334 0 ▶ my @resp = _interact($self, "use $tube")
Branch: 1 branch
BranchTrueFalseTotal
my(@resp) = _interact($self, "use $tube") or return undef 0 0 0
335 or return undef;
336  
337 0 ▶ return $self->_using($resp[1]) if $resp[0] eq 'USING';
Branch: 1 branch
BranchTrueFalseTotal
if $resp[0] eq "USING" 0 0 0
338  
339 0 $self->error(join ' ', @resp);
340 0 return undef;
341 }
342  
343  
344 0 ▶sub reserve {
Subroutine reserve: not called CC=5 SCAR=34.0
Pod documented
345 0 my $self = shift;
346 0 my $timeout = shift;
347  
348 0 ▶ my $cmd = defined($timeout) ? "reserve-with-timeout $timeout" : "reserve";
Branch: 1 branch
BranchTrueFalseTotal
defined $timeout ? : 0 0 0
349 0 ▶ my @resp = _interact($self, $cmd)
Branch: 1 branch
BranchTrueFalseTotal
my(@resp) = _interact($self, $cmd) or return undef 0 0 0
350 or return undef;
351  
352 0 ▶ if ($resp[0] eq 'RESERVED') {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp[0] eq "RESERVED") 0 0 0
353 0 my $data = _recv_data($self, $resp[2]);
354 0 ▶ return undef unless defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 0 0 0
355  
356 0 return Beanstalk::Job->new(
357 { id => $resp[1],
358 client => $self,
359 reserved => 1,
360 data => $data,
361 }
362 );
363 }
364  
365 0 $self->error(join ' ', @resp);
366 0 return undef;
367 }
368  
369  
370 0 ▶sub delete {
Subroutine delete: not called CC=3 SCAR=24.8
Pod documented
371 0 my $self = shift;
372 0 my $id = shift;
373 0 ▶ my @resp = _interact($self, "delete $id")
Branch: 1 branch
BranchTrueFalseTotal
my(@resp) = _interact($self, "delete $id") or return undef 0 0 0
374 or return undef;
375 0 ▶ return 1 if $resp[0] eq 'DELETED';
Branch: 1 branch
BranchTrueFalseTotal
if $resp[0] eq "DELETED" 0 0 0
376  
377 0 $self->error(join ' ', @resp);
378 0 return undef;
379 }
380  
381 0 ▶sub touch {
Subroutine touch: not called CC=3 SCAR=24.8
Pod documented
382 0 my $self = shift;
383 0 my $id = shift;
384 0 ▶ my @resp = _interact($self, "touch $id")
Branch: 1 branch
BranchTrueFalseTotal
my(@resp) = _interact($self, "touch $id") or return undef 0 0 0
385 or return undef;
386 0 ▶ return 1 if $resp[0] eq 'TOUCHED';
Branch: 1 branch
BranchTrueFalseTotal
if $resp[0] eq "TOUCHED" 0 0 0
387  
388 0 $self->error(join ' ', @resp);
389 0 return undef;
390 }
391  
392  
393 0 ▶sub release {
Subroutine release: not called CC=6 SCAR=37.4
Pod documented
394 0 my $self = shift;
395 0 my $id = shift;
396 0 ▶ my $opt = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
397  
398 0 ▶ my $pri = exists $opt->{priority} ? $opt->{priority} : $self->priority;
Branch: 1 branch
BranchTrueFalseTotal
exists $opt->{'priority'} ? : 0 0 0
399 0 ▶ my $delay = exists $opt->{delay} ? $opt->{delay} : $self->delay;
Branch: 1 branch
BranchTrueFalseTotal
exists $opt->{'delay'} ? : 0 0 0
400  
401 0 ▶ my @resp = _interact($self, "release $id $pri $delay")
Branch: 1 branch
BranchTrueFalseTotal
my(@resp) = _interact($self, "release $id $pri $delay") or return undef 0 0 0
402 or return undef;
403 0 ▶ return 1 if $resp[0] eq 'RELEASED';
Branch: 1 branch
BranchTrueFalseTotal
if $resp[0] eq "RELEASED" 0 0 0
404  
405 0 $self->error(join ' ', @resp);
406 0 return undef;
407 }
408  
409  
410 0 ▶sub bury {
Subroutine bury: not called CC=5 SCAR=34.0
Pod documented
411 0 my $self = shift;
412 0 my $id = shift;
413 0 ▶ my $opt = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
414  
415 0 ▶ my $pri = exists $opt->{priority} ? $opt->{priority} : $self->priority;
Branch: 1 branch
BranchTrueFalseTotal
exists $opt->{'priority'} ? : 0 0 0
416  
417 0 ▶ my @resp = _interact($self, "bury $id $pri")
Branch: 1 branch
BranchTrueFalseTotal
my(@resp) = _interact($self, "bury $id $pri") or return undef 0 0 0
418 or return undef;
419 0 ▶ return 1 if $resp[0] eq 'BURIED';
Branch: 1 branch
BranchTrueFalseTotal
if $resp[0] eq "BURIED" 0 0 0
420  
421 0 $self->error(join ' ', @resp);
422 0 return undef;
423 }
424  
425  
426 0 ▶sub watch {
Subroutine watch: not called CC=5 SCAR=34.0
Pod documented
427 0 my $self = shift;
428 0 my $tube = shift;
429  
430 0 ▶ my $watching = $self->__watching or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $watching = $self->__watching or return undef 0 0 0
431 0 ▶ return scalar keys %$watching if $watching->{$tube};
Branch: 1 branch
BranchTrueFalseTotal
if $watching->{$tube} 0 0 0
432  
433 0 ▶ my @resp = _interact($self, "watch $tube")
Branch: 1 branch
BranchTrueFalseTotal
my(@resp) = _interact($self, "watch $tube") or return undef 0 0 0
434 or return undef;
435  
436 0 ▶ if ($resp[0] eq 'WATCHING') {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp[0] eq "WATCHING") 0 0 0
437 0 $watching->{$tube}++;
438 0 return $resp[1];
439 }
440  
441 0 $self->error(join ' ', @resp);
442 0 return undef;
443 }
444  
445  
446 0 ▶sub ignore {
Subroutine ignore: not called CC=5 SCAR=34.0
Pod documented
447 0 my $self = shift;
448 0 my $tube = shift;
449  
450 0 ▶ my $watching = $self->__watching or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $watching = $self->__watching or return undef 0 0 0
451 0 ▶ return scalar keys %$watching unless $watching->{$tube};
Branch: 1 branch
BranchTrueFalseTotal
unless $watching->{$tube} 0 0 0
452  
453 0 ▶ my @resp = _interact($self, "ignore $tube")
Branch: 1 branch
BranchTrueFalseTotal
my(@resp) = _interact($self, "ignore $tube") or return undef 0 0 0
454 or return undef;
455  
456 0 ▶ if ($resp[0] eq 'WATCHING') {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp[0] eq "WATCHING") 0 0 0
457 0 delete $watching->{$tube};
458 0 return $resp[1];
459 }
460  
461 0 $self->error(join ' ', @resp);
462 0 return undef;
463 }
464  
465  
466 0 ▶sub watch_only {
Subroutine watch_only: not called CC=8 SCAR=42.8
Pod documented
467 0 my $self = shift;
468 0 ▶ my $watching = $self->__watching or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $watching = $self->__watching or return undef 0 0 0
469 0 my %watched = %$watching;
470 0 my $ret;
471 0 foreach my $watch (@_) {
472 0 ▶ next if delete $watched{$watch};
Branch: 1 branch
BranchTrueFalseTotal
if delete $watched{$watch} 0 0 0
473 0 ▶ $ret = $self->watch($watch) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$ret = $self->watch($watch) or return undef 0 0 0
474 }
475 0 foreach my $ignore (keys %watched) {
476 0 ▶ $ret = $self->ignore($ignore) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$ret = $self->ignore($ignore) or return undef 0 0 0
477 }
478 0 ▶ return $ret || scalar keys %$watching;
Condition0%0/2
$ret || scalar keys %$watching
l!l
00
MC/DC0%0/1
$ret || scalar keys %$watching
$ret
Truth table0%0/2
A
A= $ret
Aresult
11
00
479 }
480  
481  
482 0 ▶sub peek { _peek($_[0], "peek $_[1]") }
Subroutine peek: not called CC=1 SCAR=6.9
Pod documented
483 0 ▶sub peek_ready { _peek(shift, "peek-ready") }
Subroutine peek_ready: not called CC=1 SCAR=6.9
Pod documented
484 0 ▶sub peek_delayed { _peek(shift, "peek-delayed") }
Subroutine peek_delayed: not called CC=1 SCAR=6.9
Pod documented
485 0 ▶sub peek_buried { _peek(shift, "peek-buried") }
Subroutine peek_buried: not called CC=1 SCAR=6.9
Pod documented
486  
487  
488 0 ▶sub list_tubes {
Subroutine list_tubes: not called CC=2 SCAR=17.9
Pod documented
489 0 my $self = shift;
490 0 ▶ my $ret = _interact_yaml_resp($self, "list-tubes")
Branch: 1 branch
BranchTrueFalseTotal
my $ret = _interact_yaml_resp($self, "list-tubes") or return undef 0 0 0
491 or return undef;
492 0 return @$ret;
493 }
494  
495  
496 0 ▶sub list_tube_used {
Subroutine list_tube_used: not called CC=3 SCAR=24.8
Pod documented
497 0 my $self = shift;
498 0 ▶ my @resp = _interact($self, "list-tube-used")
Branch: 1 branch
BranchTrueFalseTotal
my(@resp) = _interact($self, "list-tube-used") or return undef 0 0 0
499 or return undef;
500 0 ▶ return $resp[1] if $resp[0] eq 'USING';
Branch: 1 branch
BranchTrueFalseTotal
if $resp[0] eq "USING" 0 0 0
501  
502 0 $self->error(join ' ', @resp);
503 0 return undef;
504 }
505  
506  
507 1 ▶sub list_tubes_watched {
Subroutine list_tubes_watched: called CC=2 SCAR=10.1
Pod documented
508 1 my $self = shift;
509 1 ▶ my $ret = _interact_yaml_resp($self, "list-tubes-watched")
Branch: 1 branch
BranchTrueFalseTotal
my $ret = _interact_yaml_resp($self, "list-tubes-watched") or return 0 1 1
510 or return;
511 0 $self->_watching( { map { ($_,1) } @$ret });
512 0 @$ret;
513 }
514  
515  
516 0 ▶sub pause_tube {
Subroutine pause_tube: not called CC=4 SCAR=30.0
Pod documented
517 0 my $self = shift;
518 0 my $tube = shift;
519 0 ▶ my $delay= shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
520 0 ▶ my @resp = _interact($self, "pause-tube $tube $delay")
Branch: 1 branch
BranchTrueFalseTotal
my(@resp) = _interact($self, "pause-tube $tube $delay") or return undef 0 0 0
521 or return undef;
522 0 ▶ return 1 if $resp[0] eq 'PAUSED';
Branch: 1 branch
BranchTrueFalseTotal
if $resp[0] eq "PAUSED" 0 0 0
523  
524 0 $self->error(join ' ', @resp);
525 0 return undef;
526 }
527  
528 3 1;
529  
530 __END__
↑ Summary Stats.pm »