SigGuard/select.pm

filter: Statementstmt 89.4% 17 / 19 Branchbran 75.0% 6 / 8 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 1 / 2 Podpod 100% 1 / 1 totaltotal 72.9% 27 / 37 CC 7 SCAR 19.2
CC
7
Cov
78%
select
7.5
_time
2.0
CRAP 6.8
« SigGuard/send.pm ↑ Summary SigGuard/sysread.pm »
1 package IO::SigGuard;
2  
3 #Set this in lieu of using Time::HiRes or built-in time().
4 1 our $TIME_CR;
5  
6 1 my ($start, $last_loop_time, $os_error, $nfound, $timeleft, $timer_cr);
7  
8 #pre-5.16 didn’t have \&CORE::time.
9 0 ▶sub _time { time }
Subroutine _time: not called CC=1 SCAR=6.9
10  
11 6 ▶sub select {
Subroutine select: called CC=7 SCAR=20.1
Pod documented
12 6 ▶ die( (caller 0)[3] . ' must have 4 arguments!' ) if @_ != 4;
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 4 0 6 6
13  
14 6 $os_error = $!;
15  
16 6 ▶ $timer_cr = $TIME_CR || Time::HiRes->can('time') || \&_time;
Condition40%2/5
$TIME_CR || 'Time::HiRes'->can('time') || \&_time
l!l
60
$TIME_CR or "Time::HiRes"->can("time")
l!l&&r!l&&!r
060
MC/DC0%0/2
$TIME_CR || 'Time::HiRes'->can('time') || \&_time
$TIME_CR "Time::HiRes"->can("time")
Truth table33%1/3
A or B
A= $TIME_CRB= "Time::HiRes"->can("time")
ABresult
1X1
011
000
17  
18 6 $start = $timer_cr->();
19 6 $last_loop_time = $start;
20  
21 SELECT: {
22 6 ($nfound, $timeleft) = CORE::select( $_[0], $_[1], $_[2], $_[3] - $last_loop_time + $start );
23 25 ▶ if ($nfound == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nfound == -1) { } 19 6 25
24  
25 #Use of %! will autoload Errno.pm,
26 #which can affect the value of $!.
27 19 my $select_error = $!;
28  
29 19 ▶ if ($! == Errno::EINTR()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($! == 4) 19 0 19
30 19 $last_loop_time = $timer_cr->();
31 19 redo SELECT;
32 }
33  
34 0 $! = $select_error;
35 }
36 else {
37  
38 #select() doesn’t set $! on success, so let’s not clobber what
39 #value was there before.
40 6 $! = $os_error;
41 }
42  
43 6 ▶ return wantarray ? ($nfound, $timeleft) : $nfound;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 3 6
44 }
45 }
46  
47 1 1;
« SigGuard/send.pm ↑ Summary SigGuard/sysread.pm »