File Coverage

blib/lib/IO/SigGuard/select.pm
Criterion Covered Total %
statement 15 16 93.7
branch 6 8 75.0
condition 1 2 50.0
subroutine 2 2 100.0
pod 1 1 100.0
total 25 29 86.2


line stmt bran cond sub pod time code
1             package IO::SigGuard;
2              
3             #Set this in lieu of using Time::HiRes or built-in time().
4             our $TIME_CR;
5              
6             my ($start, $last_loop_time, $os_error, $nfound, $timeleft, $timer_cr);
7              
8             #pre-5.16 didn’t have \&CORE::time.
9 27     27   90 sub _time { time }
10              
11             sub select {
12 6 50   6 1 19910 die( (caller 0)[3] . ' must have 4 arguments!' ) if @_ != 4;
13              
14 6         56 $os_error = $!;
15              
16 6   50     132 $timer_cr = $TIME_CR || Time::HiRes->can('time') || \&_time;
17              
18 6         25 $start = $timer_cr->();
19 6         20 $last_loop_time = $start;
20              
21             SELECT: {
22 6         8 ($nfound, $timeleft) = CORE::select( $_[0], $_[1], $_[2], $_[3] - $last_loop_time + $start );
  27         10020798  
23 27 100       646 if ($nfound == -1) {
24              
25             #Use of %! will autoload Errno.pm,
26             #which can affect the value of $!.
27 21         11132 my $select_error = $!;
28              
29 21 50       134 if ($! == Errno::EINTR()) {
30 21         105 $last_loop_time = $timer_cr->();
31 21         94 redo SELECT;
32             }
33              
34 0         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         19 $! = $os_error;
41             }
42              
43 6 100       33 return wantarray ? ($nfound, $timeleft) : $nfound;
44             }
45             }
46              
47             1;