| 1 | # | ||||||||||||||||||
| 2 | # Copyright (c) 2014-2015 Christian Jaeger, copying@christianjaeger.ch | ||||||||||||||||||
| 3 | # | ||||||||||||||||||
| 4 | # This is free software, offered under either the same terms as perl 5 | ||||||||||||||||||
| 5 | # or the terms of the Artistic License version 2 or the terms of the | ||||||||||||||||||
| 6 | # MIT License (Expat version). See the file COPYING.md that came | ||||||||||||||||||
| 7 | # bundled with this file. | ||||||||||||||||||
| 8 | # | ||||||||||||||||||
| 9 | |||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||
| 11 | |||||||||||||||||||
| 12 | FunctionalPerl::Htmlgen::FileUtil | ||||||||||||||||||
| 13 | |||||||||||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||||||||||
| 15 | |||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||
| 17 | |||||||||||||||||||
| 18 | |||||||||||||||||||
| 19 | =head1 NOTE | ||||||||||||||||||
| 20 | |||||||||||||||||||
| 21 | This is alpha software! Read the status section in the package README | ||||||||||||||||||
| 22 | or on the L<website|http://functional-perl.org/>. | ||||||||||||||||||
| 23 | |||||||||||||||||||
| 24 | =cut | ||||||||||||||||||
| 25 | |||||||||||||||||||
| 26 | package FunctionalPerl::Htmlgen::FileUtil; | ||||||||||||||||||
| 27 | 2 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 28 | 2 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 29 | 2 | ▶ | use warnings FATAL => 'uninitialized'; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 30 | 2 | ▶ | use experimental "signatures"; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 31 | |||||||||||||||||||
| 32 | 2 | ▶ | use Exporter "import"; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 33 | |||||||||||||||||||
| 34 | 2 | our @EXPORT = qw(); | |||||||||||||||||
| 35 | 2 | our @EXPORT_OK = qw(existingpath_or create_parent_dirs); | |||||||||||||||||
| 36 | 2 | our %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]); | |||||||||||||||||
| 37 | |||||||||||||||||||
| 38 | # lib? | ||||||||||||||||||
| 39 | 0 | ▶ | sub existingpath_or(@paths) { | ||||||||||||||||
|
Subroutine
existingpath_or: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||
| 40 | 0 | for (@paths) { | |||||||||||||||||
| 41 | 0 | ▶ | return $_ if -e $_ | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 42 | } | ||||||||||||||||||
| 43 | 0 | die "none of the paths exist: @paths"; | |||||||||||||||||
| 44 | } | ||||||||||||||||||
| 45 | |||||||||||||||||||
| 46 | 2 | ▶ | use POSIX qw(EEXIST ENOENT); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 47 | 2 | ▶ | use Chj::xperlfunc qw(dirname xmkdir); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 48 | |||||||||||||||||||
| 49 | # XX how is this different from xmkdir_p ? | ||||||||||||||||||
| 50 | 0 | ▶ | sub create_parent_dirs ($path0, $path0_to_outpath) { | ||||||||||||||||
|
Subroutine
create_parent_dirs: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||
| 51 | 0 | $path0 = dirname $path0; | |||||||||||||||||
| 52 | 0 | my $outpath = &$path0_to_outpath($path0); | |||||||||||||||||
| 53 | 0 | ▶ | if (mkdir $outpath) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 54 | |||||||||||||||||||
| 55 | # ok, return | ||||||||||||||||||
| 56 | } elsif ($! == EEXIST) { | ||||||||||||||||||
| 57 | |||||||||||||||||||
| 58 | # ok, return | ||||||||||||||||||
| 59 | } elsif ($! == ENOENT) { | ||||||||||||||||||
| 60 | 0 | create_parent_dirs($path0, $path0_to_outpath); | |||||||||||||||||
| 61 | 0 | xmkdir $outpath; | |||||||||||||||||
| 62 | } else { | ||||||||||||||||||
| 63 | 0 | die "mkdir '$outpath': $!"; | |||||||||||||||||
| 64 | } | ||||||||||||||||||
| 65 | } | ||||||||||||||||||
| 66 | |||||||||||||||||||
| 67 | 2 | 1 | |||||||||||||||||