| 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
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
"" ne $dir[$idx] and ".." ne $dir[$idx]
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]
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 31 | ▶ | return $grp if @dir <= $idx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition60%3/5
$_[0] || $idx++ && (return &$sub())
$idx++ and return &$sub()
MC/DC0%0/2
$_[0] || $idx++ && (return &$sub())
$_[0]
$idx++
Truth table66%2/3
A || B
A= $_[0]B= $idx++
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition81%9/11
&POSIX::EEXIST == $! && !($idx == $#dir && !(-d $path)) && ($idx++ && (return &$sub()))
&POSIX::EEXIST == $! and not $idx == $#dir && !(-d $path)
$idx == $#dir && !(-d $path)
$idx++ and return &$sub()
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++
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||