blib/lib/IO/AIO/Util.pm

filter: Statementstmt 100% 47 / 47 Branchbran 100% 10 / 10 Conditioncond 73.6% 14 / 19 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 87.2% 82 / 94 SCAR 24.0
CC
11
Cov
93%
__ANON__
7.2
__ANON__
5.0
aio_mkpath
1.0
CRAP 11.0
↑ Summary
1 package IO::AIO::Util;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use IO::AIO 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 use File::Spec::Functions qw(
9 canonpath catpath catdir splitdir splitpath updir
10 2 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 our $VERSION = '0.09';
14 2 $VERSION = eval $VERSION;
15  
16 2 our @EXPORT_OK = qw(aio_mkpath aio_mktree);
17  
18 sub aio_mkpath {
19 7 ▶ my ($path, $mode, $cb) = @_;
Subroutine aio_mkpath: called CC=1 SCAR=0.0
Pod documented
20  
21 7 my $pri = aioreq_pri;
22 7 my $grp = aio_group $cb;
23  
24 # Default is success.
25 7 local $!;
26 7 $grp->result(0);
27  
28 # Clean up the path.
29 7 $path = canonpath($path);
30  
31 7 my ($vol, $dir, undef) = splitpath($path, 1);
32 7 my @dir = splitdir($dir);
33 7 my $idx = 0;
34  
35 7 my $sub; $sub = sub {
36 31 ▶ for (; $idx < @dir; $idx++) {
Subroutine __ANON__: called CC=5 SCAR=16.2
Branch: 1 branch
BranchTrueFalseTotal
if ($idx < @dir) 35 3 38
37 # Root and parent directories are assumed to always exist.
38 35 ▶ last if '' ne $dir[$idx] and updir ne $dir[$idx];
Branch: 1 branch
BranchTrueFalseTotal
if "" ne $dir[$idx] and ".." ne $dir[$idx] 28 7 35
Condition66%2/3
"" ne $dir[$idx] and ".." ne $dir[$idx]
!ll&&!rl&&r
7028
MC/DC50%1/2
"" ne $dir[$idx] and ".." ne $dir[$idx]
"" ne $dir[$idx] ".." ne $dir[$idx]
Truth table66%2/3
A and B
A= "" ne $dir[$idx]B= ".." ne $dir[$idx]
ABresult
0X0
100
111
39 }
40 31 ▶ return $grp if @dir <= $idx;
Branch: 1 branch
BranchTrueFalseTotal
if @dir <= $idx 3 28 31
41  
42 28 my $path = catpath($vol, catdir(@dir[0 .. $idx]), '');
43  
44 28 aioreq_pri $pri;
45 add $grp aio_mkdir $path, $mode, sub {
46 28 ▶ $idx++ and return $sub->() unless $_[0];
Subroutine __ANON__: called CC=7 SCAR=19.7
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 5 23 28
Condition60%3/5
$_[0] || $idx++ && (return &$sub())
l!l&&r!l&&!r
2350
$idx++ and return &$sub()
!ll
05
MC/DC0%0/2
$_[0] || $idx++ && (return &$sub())
$_[0] $idx++
Truth table66%2/3
A || B
A= $_[0]B= $idx++
ABresult
1X1
011
000
47  
48 # Ignore "file exists" errors unless it is the last component,
49 # then stat it to ensure it is a directory. This matches
50 # the behaviour of `mkdir -p` from GNU coreutils.
51 23 ▶ $idx++ and return $sub->() if &POSIX::EEXIST == $!
Branch: 1 branch
BranchTrueFalseTotal
if &POSIX::EEXIST == $! and not $idx == $#dir && !(-d $path) 19 4 23
Condition81%9/11
&POSIX::EEXIST == $! && !($idx == $#dir && !(-d $path)) && ($idx++ && (return &$sub()))
!ll&&!rl&&r
4190
&POSIX::EEXIST == $! and not $idx == $#dir && !(-d $path)
!ll&&!rl&&r
3119
$idx == $#dir && !(-d $path)
!ll&&!rl&&r
1811
$idx++ and return &$sub()
!ll
019
MC/DC0%0/4
&POSIX::EEXIST == $! && !($idx == $#dir && !(-d $path)) && ($idx++ && (return &$sub()))
&POSIX::EEXIST == $! $idx == $#dir !(-d $path) $idx++
Truth table33%2/6
A and not(B && not(C)) && D
A= &POSIX::EEXIST == $!B= $idx == $#dirC= !(-d $path)D= $idx++
ABCDresult
0XXX0
111X0
10X00
11000
10X11
11011
52 and not ($idx == $#dir and not -d $path);
53  
54 4 $grp->cancel_subs;
55 4 $grp->errno($!);
56 4 $grp->result($_[0]);
57 4 return $grp;
58 28 };
59 7 };
60  
61 7 return $sub->();
62 }
63  
64 2 *aio_mktree = \&aio_mkpath;
65  
66  
67 2 1;
68  
69 __END__
↑ Summary