| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package IO::AIO::Util; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 2 |  |  | 2 |  | 139260 | use strict; | 
|  | 2 |  |  |  |  | 14 |  | 
|  | 2 |  |  |  |  | 61 |  | 
| 4 | 2 |  |  | 2 |  | 10 | use warnings; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 60 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 2 |  |  | 2 |  | 10 | use Exporter qw(import); | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 56 |  | 
| 7 | 2 |  |  | 2 |  | 776 | use IO::AIO 2; | 
|  | 2 |  |  |  |  | 5678 |  | 
|  | 2 |  |  |  |  | 373 |  | 
| 8 | 2 |  |  |  |  | 143 | use File::Spec::Functions qw( | 
| 9 |  |  |  |  |  |  | canonpath catpath catdir splitdir splitpath updir | 
| 10 | 2 |  |  | 2 |  | 952 | ); | 
|  | 2 |  |  |  |  | 1644 |  | 
| 11 | 2 |  |  | 2 |  | 988 | use POSIX (); | 
|  | 2 |  |  |  |  | 12471 |  | 
|  | 2 |  |  |  |  | 744 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | our $VERSION = '0.11'; | 
| 14 |  |  |  |  |  |  | $VERSION = eval $VERSION; | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | our @EXPORT_OK = qw(aio_mkpath aio_mktree); | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | sub aio_mkpath { | 
| 19 | 4 |  |  | 4 | 1 | 5138 | my ($path, $mode, $cb) = @_; | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 4 |  |  |  |  | 13 | my $pri = aioreq_pri; | 
| 22 | 4 |  |  |  |  | 38 | my $grp = aio_group $cb; | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | # Default is success. | 
| 25 | 4 |  |  |  |  | 22 | local $!; | 
| 26 | 4 |  |  |  |  | 17 | $grp->result(0); | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | # Clean up the path. | 
| 29 | 4 |  |  |  |  | 14 | $path = canonpath($path); | 
| 30 |  |  |  |  |  |  |  | 
| 31 | 4 |  |  |  |  | 14 | my ($vol, $dir, undef) = splitpath($path, 1); | 
| 32 | 4 |  |  |  |  | 37 | my @dir = splitdir($dir); | 
| 33 | 4 |  |  |  |  | 27 | my $idx = 0; | 
| 34 |  |  |  |  |  |  |  | 
| 35 | 4 |  |  |  |  | 6 | my $sub; $sub = sub { | 
| 36 | 17 |  |  | 17 |  | 48 | for (; $idx < @dir; $idx++) { | 
| 37 |  |  |  |  |  |  | # Root and parent directories are assumed to always exist. | 
| 38 | 19 | 100 | 66 |  |  | 87 | last if '' ne $dir[$idx] and updir ne $dir[$idx]; | 
| 39 |  |  |  |  |  |  | } | 
| 40 | 17 | 100 |  |  |  | 50 | return $grp if @dir <= $idx; | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 15 |  |  |  |  | 94 | my $path = catpath($vol, catdir(@dir[0 .. $idx]), ''); | 
| 43 |  |  |  |  |  |  |  | 
| 44 | 15 |  |  |  |  | 129 | aioreq_pri $pri; | 
| 45 |  |  |  |  |  |  | add $grp aio_mkdir $path, $mode, sub { | 
| 46 | 15 | 100 | 50 |  |  | 1433 | $idx++ and return $sub->() unless $_[0]; | 
| 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 | 13 | 100 | 50 |  |  | 174 | $idx++ and return $sub->() if &POSIX::EEXIST == $! | 
|  |  |  | 100 |  |  |  |  | 
|  |  |  | 100 |  |  |  |  | 
| 52 |  |  |  |  |  |  | and not ($idx == $#dir and not -d $path); | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 2 |  |  |  |  | 10 | $grp->cancel_subs; | 
| 55 | 2 |  |  |  |  | 8 | $grp->errno($!); | 
| 56 | 2 |  |  |  |  | 8 | $grp->result($_[0]); | 
| 57 | 2 |  |  |  |  | 8 | return $grp; | 
| 58 | 15 |  |  |  |  | 738 | }; | 
| 59 | 4 |  |  |  |  | 21 | }; | 
| 60 |  |  |  |  |  |  |  | 
| 61 | 4 |  |  |  |  | 19 | return $sub->(); | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | *aio_mktree = \&aio_mkpath; | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | 1; | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | __END__ |