blib/lib/IO/Die.pm

filter: Statementstmt 25.8% 96 / 372 Branchbran 21.7% 44 / 202 Conditioncond 16.6% 4 / 24 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 32.7% 18 / 55 Podpod 20.8% 10 / 48 totaltotal 24.0% 172 / 716 SCAR 86.1
CC
111
Cov
24%
open
96.7
syswrite
72.0
print
56.0
CRAP 5502.5
↑ Summary Build »
1 package IO::Die;
2  
3 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 #not in production
7 #use warnings;
8  
9 =head1 NAME
10  
11 IO::Die - Namespaced, error-checked I/O
12  
13 =head1 VERSION
14  
15 Version 0.056
16  
17 =cut
18  
19 2 our $VERSION = '0.056';
20  
21 #----------------------------------------------------------------------
22 #PROTECTED
23  
24 #Override in subclasses as needed
25 sub _CREATE_ERROR {
26 11 ▶ shift;
Subroutine _CREATE_ERROR: called CC=2 SCAR=7.1
27 11 ▶ return shift() . ": " . join( ' ', map { defined() ? $_ : q<> } @_ );
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 70 0 70
28 }
29  
30 12 ▶sub _DO_WITH_ERROR { die $_[1] }
Subroutine _DO_WITH_ERROR: called CC=1 SCAR=0.0
31  
32 #----------------------------------------------------------------------
33 #PRIVATES
34  
35 sub __THROW {
36 12 ▶ my ( $NS, $type, @args ) = @_;
Subroutine __THROW: called CC=1 SCAR=0.0
37  
38 12 $NS->_DO_WITH_ERROR(
39 $NS->_CREATE_ERROR(
40 $type,
41 @args,
42 OS_ERROR => $!,
43 EXTENDED_OS_ERROR => $^E,
44 )
45 );
46 }
47  
48 sub __is_a_fh {
49 5 ▶ my ($thing) = @_;
Subroutine __is_a_fh: called CC=3 SCAR=11.2
50  
51 5 my $is_fh;
52  
53 #Every file handle is a GLOB reference. This would be sufficient, except
54 #GLOBs can also be symbol table references.
55 5 ▶ if ( UNIVERSAL::isa( $thing, 'GLOB' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($thing, "GLOB")) 2 3 5
56  
57 # You can’t tie() a symbol table reference, so if we’re tied(),
58 # then this is a filehandle.
59 #
60 # If we’re not tied(), then we have to check fileno().
61 2 ▶ $is_fh = ( tied *{$thing} ) || defined( CORE::fileno($thing) );
Condition33%1/3
tied *{$thing;} || defined CORE::fileno $thing
l!l&&r!l&&!r
002
MC/DC0%0/2
tied *{$thing;} || defined CORE::fileno $thing
tied *{$thing;} defined CORE::fileno $thing
Truth table33%1/3
A || B
A= tied *{$thing;}B= defined CORE::fileno $thing
ABresult
1X1
011
000
62 }
63  
64 5 return $is_fh;
65 }
66  
67 #----------------------------------------------------------------------
68  
69 #NOTE: This function does not attempt to support every possible way of calling
70 #Perl’s open() built-in, but to support the minimal syntax required to do
71 #everything that is useful to do with open(), with preference given to those
72 #forms that may (somewhat arbitrarily) be considered "better".
73 #
74 #For example, this function does NOT allow one-arg or two-arg open() except for
75 #the more "useful" cases like when MODE is '-|' or '|-'.
76 #
77 #On the other hand, open($fh, '-') seems harder to understand than its 3-arg
78 #equivalent, open($fh, '<&=', STDIN), so that two-arg form is unsupported.
79 #
80 #Current forms of open() that this supports are:
81 # - any form of 3 or more arguments
82 # - 2-arg when the MODE is '-|' or '|-'
83 #
84 #NOTE: Bareword file handles DO NOT WORK. (Auto-vivification does, though.)
85 #
86 sub open {
87 4 ▶ my ( $NS, $mode, $expr, @list ) = ( shift, @_[ 1 .. $#_ ] );
Subroutine open: called CC=14 SCAR=45.7
Pod documented
88  
89 #https://github.com/pjcj/Devel--Cover/issues/125
90 #my ( $NS, $handle_r, $mode, $expr, @list ) = ( shift, \shift, @_ );
91  
92 4 ▶ die "Avoid bareword file handles." if !ref $_[0] && defined $_[0] && length $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if not ref $_[0] and defined $_[0] and length $_[0] 0 4 4
Condition33%2/6
not ref $_[0] and defined $_[0] and length $_[0]
!ll&&!rl&&r
400
not ref $_[0] and defined $_[0]
!ll&&!rl&&r
040
MC/DC0%0/3
not ref $_[0] and defined $_[0] and length $_[0]
not ref $_[0] defined $_[0] length $_[0]
Truth table25%1/4
not(A) and B and C
A= not ref $_[0]B= defined $_[0]C= length $_[0]
ABCresult
0XX0
10X0
1100
1111
93 4 ▶ die "Avoid one-argument open()." if !$mode;
Branch: 1 branch
BranchTrueFalseTotal
unless $mode 0 4 4
94  
95 4 local ( $!, $^E );
96 4 ▶ if ( !defined $expr ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $expr) 0 4 4
97 0 ▶ if ( $mode eq '|-' or $mode eq '-|' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "|-" or $mode eq "-|") 0 0 0
Condition0%0/3
$mode eq "|-" or $mode eq "-|"
l!l&&r!l&&!r
000
MC/DC0%0/2
$mode eq "|-" or $mode eq "-|"
$mode eq "|-" $mode eq "-|"
Truth table0%0/3
A or B
A= $mode eq "|-"B= $mode eq "-|"
ABresult
1X1
011
000
98  
99 #NOTE: Avoid // for compatibility with old Perl versions.
100 0 my $open = CORE::open( $_[0], $mode );
101 0 ▶ if ( !defined $open ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $open) 0 0 0
102 0 $NS->__THROW('Fork');
103 }
104  
105 0 return $open;
106 }
107  
108 0 my $file = __FILE__;
109 0 die "Avoid most forms of two-argument open(). (See $file and its tests for allowable forms.)";
110 }
111  
112 4 ▶ my $ok = CORE::open( $_[0], $mode, $expr, @list ) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::open($_[0], $mode, $expr, @list) or do { if ($mode eq "|-" or $mode eq "-|") { my $cmd = $expr; unless (@list) { ($cmd) = $cmd =~ /\A(\S+)/; } ; $NS->__THROW("Exec", "path", $cmd, "arguments", \@list); } ; if ("SCALAR" eq ref $expr) { $NS->__THROW("ScalarOpen"); } ; $NS->__THROW("FileOpen", "mode", $mode, "path", $expr) } 0 4 4
113 0 ▶ if ( $mode eq '|-' || $mode eq '-|' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "|-" or $mode eq "-|") 0 0 0
Condition0%0/3
$mode eq "|-" or $mode eq "-|"
l!l&&r!l&&!r
000
MC/DC0%0/2
$mode eq "|-" or $mode eq "-|"
$mode eq "|-" $mode eq "-|"
Truth table0%0/3
A or B
A= $mode eq "|-"B= $mode eq "-|"
ABresult
1X1
011
000
114 0 my $cmd = $expr;
115  
116 #If the EXPR (cf. perldoc -f open) has spaces and no LIST
117 #is given, then Perl interprets EXPR as a space-delimited
118 #shell command, the first component of which is the actual
119 #command.
120 0 ▶ if ( !@list ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@list) 0 0 0
121 0 ($cmd) = ( $cmd =~ m<\A(\S+)> );
122 }
123  
124 0 $NS->__THROW( 'Exec', path => $cmd, arguments => \@list );
125 }
126  
127 0 ▶ if ( 'SCALAR' eq ref $expr ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("SCALAR" eq ref $expr) 0 0 0
128 0 $NS->__THROW('ScalarOpen');
129 }
130  
131 0 $NS->__THROW( 'FileOpen', mode => $mode, path => $expr );
132 };
133  
134 4 return $ok;
135 }
136  
137 sub sysopen {
138 0 ▶ my ( $NS, @post_handle_args ) = ( shift, @_[ 1 .. $#_ ] );
Subroutine sysopen: not called CC=3 SCAR=24.8
Pod undocumented
139  
140 #https://github.com/pjcj/Devel--Cover/issues/125
141 #my ( $NS, $handle_r, @post_handle_args ) = ( shift, \shift, @_ );
142  
143 0 my ( $path, $mode, $perms ) = @post_handle_args;
144  
145 0 local ( $!, $^E );
146  
147 0 my $ret;
148 0 ▶ if ( @post_handle_args < 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@post_handle_args < 3) { } 0 0 0
149 0 $ret = CORE::sysopen( $_[0], $path, $mode );
150 }
151 else {
152 0 $ret = CORE::sysopen( $_[0], $path, $mode, $perms );
153 }
154  
155 #XXX: Perl bug? $! is often set here even when $ret is truthy.
156  
157 0 ▶ if ( !$ret ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ret) 0 0 0
158 0 $NS->__THROW( 'FileOpen', path => $path, mode => $mode, mask => $perms );
159 }
160  
161 0 return $ret;
162 }
163  
164 sub chroot {
165 0 ▶ my ( $NS, $filename ) = @_;
Subroutine chroot: not called CC=3 SCAR=24.8
Pod undocumented
166  
167 0 local ( $!, $^E );
168  
169 0 ▶ if ( !defined $filename ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $filename) 0 0 0
170 0 $filename = $_;
171 }
172  
173 0 ▶ my $ok = CORE::chroot($filename) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::chroot $filename or do { $NS->__THROW("Chroot", "filename", $filename) } 0 0 0
174 0 $NS->__THROW( 'Chroot', filename => $filename );
175 };
176  
177 0 return $ok;
178 }
179  
180 sub chdir {
181 8 ▶ my ( $NS, @args ) = @_;
Subroutine chdir: called CC=6 SCAR=18.0
Pod undocumented
182  
183 8 local ( $!, $^E );
184  
185 8 my $ret;
186  
187 8 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) { } 4 4 8
188 4 ▶ $ret = CORE::chdir( $args[0] ) or do {
Branch: 1 branch
BranchTrueFalseTotal
$ret = CORE::chdir $args[0] or do { if (__is_a_fh($args[0])) { $NS->__THROW("Chdir"); } else { $NS->__THROW("Chdir", "path", $args[0]); } } 1 3 4
189 1 ▶ if ( __is_a_fh( $args[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (__is_a_fh($args[0])) { } 0 1 1
190 0 $NS->__THROW('Chdir');
191 }
192 else {
193 1 $NS->__THROW( 'Chdir', path => $args[0] );
194 }
195 };
196 }
197 else {
198 4 ▶ $ret = CORE::chdir or do {
Branch: 1 branch
BranchTrueFalseTotal
$ret = CORE::chdir or do { my $path = _get_what_chdir_took_as_homedir(); unless (defined $path) { $NS->__THROW("Chdir"); } ; $NS->__THROW("Chdir", "path", $path) } 2 2 4
199 2 my $path = _get_what_chdir_took_as_homedir();
200  
201 2 ▶ if ( !defined $path ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $path) 1 1 2
202 1 $NS->__THROW('Chdir');
203 }
204  
205 1 $NS->__THROW( 'Chdir', path => $path );
206 };
207 }
208  
209 5 return $ret;
210 }
211  
212 sub _get_what_chdir_took_as_homedir {
213 2 ▶ my $path = $ENV{'HOME'};
Subroutine _get_what_chdir_took_as_homedir: called CC=4 SCAR=15.0
214 2 ▶ if ( !defined $path ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $path) 1 1 2
215 1 $path = $ENV{'LOGDIR'};
216  
217 1 ▶ if ( !defined($path) && $^O eq 'VMS' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $path and $^O eq "VMS") 0 1 1
Condition33%1/3
not defined $path and $^O eq "VMS"
!ll&&!rl&&r
010
MC/DC0%0/2
not defined $path and $^O eq "VMS"
not defined $path $^O eq "VMS"
Truth table33%1/3
not(A) and B
A= not defined $pathB= $^O eq "VMS"
ABresult
0X0
100
111
218 0 $path = $ENV{'SYS$LOGIN'};
219 }
220 }
221  
222 2 return $path;
223 }
224  
225 #A bit more restrictive than Perl’s built-in print():
226 # - A file handle is still optional, but it MUST be a reference.
227 #
228 #This does still fall back to $_ and does still use the default file handle
229 #if either the LIST or FILEHANDLE is omitted (cf. perldoc -f print).
230 #
231 sub print {
232 0 ▶ my ( $NS, $args_ar ) = ( shift, \@_ );
Subroutine print: not called CC=7 SCAR=40.3
Pod undocumented
233  
234 0 local ( $!, $^E );
235  
236 0 my $ret;
237 0 ▶ if ( __is_a_fh( $args_ar->[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (__is_a_fh($args_ar->[0])) { } 0 0 0
238 0 ▶ $ret = CORE::print { shift @$args_ar } ( @$args_ar ? @$args_ar : $_ );
Branch: 1 branch
BranchTrueFalseTotal
@$args_ar ? : 0 0 0
239 }
240 else {
241 0 ▶ $ret = CORE::print( @$args_ar ? @$args_ar : $_ );
Branch: 1 branch
BranchTrueFalseTotal
@$args_ar ? : 0 0 0
242 }
243  
244 0 ▶ if ($^E) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^E) 0 0 0
245  
246 #Figure out the "length" to report to the exception object.
247 0 my $length;
248 0 ▶ if (@$args_ar) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$args_ar) { } 0 0 0
249 0 $length = 0;
250 0 $length += length for @$args_ar;
251 }
252 else {
253 0 $length = length;
254 }
255  
256 0 $NS->__THROW( 'Write', length => $length );
257 }
258  
259 0 return $ret;
260 }
261  
262 sub syswrite {
263 0 ▶ my ( $NS, $fh, @length_offset ) = ( shift, shift, @_[ 1 .. $#_ ] );
Subroutine syswrite: not called CC=8 SCAR=42.8
Pod undocumented
264  
265 #https://github.com/pjcj/Devel--Cover/issues/125
266 #my ( $NS, $fh, $buffer_sr, @length_offset ) = ( shift, shift, \shift, @_ );
267  
268 0 my ( $length, $offset ) = @length_offset;
269  
270 0 local ( $!, $^E );
271  
272 0 my $ret;
273 0 ▶ if ( @length_offset > 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@length_offset > 1) { } 0 0 0
elsif (@length_offset) { } 0 0 0
274 0 $ret = CORE::syswrite( $fh, $_[0], $length, $offset );
275 }
276 elsif (@length_offset) {
277 0 $ret = CORE::syswrite( $fh, $_[0], $length );
278 }
279 else {
280 0 $ret = CORE::syswrite( $fh, $_[0] );
281 }
282  
283 0 ▶ if ( !defined $ret ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ret) 0 0 0
284 0 my $real_length = length $_[0];
285  
286 0 ▶ if ($offset) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset) 0 0 0
287 0 ▶ if ( $offset > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset > 0) { } 0 0 0
288 0 $real_length -= $offset;
289 }
290 else {
291 0 $real_length = 0 - $offset;
292 }
293 }
294  
295 0 ▶ if ( defined $length && $length < $real_length ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $length and $length < $real_length) 0 0 0
Condition0%0/3
defined $length and $length < $real_length
!ll&&!rl&&r
000
MC/DC0%0/2
defined $length and $length < $real_length
defined $length $length < $real_length
Truth table0%0/3
A and B
A= defined $lengthB= $length < $real_length
ABresult
0X0
100
111
296 0 $real_length = $length;
297 }
298  
299 0 $NS->__THROW( 'Write', length => $real_length );
300 }
301  
302 0 return $ret;
303 }
304  
305 #----------------------------------------------------------------------
306 #NOTE: read() and sysread() implementations are exactly the same except
307 #for the CORE:: function call. Alas, Perl’s prototyping stuff seems to
308 #make it impossible not to duplicate code here.
309  
310 sub read {
311 1 ▶ my ( $NS, $fh, @length_offset ) = ( shift, shift, @_[ 1 .. $#_ ] );
Subroutine read: called CC=3 SCAR=11.7
Pod undocumented
312  
313 #https://github.com/pjcj/Devel--Cover/issues/125
314 #my ( $NS, $fh, $buffer_sr, @length_offset ) = ( shift, shift, \shift, @_ );
315  
316 1 my ( $length, $offset ) = @length_offset;
317  
318 1 local ( $!, $^E );
319  
320 #NOTE: Perl’s prototypes can throw errors on things like:
321 #(@length_offset > 1) ? $offset : ()
322 #...so the following writes out the two forms of read():
323  
324 1 my $ret;
325 1 ▶ if ( @length_offset > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@length_offset > 1) { } 0 1 1
326 0 $ret = CORE::read( $fh, $_[0], $length, $offset );
327 }
328 else {
329 1 $ret = CORE::read( $fh, $_[0], $length );
330 }
331  
332 1 ▶ if ( !defined $ret ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ret) 1 0 1
333 1 $NS->__THROW( 'Read', length => $length );
334 }
335  
336 0 return $ret;
337 }
338  
339 sub sysread {
340 0 ▶ my ( $NS, $fh, @length_offset ) = ( shift, shift, @_[ 1 .. $#_ ] );
Subroutine sysread: not called CC=3 SCAR=24.8
Pod undocumented
341  
342 #https://github.com/pjcj/Devel--Cover/issues/125
343 #my ( $NS, $fh, $buffer_sr, @length_offset ) = ( shift, shift, \shift, @_ );
344  
345 0 my ( $length, $offset ) = @length_offset;
346  
347 0 local ( $!, $^E );
348  
349 #NOTE: Perl’s prototypes can throw errors on things like:
350 #(@length_offset > 1) ? $offset : ()
351 #...so the following writes out the two forms of sysread():
352  
353 0 my $ret;
354 0 ▶ if ( @length_offset > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@length_offset > 1) { } 0 0 0
355 0 $ret = CORE::sysread( $fh, $_[0], $length, $offset );
356 }
357 else {
358 0 $ret = CORE::sysread( $fh, $_[0], $length );
359 }
360  
361 0 ▶ if ( !defined $ret ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ret) 0 0 0
362 0 $NS->__THROW( 'Read', length => $length );
363 }
364  
365 0 return $ret;
366 }
367  
368 sub close {
369 6 ▶ my ( $NS, $fh ) = @_;
Subroutine close: called CC=3 SCAR=11.0
Pod undocumented
370  
371 6 local ( $!, $^E );
372 6 ▶ my $ok = ( $fh ? CORE::close($fh) : CORE::close() ) or do {
Branch: 2 branches
BranchTrueFalseTotal
my $ok = $fh ? CORE::close $fh : CORE::close() or do { $NS->__THROW("Close") } 2 4 6
$fh ? : 4 2 6
373 2 $NS->__THROW('Close');
374 };
375  
376 4 return $ok;
377 }
378  
379 #NOTE: See above about read/sysread; the same duplicated code problem
380 #applies to seek/sysseek.
381  
382 sub seek {
383 0 ▶ my ( $NS, $fh, $pos, $whence ) = @_;
Subroutine seek: not called CC=2 SCAR=17.9
Pod undocumented
384  
385 0 local ( $!, $^E );
386 0 ▶ my $ok = CORE::seek( $fh, $pos, $whence ) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::seek($fh, $pos, $whence) or do { $NS->__THROW("FileSeek", "whence", $whence, "position", $pos) } 0 0 0
387 0 $NS->__THROW( 'FileSeek', whence => $whence, position => $pos );
388 };
389  
390 0 return $ok;
391 }
392  
393 sub sysseek {
394 0 ▶ my ( $NS, $fh, $pos, $whence ) = @_;
Subroutine sysseek: not called CC=2 SCAR=17.9
Pod undocumented
395  
396 0 local ( $!, $^E );
397 0 ▶ my $ok = CORE::sysseek( $fh, $pos, $whence ) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::sysseek($fh, $pos, $whence) or do { $NS->__THROW("FileSeek", "whence", $whence, "position", $pos) } 0 0 0
398 0 $NS->__THROW( 'FileSeek', whence => $whence, position => $pos );
399 };
400  
401 0 return $ok;
402 }
403  
404 sub truncate {
405 0 ▶ my ( $NS, $fh_or_expr, $length ) = @_;
Subroutine truncate: not called CC=2 SCAR=17.9
Pod undocumented
406  
407 0 local ( $!, $^E );
408 0 ▶ my $ok = CORE::truncate( $fh_or_expr, $length ) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::truncate($fh_or_expr, $length) or do { $NS->__THROW("FileTruncate", "length", $length) } 0 0 0
409 0 $NS->__THROW( 'FileTruncate', length => $length );
410 };
411  
412 0 return $ok;
413 }
414  
415 #----------------------------------------------------------------------
416  
417 sub opendir {
418 1 ▶ my ( $NS, $dir ) = ( shift, @_[ 1 .. $#_ ] );
Subroutine opendir: called CC=2 SCAR=7.4
Pod undocumented
419  
420 #https://github.com/pjcj/Devel--Cover/issues/125
421 #my ( $NS, $dh_r, $dir ) = ( shift, \shift, shift );
422  
423 1 local ( $!, $^E );
424 1 ▶ my $ok = CORE::opendir( $_[0], $dir ) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::opendir($_[0], $dir) or do { $NS->__THROW("DirectoryOpen", "path", $dir) } 0 1 1
425 0 $NS->__THROW( 'DirectoryOpen', path => $dir );
426 };
427  
428 1 return $ok;
429 }
430  
431 sub rewinddir {
432 0 ▶ my ( $NS, $dh ) = @_;
Subroutine rewinddir: not called CC=2 SCAR=17.9
Pod undocumented
433  
434 0 local ( $!, $^E );
435 0 ▶ my $ok = CORE::rewinddir($dh) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::rewinddir $dh or do { $NS->__THROW("DirectoryRewind") } 0 0 0
436 0 $NS->__THROW('DirectoryRewind');
437 };
438  
439 0 return $ok;
440 }
441  
442 sub closedir {
443 2 ▶ my ( $NS, $dh ) = @_;
Subroutine closedir: called CC=2 SCAR=6.9
Pod undocumented
444  
445 2 local ( $!, $^E );
446 2 ▶ my $ok = CORE::closedir($dh) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::closedir $dh or do { $NS->__THROW("DirectoryClose") } 1 1 2
447 1 $NS->__THROW('DirectoryClose');
448 };
449  
450 1 return $ok;
451 }
452  
453 #----------------------------------------------------------------------
454  
455 #NOTE: To get stat(_), do stat(\*_).
456 sub stat {
457 7 ▶ my ( $NS, $path_or_fh ) = @_;
Subroutine stat: called CC=5 SCAR=20.9
Pod undocumented
458  
459 7 local ( $!, $^E );
460  
461 7 ▶ my $ret = wantarray ? [ CORE::stat($path_or_fh) ] : CORE::stat($path_or_fh);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 7 0 7
462  
463 7 ▶ if ($^E) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^E) 0 7 7
464 0 ▶ if ( __is_a_fh($path_or_fh) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (__is_a_fh($path_or_fh)) 0 0 0
465 0 $NS->__THROW('Stat');
466 }
467  
468 0 $NS->__THROW( 'Stat', path => $path_or_fh );
469 }
470  
471 7 ▶ return wantarray ? @$ret : $ret;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 7 0 7
472 }
473  
474 #NOTE: To get lstat(_), do lstat(\*_).
475 sub lstat {
476 0 ▶ my ( $NS, $path_or_fh ) = @_;
Subroutine lstat: not called CC=5 SCAR=34.0
Pod undocumented
477  
478 0 local ( $!, $^E );
479  
480 0 ▶ my $ret = wantarray ? [ CORE::lstat($path_or_fh) ] : CORE::lstat($path_or_fh);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
481  
482 0 ▶ if ($^E) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^E) 0 0 0
483 0 ▶ if ( __is_a_fh($path_or_fh) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (__is_a_fh($path_or_fh)) 0 0 0
484 0 $NS->__THROW('Stat');
485 }
486  
487 0 $NS->__THROW( 'Stat', path => $path_or_fh );
488 }
489  
490 0 ▶ return wantarray ? @$ret : $ret;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
491 }
492  
493 #----------------------------------------------------------------------
494  
495 sub fileno {
496 0 ▶ my ( $NS, $fh ) = @_;
Subroutine fileno: not called CC=2 SCAR=17.9
Pod undocumented
497  
498 0 local ( $!, $^E );
499 0 my $fileno = CORE::fileno($fh);
500  
501 0 ▶ if ( !defined $fileno ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fileno) 0 0 0
502 0 $NS->__THROW('Fileno');
503 }
504  
505 0 return $fileno;
506 }
507  
508 sub flock {
509 0 ▶ my ( $NS, $fh, $operation ) = @_;
Subroutine flock: not called CC=2 SCAR=17.9
Pod undocumented
510  
511 0 local ( $!, $^E );
512 0 ▶ my $ok = CORE::flock( $fh, $operation ) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::flock($fh, $operation) or do { $NS->__THROW("Flock", "operation", $operation) } 0 0 0
513 0 $NS->__THROW( 'Flock', operation => $operation );
514 };
515  
516 0 return $ok;
517 }
518  
519 #NOTE: This will only chmod() one thing at a time. It refuses to support
520 #multiple chmod() operations within the same call. This is in order to provide
521 #reliable error reporting.
522 #
523 #You, of course, can still do: IO::Die->chmod() for @items;
524 #
525 sub chmod {
526 5 ▶ my ( $NS, $mode, $target, @too_many_args ) = @_;
Subroutine chmod: called CC=4 SCAR=14.0
Pod documented
527  
528 #This is here because it’s impossible to do reliable error-checking when
529 #you operate on >1 filesystem node at once.
530 5 ▶ die "Only one path at a time!" if @too_many_args;
Branch: 1 branch
BranchTrueFalseTotal
if @too_many_args 1 4 5
531  
532 #NOTE: This breaks chmod’s error reporting when a file handle is passed in.
533 #cf. https://rt.perl.org/Ticket/Display.html?id=122703
534 4 local ( $!, $^E );
535  
536 4 ▶ my $ok = CORE::chmod( $mode, $target ) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::chmod($mode, $target) or do { if (__is_a_fh($target)) { $NS->__THROW("Chmod", "permissions", $mode); } ; $NS->__THROW("Chmod", "permissions", $mode, "path", $target) } 2 2 4
537 2 ▶ if ( __is_a_fh($target) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (__is_a_fh($target)) 0 2 2
538 0 $NS->__THROW( 'Chmod', permissions => $mode );
539 }
540  
541 2 $NS->__THROW( 'Chmod', permissions => $mode, path => $target );
542 };
543  
544 2 return $ok;
545 }
546  
547 #NOTE: This will only chown() one thing at a time. It refuses to support
548 #multiple chown() operations within the same call. This is in order to provide
549 #reliable error reporting.
550 #
551 #You, of course, can still do: IO::Die->chown() for @items;
552 #
553 sub chown {
554 5 ▶ my ( $NS, $uid, $gid, $target, @too_many_args ) = @_;
Subroutine chown: called CC=4 SCAR=14.0
Pod documented
555  
556 #This is here because it’s impossible to do reliable error-checking when
557 #you operate on >1 filesystem node at once.
558 5 ▶ die "Only one path at a time!" if @too_many_args;
Branch: 1 branch
BranchTrueFalseTotal
if @too_many_args 1 4 5
559  
560 4 local ( $!, $^E );
561  
562 4 ▶ my $ok = CORE::chown( $uid, $gid, $target ) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::chown($uid, $gid, $target) or do { if (__is_a_fh($target)) { $NS->__THROW("Chown", "uid", $uid, "gid", $gid); } ; $NS->__THROW("Chown", "uid", $uid, "gid", $gid, "path", $target) } 2 2 4
563 2 ▶ if ( __is_a_fh($target) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (__is_a_fh($target)) 0 2 2
564 0 $NS->__THROW( 'Chown', uid => $uid, gid => $gid );
565 }
566  
567 2 $NS->__THROW( 'Chown', uid => $uid, gid => $gid, path => $target );
568 };
569  
570 2 return $ok;
571 }
572  
573 sub link {
574 0 ▶ my ( $NS, $old, $new ) = @_;
Subroutine link: not called CC=2 SCAR=17.9
Pod undocumented
575  
576 0 local ( $!, $^E );
577 0 ▶ my $ok = CORE::link( $old, $new ) || do {
Condition0%0/3
CORE::link($old, $new) || do { $NS->__THROW('Link', 'oldpath', $old, 'newpath', $new) }
l!l&&r!l&&!r
000
MC/DC0%0/2
CORE::link($old, $new) || do { $NS->__THROW('Link', 'oldpath', $old, 'newpath', $new) }
CORE::link($old, $new) do { $NS->__THROW('Link', 'oldpath', $old, 'newpath', $new) }
Truth table0%0/3
A || B
A= CORE::link($old, $new)B= do { $NS->__THROW('Link', 'oldpath', $old, 'newpath', $new) }
ABresult
1X1
011
000
578 0 $NS->__THROW( 'Link', oldpath => $old, newpath => $new );
579 };
580  
581 0 return $ok;
582 }
583  
584 sub symlink {
585 0 ▶ my ( $NS, $old, $new ) = @_;
Subroutine symlink: not called CC=2 SCAR=17.9
Pod undocumented
586  
587 0 local ( $!, $^E );
588 0 ▶ my $ok = CORE::symlink( $old, $new ) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::symlink($old, $new) or do { $NS->__THROW("SymlinkCreate", "oldpath", $old, "newpath", $new) } 0 0 0
589 0 $NS->__THROW( 'SymlinkCreate', oldpath => $old, newpath => $new );
590 };
591  
592 0 return $ok;
593 }
594  
595 sub readlink {
596 0 ▶ my $NS = shift;
Subroutine readlink: not called CC=3 SCAR=24.8
Pod undocumented
597 0 ▶ my $path = @_ ? shift : $_;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
598  
599 0 local ( $!, $^E );
600 0 ▶ my $ok = CORE::readlink($path) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::readlink $path or do { $NS->__THROW("SymlinkRead", "path", $path) } 0 0 0
601 0 $NS->__THROW( 'SymlinkRead', path => $path );
602 };
603  
604 0 return $ok;
605 }
606  
607 sub rename {
608 0 ▶ my ( $NS, $old, $new ) = @_;
Subroutine rename: not called CC=2 SCAR=17.9
Pod undocumented
609  
610 0 local ( $!, $^E );
611 0 ▶ my $ok = CORE::rename( $old, $new ) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::rename($old, $new) or do { $NS->__THROW("Rename", "oldpath", $old, "newpath", $new) } 0 0 0
612 0 $NS->__THROW( 'Rename', oldpath => $old, newpath => $new );
613 };
614  
615 0 return $ok;
616 }
617  
618 #NOTE: This will only unlink() one file at a time. It refuses to support
619 #multiple unlink() operations within the same call. This is in order to provide
620 #reliable error reporting.
621 #
622 #You, of course, can still do: IO::Die->unlink() for @files;
623 #
624 sub unlink {
625 0 ▶ my ( $NS, @paths ) = @_;
Subroutine unlink: not called CC=4 SCAR=30.0
Pod documented
626  
627 #This is here because it’s impossible to do reliable error-checking when
628 #you operate on >1 filesystem node at once.
629 0 ▶ die "Only one path at a time!" if @paths > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @paths > 1 0 0 0
630  
631 0 ▶ if ( !@paths ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@paths) 0 0 0
632 0 @paths = ($_);
633 }
634  
635 0 local ( $!, $^E );
636 0 ▶ my $ok = CORE::unlink(@paths) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::unlink(@paths) or do { $NS->__THROW("Unlink", "path", $paths[0]) } 0 0 0
637 0 $NS->__THROW( 'Unlink', path => $paths[0] );
638 };
639  
640 0 return $ok;
641 }
642  
643 sub mkdir {
644 0 ▶ my ( $NS, @args ) = @_;
Subroutine mkdir: not called CC=4 SCAR=30.0
Pod undocumented
645  
646 0 local ( $!, $^E );
647  
648 0 my $ret;
649 0 ▶ if ( @args > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args > 1) { } 0 0 0
650 0 $ret = CORE::mkdir $args[0], $args[1];
651 }
652 else {
653 0 ▶ if ( !@args ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@args) 0 0 0
654 0 @args = ($_);
655 }
656  
657 0 $ret = CORE::mkdir( $args[0] );
658 }
659  
660 0 ▶ if ( !$ret ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ret) 0 0 0
661 0 $NS->__THROW( 'DirectoryCreate', path => $args[0], mask => $args[1] );
662 }
663  
664 0 return $ret;
665 }
666  
667 sub rmdir {
668 0 ▶ my ( $NS, @args ) = @_;
Subroutine rmdir: not called CC=4 SCAR=30.0
Pod undocumented
669  
670 #Perl's rmdir() doesn’t actually allow batching like this,
671 #but we might as well prevent anyone from trying.
672 0 ▶ die "Only one path at a time!" if @args > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args > 1 0 0 0
673  
674 0 ▶ if ( !@args ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@args) 0 0 0
675 0 @args = ($_);
676 }
677  
678 0 local ( $!, $^E );
679 0 ▶ my $ok = CORE::rmdir( $args[0] ) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::rmdir $args[0] or do { $NS->__THROW("DirectoryDelete", "path", $args[0]) } 0 0 0
680 0 $NS->__THROW( 'DirectoryDelete', path => $args[0] );
681 };
682  
683 0 return $ok;
684 }
685  
686 sub fork {
687 0 ▶ my ($NS) = @_;
Subroutine fork: not called CC=2 SCAR=17.9
Pod documented
688  
689 0 my $pid = fork;
690  
691 0 ▶ $NS->__THROW('Fork') if !defined $pid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pid 0 0 0
692  
693 0 return $pid;
694 }
695  
696 sub kill {
697 0 ▶ my ( $NS, $sig, @list ) = @_;
Subroutine kill: not called CC=3 SCAR=24.8
Pod documented
698  
699 0 ▶ die "Only 1 process!" if @list > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @list > 1 0 0 0
700  
701 0 local ( $!, $^E );
702 0 my $ret = CORE::kill( $sig, @list );
703 0 ▶ if ($!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($!) 0 0 0
704 0 $NS->__THROW( 'Kill', signal => $sig, process => $list[0] );
705 }
706  
707 0 return $ret;
708 }
709  
710 sub exec {
711 1 ▶ my ( $NS, $progname, @args ) = @_;
Subroutine exec: called CC=2 SCAR=10.1
Pod documented
712  
713 1 ▶ my $ok = CORE::exec {$progname} $progname, @args or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::exec({$progname;} $progname, @args) or do { $NS->__THROW("Exec", "program", $progname, "arguments", \@args) } 0 0 0
714 0 $NS->__THROW( 'Exec', program => $progname, arguments => \@args );
715 };
716  
717 0 return $ok;
718 }
719  
720 sub pipe {
721 0 ▶ my ($NS) = (shift);
Subroutine pipe: not called CC=2 SCAR=17.9
Pod undocumented
722  
723 #https://github.com/pjcj/Devel--Cover/issues/125
724 #my ( $NS, $read_r, $write_r ) = ( shift, \shift, \shift );
725  
726 0 local ( $!, $^E );
727 0 ▶ my $ok = CORE::pipe( $_[0], $_[1] ) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::pipe($_[0], $_[1]) or do { $NS->__THROW("Pipe") } 0 0 0
728 0 $NS->__THROW('Pipe');
729 };
730  
731 0 return $ok;
732 }
733  
734 2 my $DEFAULT_BINMODE_LAYER = ':raw'; #cf. perldoc -f binmode
735  
736 sub binmode {
737 2 ▶ my ( $NS, $fh_r, $layer ) = @_;
Subroutine binmode: called CC=3 SCAR=11.0
Pod undocumented
738  
739 2 ▶ if ( !defined $layer ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $layer) 2 0 2
740 2 $layer = $DEFAULT_BINMODE_LAYER;
741 }
742  
743 2 local ( $!, $^E );
744 2 ▶ my $ok = CORE::binmode( $fh_r, $layer ) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::binmode($fh_r, $layer) or do { $NS->__THROW("Binmode", "layer", $layer) } 1 1 2
745 1 $NS->__THROW( 'Binmode', layer => $layer );
746 };
747  
748 1 return $ok;
749 }
750  
751 #NOTE: This will only utime() one thing at a time. It refuses to support
752 #multiple utime() operations within the same call. This is in order to provide
753 #reliable error reporting.
754 #
755 #You, of course, can still do: IO::Die->utime() for @items;
756 #
757 sub utime {
758 0 ▶ my ( $NS, $atime, $mtime, $target, @too_many_args ) = @_;
Subroutine utime: not called CC=4 SCAR=30.0
Pod documented
759  
760 0 ▶ die "Only one utime() at a time!" if @too_many_args;
Branch: 1 branch
BranchTrueFalseTotal
if @too_many_args 0 0 0
761  
762 0 local ( $!, $^E );
763 0 ▶ my $ok = CORE::utime( $atime, $mtime, $target ) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::utime($atime, $mtime, $target) or do { if (__is_a_fh($target)) { $NS->__THROW("Utime", "atime", $atime, "mtime", $mtime, "path", $target); } ; $NS->__THROW("Utime", "atime", $atime, "mtime", $mtime) } 0 0 0
764 0 ▶ if ( __is_a_fh($target) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (__is_a_fh($target)) 0 0 0
765 0 $NS->__THROW( 'Utime', atime => $atime, mtime => $mtime, path => $target );
766 }
767  
768 0 $NS->__THROW( 'Utime', atime => $atime, mtime => $mtime );
769 };
770  
771 0 return $ok;
772 }
773  
774 sub fcntl {
775 0 ▶ my ( $NS, $fh, $func, $scalar ) = @_;
Subroutine fcntl: not called CC=2 SCAR=17.9
Pod undocumented
776  
777 0 local ( $!, $^E );
778 0 ▶ my $ok = CORE::fcntl( $fh, $func, $scalar ) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::fcntl($fh, $func, $scalar) or do { $NS->__THROW("Fcntl", "function", $func, "scalar", $scalar) } 0 0 0
779 0 $NS->__THROW( 'Fcntl', function => $func, scalar => $scalar );
780 };
781  
782 0 return $ok;
783 }
784  
785 sub select {
786 0 ▶ my ( $NS, $timeout ) = ( shift, $_[3] );
Subroutine select: not called CC=4 SCAR=30.0
Pod documented
787  
788 #Perl::Critic says not to use one-arg select() anyway.
789 0 ▶ die "Need four args!" if @_ < 4;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 4 0 0 0
790  
791 0 local ( $!, $^E );
792 0 my ( $nfound, $timeleft ) = CORE::select( $_[0], $_[1], $_[2], $timeout );
793  
794 0 ▶ if ($^E) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^E) 0 0 0
795 0 $NS->__THROW('Select');
796 }
797  
798 0 ▶ return wantarray ? ( $nfound, $timeleft ) : $nfound;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
799 }
800  
801 #----------------------------------------------------------------------
802  
803 sub socket {
804 0 ▶ my ( $NS, $domain, $type, $protocol ) = ( shift, @_[ 1 .. $#_ ] );
Subroutine socket: not called CC=2 SCAR=17.9
Pod undocumented
805  
806 #https://github.com/pjcj/Devel--Cover/issues/125
807 #my ( $NS, $socket_r, $domain, $type, $protocol ) = ( shift, \shift, shift, shift, shift );
808  
809 0 local ( $!, $^E );
810 0 ▶ my $ok = CORE::socket( $_[0], $domain, $type, $protocol ) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::socket($_[0], $domain, $type, $protocol) or do { $NS->__THROW("SocketOpen", "domain", $domain, "type", $type, "protocol", $protocol) } 0 0 0
811 0 $NS->__THROW( 'SocketOpen', domain => $domain, type => $type, protocol => $protocol );
812 };
813  
814 0 return $ok;
815 }
816  
817 sub socketpair {
818 0 ▶ my ( $NS, $domain, $type, $protocol ) = ( shift, @_[ 2 .. $#_ ] );
Subroutine socketpair: not called CC=2 SCAR=17.9
Pod undocumented
819  
820 #https://github.com/pjcj/Devel--Cover/issues/125
821 #my ( $NS, $socket1_r, $socket2_r, $domain, $type, $protocol ) = ( \shift, \shift, shift, shift );
822  
823 0 local ( $!, $^E );
824 0 ▶ my $ok = CORE::socketpair( $_[0], $_[1], $domain, $type, $protocol ) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::socketpair($_[0], $_[1], $domain, $type, $protocol) or do { $NS->__THROW("SocketPair", "domain", $domain, "type", $type, "protocol", $protocol) } 0 0 0
825 0 $NS->__THROW( 'SocketPair', domain => $domain, type => $type, protocol => $protocol );
826 };
827  
828 0 return $ok;
829 }
830  
831 sub bind {
832 0 ▶ my ( $NS, $socket, $name ) = @_;
Subroutine bind: not called CC=2 SCAR=17.9
Pod undocumented
833  
834 0 local ( $!, $^E );
835 0 ▶ my $ok = CORE::bind( $socket, $name ) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::bind($socket, $name) or do { $NS->__THROW("SocketBind", "name", $name) } 0 0 0
836 0 $NS->__THROW( 'SocketBind', name => $name );
837 };
838  
839 0 return $ok;
840 }
841  
842 sub connect {
843 0 ▶ my ( $NS, $socket, $name ) = @_;
Subroutine connect: not called CC=2 SCAR=17.9
Pod undocumented
844  
845 0 local ( $!, $^E );
846 0 ▶ my $ok = CORE::connect( $socket, $name ) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::connect($socket, $name) or do { $NS->__THROW("SocketConnect", "name", $name) } 0 0 0
847 0 $NS->__THROW( 'SocketConnect', name => $name );
848 };
849  
850 0 return $ok;
851 }
852  
853 sub accept {
854 0 ▶ my ( $NS, $generic_socket ) = @_[ 0, 2 ];
Subroutine accept: not called CC=2 SCAR=17.9
Pod undocumented
855  
856 #https://github.com/pjcj/Devel--Cover/issues/125
857 #my ( $NS, $new_socket, $generic_socket ) = @_;
858  
859 0 local ( $!, $^E );
860 0 ▶ my $ok = CORE::accept( $_[1], $generic_socket ) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::accept($_[1], $generic_socket) or do { $NS->__THROW("SocketAccept") } 0 0 0
861 0 $NS->__THROW('SocketAccept');
862 };
863  
864 0 return $ok;
865 }
866  
867 sub getsockopt {
868 0 ▶ my ( $NS, $socket, $level, $optname ) = @_;
Subroutine getsockopt: not called CC=2 SCAR=17.9
Pod undocumented
869  
870 0 local ( $!, $^E );
871 0 my $res = CORE::getsockopt( $socket, $level, $optname );
872 0 ▶ if ( !defined $res ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res) 0 0 0
873 0 $NS->__THROW( 'SocketGetOpt', level => $level, optname => $optname );
874 }
875  
876 0 return $res;
877 }
878  
879 sub setsockopt {
880 0 ▶ my ( $NS, $socket, $level, $optname, $optval ) = @_;
Subroutine setsockopt: not called CC=2 SCAR=17.9
Pod undocumented
881  
882 0 local ( $!, $^E );
883 0 my $res = CORE::setsockopt( $socket, $level, $optname, $optval );
884 0 ▶ if ( !defined $res ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res) 0 0 0
885 0 $NS->__THROW( 'SocketSetOpt', level => $level, optname => $optname, optval => $optval );
886 }
887  
888 0 return $res;
889 }
890  
891 sub listen {
892 0 ▶ my ( $NS, $socket, $queuesize ) = @_;
Subroutine listen: not called CC=2 SCAR=17.9
Pod undocumented
893  
894 0 local ( $!, $^E );
895 0 ▶ my $ok = CORE::listen( $socket, $queuesize ) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = CORE::listen($socket, $queuesize) or do { $NS->__THROW("SocketListen", "queuesize", $queuesize) } 0 0 0
896 0 $NS->__THROW( 'SocketListen', queuesize => $queuesize );
897 };
898  
899 0 return $ok;
900 }
901  
902 sub recv {
903 0 ▶ my ( $NS, $socket, $length, $flags ) = ( shift, shift, @_[ 1 .. $#_ ] );
Subroutine recv: not called CC=2 SCAR=17.9
Pod undocumented
904  
905 #https://github.com/pjcj/Devel--Cover/issues/125
906 #my ( $NS, $socket, $scalar_r, $length, $flags ) = ( shift, shift, \shift, @_ );
907  
908 0 local ( $!, $^E );
909 0 my $res = CORE::recv( $socket, $_[0], $length, $flags );
910 0 ▶ if ( !defined $res ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res) 0 0 0
911 0 $NS->__THROW( 'SocketReceive', length => $length, flags => $flags );
912 }
913  
914 0 return $res;
915 }
916  
917 sub send {
918 0 ▶ my ( $NS, $socket, $flags, $to ) = ( shift, shift, @_[ 1 .. $#_ ] );
Subroutine send: not called CC=3 SCAR=24.8
Pod undocumented
919  
920 #https://github.com/pjcj/Devel--Cover/issues/125
921 #my ( $NS, $socket, $msg_r, $flags, $to ) = ( shift, shift, \shift, @_ );
922  
923 0 local ( $!, $^E );
924 0 my $res;
925 0 ▶ if ( defined $to ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $to) { } 0 0 0
926 0 $res = CORE::send( $socket, $_[0], $flags, $to );
927 }
928 else {
929 0 $res = CORE::send( $socket, $_[0], $flags );
930 }
931  
932 0 ▶ if ( !defined $res ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res) 0 0 0
933 0 $NS->__THROW( 'SocketSend', length => length( $_[0] ), flags => $flags );
934 }
935  
936 0 return $res;
937 }
938  
939 sub shutdown {
940 0 ▶ my ( $NS, $socket, $how ) = @_;
Subroutine shutdown: not called CC=3 SCAR=24.8
Pod undocumented
941  
942 0 local ( $!, $^E );
943  
944 0 my $res = CORE::shutdown( $socket, $how );
945 0 ▶ if ( !$res ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res) 0 0 0
946 0 ▶ die "Invalid filehandle!" if !defined $res;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $res 0 0 0
947 0 $NS->__THROW( 'SocketShutdown', how => $how );
948 }
949  
950 0 return $res;
951 }
952  
953 #----------------------------------------------------------------------
954 # CONVENIENCE
955 #
956  
957 2 my $Fcntl_SEEK_CUR = 1;
958  
959 #Note that, since we die() on error, this does NOT return "0 but true"
960 #as sysseek() does; instead it returns just a plain 0.
961 sub systell {
962 0 ▶ my ( $NS, $fh ) = @_;
Subroutine systell: not called CC=1 SCAR=6.9
Pod documented
963  
964 #cf. perldoc -f tell
965 0 return 0 + $NS->sysseek( $fh, 0, $Fcntl_SEEK_CUR );
966 }
967  
968 #----------------------------------------------------------------------
969  
970 __END__
↑ Summary Build »