| 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
| |||||||||||||||||||||||||
| 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
$TIME_CR or "Time::HiRes"->can("time")
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")
| |||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||
| 47 | 1 | 1; | |||||||||||||||||||||||