lib/POSIX/Util.pm

filter: Statementstmt 81.4% 35 / 43 Branchbran 35.0% 7 / 20 Conditioncond 30.0% 3 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 87.5% 7 / 8 Podpod 100% 2 / 2 totaltotal 61.3% 54 / 88 CC 15 SCAR 28.6
CC
15
Cov
62%
writefd_all
42.0
readfd_all
12.7
BEGIN
1.0
CRAP 17.5
↑ Summary
1 # Copyrights 2012 by [Mark Overmeer].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.00.
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 package POSIX::Util;
9 2 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 $VERSION = '0.10';
11  
12 2 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use POSIX::1003::Pathconf qw/_PC_REC_INCR_XFER_SIZE/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use POSIX::1003::FdIO qw/writefd readfd BUFSIZ SSIZE_MAX/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 my @fdio = qw/readfd_all writefd_all/;
18 2 my @functions = (@fdio);
19  
20 # need to extract the POSIX::1003 exporter
21 2 our @EXPORT = @functions;
22  
23 2 our %EXPORT_TAGS =
24 ( functions => \@functions
25 , fdio => \@fdio
26 );
27  
28  
29 sub writefd_all($$;$)
30 0 ▶{ my ($to, $data, $do_close) = @_;
Subroutine writefd_all: not called CC=6 SCAR=37.4
Pod documented
31 0 my $size = length $data;
32  
33 0 ▶ while(my $l = length $data)
Branch: 1 branch
BranchTrueFalseTotal
if (my $l = length $data) 0 0 0
34 0 { my $written = writefd $to, $data, $l;
35 0 ▶ defined $written or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $written or return 0 0 0
36  
37 0 ▶ last if $l eq $written; # normal case
Branch: 1 branch
BranchTrueFalseTotal
if $l eq $written 0 0 0
38 0 substr($data, 0, $written) = '';
39 }
40  
41 0 ▶ $do_close && !defined closefd($to) ? undef : $size;
Branch: 1 branch
BranchTrueFalseTotal
$do_close && !defined(closefd($to)) ? : 0 0 0
Condition0%0/3
$do_close and not defined closefd($to)
!ll&&!rl&&r
000
MC/DC0%0/2
$do_close and not defined closefd($to)
$do_close not defined closefd($to)
Truth table0%0/3
A and not(B)
A= $do_closeB= not defined closefd($to)
ABresult
0X0
100
111
42 }
43  
44  
45 sub readfd_all($;$$)
46 1 ▶{ my ($in, $size, $do_close) = @_;
Subroutine readfd_all: called CC=10 SCAR=25.4
Pod documented
47 1 ▶ defined $size or $size = SSIZE_MAX;
Branch: 1 branch
BranchTrueFalseTotal
defined $size or $size = '9223372036854775807' 0 1 1
48 1 my ($data, $buf) = ('', '');
49  
50 1 ▶ my $block = _PC_REC_INCR_XFER_SIZE($in) || BUFSIZ || 4096;
Condition50%2/4
&_PC_REC_INCR_XFER_SIZE($in) || 8192 || 4096
l!l
10
&_PC_REC_INCR_XFER_SIZE($in) or 8192
l!l
01
MC/DC0%0/1
&_PC_REC_INCR_XFER_SIZE($in) || 8192 || 4096
&_PC_REC_INCR_XFER_SIZE($in)
Truth table50%1/2
A
A= &_PC_REC_INCR_XFER_SIZE($in)
Aresult
11
00
51  
52 # we should probably align the $in-fd onto a block size in the
53 # first read for optimal performance under all cirmstances...
54  
55 1 my $bytes;
56 1 ▶ while($bytes = readfd $in, $buf, ($block < $size ? $block : $size))
Branch: 2 branches
BranchTrueFalseTotal
if ($bytes = &readfd($in, $buf, scalar($block < $size ? $block : $size))) 2 0 2
$block < $size ? : 2 0 2
57 2 ▶ { last if $bytes==0; # readfd will return "0 but true"
Branch: 1 branch
BranchTrueFalseTotal
if $bytes == 0 1 1 2
58 1 $data .= $buf;
59 1 $size -= $bytes;
60 }
61 1 ▶ defined $bytes or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $bytes or return 1 0 1
62  
63 1 ▶ $do_close && !defined closefd($in) ? undef : $data;
Branch: 1 branch
BranchTrueFalseTotal
$do_close && !defined(closefd($in)) ? : 0 1 1
Condition33%1/3
$do_close and not defined closefd($in)
!ll&&!rl&&r
100
MC/DC0%0/2
$do_close and not defined closefd($in)
$do_close not defined closefd($in)
Truth table33%1/3
A and not(B)
A= $do_closeB= not defined closefd($in)
ABresult
0X0
100
111
64 }
65  
66 2 1;
↑ Summary