/usr/local/lib/perl5/5.44.0/x86_64-linux/IO/Select.pm

filter: Statementstmt 65.8% 81 / 123 Branchbran 50.0% 39 / 78 Conditioncond 30.9% 13 / 42 MC/DCmcdc 8.0% 2 / 25 Subroutinesub 66.6% 12 / 18 Podpod 84.6% 11 / 13 totaltotal 52.8% 158 / 299 CC 58 SCAR 28.6
CC
58
Cov
55%
select
32.8
_fileno
21.2
as_string
20.0
CRAP 17.5
« /usr/local/lib/perl5/5.44.0/x86_64-linux/IO/Handle.pm ↑ Summary /usr/local/lib/perl5/5.44.0/x86_64-linux/Encode/Alias.pm »
1 # IO::Select.pm
2 #
3 # Copyright (c) 1997-8 Graham Barr <gbarr@pobox.com>. All rights reserved.
4 # This program is free software; you can redistribute it and/or
5 # modify it under the same terms as Perl itself.
6  
7 package IO::Select;
8  
9 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 require Exporter;
12  
13 7 our $VERSION = "1.56";
14  
15 7 our @ISA = qw(Exporter); # This is only so we can do version checking
16  
17 sub VEC_BITS () {0}
18 sub FD_COUNT () {1}
19 sub FIRST_FD () {2}
20  
21 sub new
22 12 ▶{
Subroutine new: called CC=3 SCAR=11.2
Pod documented
23 12 my $self = shift;
24 12 ▶ my $type = ref($self) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
0120
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
25  
26 12 my $vec = bless [undef,0], $type;
27  
28 12 ▶ $vec->add(@_)
Branch: 1 branch
BranchTrueFalseTotal
if @_ 6 6 12
29 if @_;
30  
31 12 $vec;
32 }
33  
34 sub add
35 6 ▶{
Subroutine add: called CC=1 SCAR=0.0
Pod documented
36 6 shift->_update('add', @_);
37 }
38  
39  
40 sub remove
41 12 ▶{
Subroutine remove: called CC=1 SCAR=0.0
Pod documented
42 12 shift->_update('remove', @_);
43 }
44  
45  
46 sub exists
47 0 ▶{
Subroutine exists: not called CC=2 SCAR=17.9
Pod documented
48 0 my $vec = shift;
49 0 my $fno = $vec->_fileno(shift);
50 0 ▶ return undef unless defined $fno;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fno 0 0 0
51 0 $vec->[$fno + FIRST_FD];
52 }
53  
54  
55 sub _fileno
56 24 ▶{
Subroutine _fileno: called CC=8 SCAR=30.5
57 24 my($self, $f) = @_;
58 24 ▶ return unless defined $f;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f 0 24 24
59 24 ▶ $f = $f->[0] if ref($f) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $f eq "ARRAY" 0 24 24
60 24 ▶ if($f =~ /^[0-9]+$/) { # plain file number
Branch: 2 branches
BranchTrueFalseTotal
if ($f =~ /^[0-9]+$/) { } 0 24 24
elsif (defined(my $fd = fileno $f)) { } 24 0 24
61 0 return $f;
62 }
63 elsif(defined(my $fd = fileno($f))) {
64 24 return $fd;
65 }
66 else {
67 # Neither a plain file number nor an opened filehandle; but maybe it was
68 # previously registered and has since been closed. ->remove still wants to
69 # know what fileno it had
70 0 foreach my $i ( FIRST_FD .. $#$self ) {
71 0 ▶ return $i - FIRST_FD if defined $self->[$i] && $self->[$i] == $f;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->[$i] and $self->[$i] == $f 0 0 0
Condition0%0/3
defined $self->[$i] and $self->[$i] == $f
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->[$i] and $self->[$i] == $f
defined $self->[$i] $self->[$i] == $f
Truth table0%0/3
A and B
A= defined $self->[$i]B= $self->[$i] == $f
ABresult
0X0
100
111
72 }
73 0 return undef;
74 }
75 }
76  
77 sub _update
78 18 ▶{
Subroutine _update: called CC=12 SCAR=29.6
79 18 my $vec = shift;
80 18 my $add = shift eq 'add';
81  
82 18 my $bits = $vec->[VEC_BITS];
83 18 ▶ $bits = '' unless defined $bits;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bits 6 12 18
84  
85 18 my $count = 0;
86 18 my $f;
87 18 foreach $f (@_)
88 {
89 24 my $fn = $vec->_fileno($f);
90 24 ▶ if ($add) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add) { } 12 12 24
91 12 ▶ next unless defined $fn;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fn 0 12 12
92 12 my $i = $fn + FIRST_FD;
93 12 ▶ if (defined $vec->[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $vec->[$i]) 0 12 12
94 0 $vec->[$i] = $f; # if array rest might be different, so we update
95 0 next;
96 }
97 12 $vec->[FD_COUNT]++;
98 12 vec($bits, $fn, 1) = 1;
99 12 $vec->[$i] = $f;
100 } else { # remove
101 12 ▶ if ( ! defined $fn ) { # remove if fileno undef'd
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $fn) { } 0 12 12
102 0 $fn = 0;
103 0 for my $fe (@{$vec}[FIRST_FD .. $#$vec]) {
104 0 ▶ if (defined($fe) && $fe == $f) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fe and $fe == $f) 0 0 0
Condition0%0/3
defined $fe and $fe == $f
!ll&&!rl&&r
000
MC/DC0%0/2
defined $fe and $fe == $f
defined $fe $fe == $f
Truth table0%0/3
A and B
A= defined $feB= $fe == $f
ABresult
0X0
100
111
105 0 $vec->[FD_COUNT]--;
106 0 $fe = undef;
107 0 vec($bits, $fn, 1) = 0;
108 0 last;
109 }
110 0 ++$fn;
111 }
112 }
113 else {
114 12 my $i = $fn + FIRST_FD;
115 12 ▶ next unless defined $vec->[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $vec->[$i] 0 12 12
116 12 $vec->[FD_COUNT]--;
117 12 vec($bits, $fn, 1) = 0;
118 12 $vec->[$i] = undef;
119 }
120 }
121 24 $count++;
122 }
123 18 ▶ $vec->[VEC_BITS] = $vec->[FD_COUNT] ? $bits : undef;
Branch: 1 branch
BranchTrueFalseTotal
$vec->[1] ? : 12 6 18
124 18 $count;
125 }
126  
127 sub can_read
128 6 ▶{
Subroutine can_read: called CC=3 SCAR=12.0
Pod documented
129 6 my $vec = shift;
130 6 my $timeout = shift;
131 6 my $r = $vec->[VEC_BITS];
132  
133 6 ▶ defined($r) && (select($r,undef,undef,$timeout) > 0)
Branch: 1 branch
BranchTrueFalseTotal
defined $r && CORE::select($r, undef, undef, $timeout) > 0 ? : 6 0 6
Condition33%1/3
defined $r and CORE::select($r, undef, undef, $timeout) > 0
!ll&&!rl&&r
006
MC/DC0%0/2
defined $r and CORE::select($r, undef, undef, $timeout) > 0
defined $r CORE::select($r, undef, undef, $timeout) > 0
Truth table33%1/3
A and B
A= defined $rB= CORE::select($r, undef, undef, $timeout) > 0
ABresult
0X0
100
111
134 ? handles($vec, $r)
135 : ();
136 }
137  
138 sub can_write
139 0 ▶{
Subroutine can_write: not called CC=3 SCAR=24.8
Pod documented
140 0 my $vec = shift;
141 0 my $timeout = shift;
142 0 my $w = $vec->[VEC_BITS];
143  
144 0 ▶ defined($w) && (select(undef,$w,undef,$timeout) > 0)
Branch: 1 branch
BranchTrueFalseTotal
defined $w && CORE::select(undef, $w, undef, $timeout) > 0 ? : 0 0 0
Condition0%0/3
defined $w and CORE::select(undef, $w, undef, $timeout) > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $w and CORE::select(undef, $w, undef, $timeout) > 0
defined $w CORE::select(undef, $w, undef, $timeout) > 0
Truth table0%0/3
A and B
A= defined $wB= CORE::select(undef, $w, undef, $timeout) > 0
ABresult
0X0
100
111
145 ? handles($vec, $w)
146 : ();
147 }
148  
149 sub has_exception
150 0 ▶{
Subroutine has_exception: not called CC=3 SCAR=24.8
Pod documented
151 0 my $vec = shift;
152 0 my $timeout = shift;
153 0 my $e = $vec->[VEC_BITS];
154  
155 0 ▶ defined($e) && (select(undef,undef,$e,$timeout) > 0)
Branch: 1 branch
BranchTrueFalseTotal
defined $e && CORE::select(undef, undef, $e, $timeout) > 0 ? : 0 0 0
Condition0%0/3
defined $e and CORE::select(undef, undef, $e, $timeout) > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $e and CORE::select(undef, undef, $e, $timeout) > 0
defined $e CORE::select(undef, undef, $e, $timeout) > 0
Truth table0%0/3
A and B
A= defined $eB= CORE::select(undef, undef, $e, $timeout) > 0
ABresult
0X0
100
111
156 ? handles($vec, $e)
157 : ();
158 }
159  
160 sub has_error
161 0 ▶{
Subroutine has_error: not called CC=2 SCAR=17.9
Pod undocumented
162 0 ▶ warnings::warn("Call to deprecated method 'has_error', use 'has_exception'")
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
163 if warnings::enabled();
164 0 goto &has_exception;
165 }
166  
167 sub count
168 48 ▶{
Subroutine count: called CC=1 SCAR=0.0
Pod documented
169 48 my $vec = shift;
170 48 $vec->[FD_COUNT];
171 }
172  
173 sub bits
174 0 ▶{
Subroutine bits: not called CC=1 SCAR=6.9
Pod documented
175 0 my $vec = shift;
176 0 $vec->[VEC_BITS];
177 }
178  
179 sub as_string # for debugging
180 0 ▶{
Subroutine as_string: not called CC=4 SCAR=30.0
Pod undocumented
181 0 my $vec = shift;
182 0 my $str = ref($vec) . ": ";
183 0 my $bits = $vec->bits;
184 0 my $count = $vec->count;
185 0 ▶ $str .= defined($bits) ? unpack("b*", $bits) : "undef";
Branch: 1 branch
BranchTrueFalseTotal
defined $bits ? : 0 0 0
186 0 $str .= " $count";
187 0 my @handles = @$vec;
188 0 splice(@handles, 0, FIRST_FD);
189 0 for (@handles) {
190 0 ▶ $str .= " " . (defined($_) ? "$_" : "-");
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
191 }
192 0 $str;
193 }
194  
195 sub _max
196 6 ▶{
Subroutine _max: called CC=4 SCAR=17.9
197 6 my($a,$b,$c) = @_;
198 6 ▶ $a > $b
Branch: 3 branches
BranchTrueFalseTotal
$a > $b ? : 6 0 6
$a > $c ? : 6 0 6
$b > $c ? : 0 0 0
199 ? $a > $c
200 ? $a
201 : $c
202 : $b > $c
203 ? $b
204 : $c;
205 }
206  
207 sub select
208 12 ▶{
Subroutine select: called CC=20 SCAR=34.9
Pod documented
209 shift
210 12 ▶ if defined $_[0] && !ref($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and not ref $_[0] 12 0 12
Condition33%1/3
defined $_[0] and not ref $_[0]
!ll&&!rl&&r
0012
MC/DC0%0/2
defined $_[0] and not ref $_[0]
defined $_[0] not ref $_[0]
Truth table33%1/3
A and not(B)
A= defined $_[0]B= not ref $_[0]
ABresult
0X0
100
111
211  
212 12 my($r,$w,$e,$t) = @_;
213 12 my @result = ();
214  
215 12 ▶ my $rb = defined $r ? $r->[VEC_BITS] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $r ? : 12 0 12
216 12 ▶ my $wb = defined $w ? $w->[VEC_BITS] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $w ? : 0 12 12
217 12 ▶ my $eb = defined $e ? $e->[VEC_BITS] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $e ? : 0 12 12
218  
219 12 ▶ if(select($rb,$wb,$eb,$t) > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::select($rb, $wb, $eb, $t) > 0) 6 6 12
220 {
221 6 my @r = ();
222 6 my @w = ();
223 6 my @e = ();
224 6 ▶ my $i = _max(defined $r ? scalar(@$r)-1 : 0,
Branch: 3 branches
BranchTrueFalseTotal
defined $r ? : 6 0 6
defined $w ? : 0 6 6
defined $e ? : 0 6 6
225 defined $w ? scalar(@$w)-1 : 0,
226 defined $e ? scalar(@$e)-1 : 0);
227  
228 6 ▶ for( ; $i >= FIRST_FD ; $i--)
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 2) 42 6 48
229 {
230 42 my $j = $i - FIRST_FD;
231 42 ▶ push(@r, $r->[$i])
Branch: 1 branch
BranchTrueFalseTotal
if defined $rb and defined $r->[$i] and vec $rb, $j, 1 6 36 42
Condition83%5/6
defined $rb and defined $r->[$i] and vec $rb, $j, 1
!ll&&!rl&&r
3066
defined $rb and defined $r->[$i]
!ll&&!rl&&r
03012
MC/DC66%2/3
defined $rb and defined $r->[$i] and vec $rb, $j, 1
defined $rb defined $r->[$i] vec $rb, $j, 1
Truth table75%3/4
A and B and C
A= defined $rbB= defined $r->[$i]C= vec $rb, $j, 1
ABCresult
0XX0
10X0
1100
1111
232 if defined $rb && defined $r->[$i] && vec($rb, $j, 1);
233 42 ▶ push(@w, $w->[$i])
Branch: 1 branch
BranchTrueFalseTotal
if defined $wb and defined $w->[$i] and vec $wb, $j, 1 0 42 42
Condition33%2/6
defined $wb and defined $w->[$i] and vec $wb, $j, 1
!ll&&!rl&&r
4200
defined $wb and defined $w->[$i]
!ll&&!rl&&r
4200
MC/DC0%0/3
defined $wb and defined $w->[$i] and vec $wb, $j, 1
defined $wb defined $w->[$i] vec $wb, $j, 1
Truth table25%1/4
A and B and C
A= defined $wbB= defined $w->[$i]C= vec $wb, $j, 1
ABCresult
0XX0
10X0
1100
1111
234 if defined $wb && defined $w->[$i] && vec($wb, $j, 1);
235 42 ▶ push(@e, $e->[$i])
Branch: 1 branch
BranchTrueFalseTotal
if defined $eb and defined $e->[$i] and vec $eb, $j, 1 0 42 42
Condition33%2/6
defined $eb and defined $e->[$i] and vec $eb, $j, 1
!ll&&!rl&&r
4200
defined $eb and defined $e->[$i]
!ll&&!rl&&r
4200
MC/DC0%0/3
defined $eb and defined $e->[$i] and vec $eb, $j, 1
defined $eb defined $e->[$i] vec $eb, $j, 1
Truth table25%1/4
A and B and C
A= defined $ebB= defined $e->[$i]C= vec $eb, $j, 1
ABCresult
0XX0
10X0
1100
1111
236 if defined $eb && defined $e->[$i] && vec($eb, $j, 1);
237 }
238  
239 6 @result = (\@r, \@w, \@e);
240 }
241 12 @result;
242 }
243  
244  
245 sub handles
246 12 ▶{
Subroutine handles: called CC=5 SCAR=16.3
Pod documented
247 12 my $vec = shift;
248 12 my $bits = shift;
249 12 my @h = ();
250 12 my $i;
251 12 my $max = scalar(@$vec) - 1;
252  
253 12 ▶ for ($i = FIRST_FD; $i <= $max; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $max) 42 12 54
254 {
255 42 ▶ next unless defined $vec->[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $vec->[$i] 30 12 42
256 12 ▶ push(@h, $vec->[$i])
Branch: 1 branch
BranchTrueFalseTotal
if not defined $bits or vec $bits, $i - 2, 1 12 0 12
Condition33%1/3
not defined $bits or vec $bits, $i - 2, 1
l!l&&r!l&&!r
0120
MC/DC0%0/2
not defined $bits or vec $bits, $i - 2, 1
not defined $bits vec $bits, $i - 2, 1
Truth table33%1/3
not(A) or B
A= not defined $bitsB= vec $bits, $i - 2, 1
ABresult
1X1
011
000
257 if !defined($bits) || vec($bits, $i - FIRST_FD, 1);
258 }
259
260 12 @h;
261 }
262  
263 7 1;
264 __END__
« /usr/local/lib/perl5/5.44.0/x86_64-linux/IO/Handle.pm ↑ Summary /usr/local/lib/perl5/5.44.0/x86_64-linux/Encode/Alias.pm »