line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package LEOCHARRE::Dir; |
2
|
1
|
|
|
1
|
|
65763
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
74
|
|
3
|
1
|
|
|
1
|
|
7
|
use Cwd; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
39
|
|
5
|
1
|
|
|
1
|
|
7
|
use vars qw($VERSION @ISA %EXPORT_TAGS @EXPORT_OK); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
93
|
|
6
|
1
|
|
|
1
|
|
6
|
use Exporter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
151
|
|
7
|
|
|
|
|
|
|
@ISA = qw/Exporter/; |
8
|
|
|
|
|
|
|
@EXPORT_OK = qw(reqdir ls lsa lsf lsfa lsd lsda lsr lsfr lsdr); |
9
|
|
|
|
|
|
|
%EXPORT_TAGS = ( all => \@EXPORT_OK ); |
10
|
|
|
|
|
|
|
$VERSION = '1.09'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
BEGIN { |
13
|
1
|
50
|
|
1
|
|
812
|
croak("Not meant to run in windows or cygwin environments.") |
14
|
|
|
|
|
|
|
if $^O=~/cygwin|MSWin32/; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
*reqdir = \&__require_dir; |
20
|
|
|
|
|
|
|
*ls = \&__ls; |
21
|
|
|
|
|
|
|
*lsa = \&__lsa; |
22
|
|
|
|
|
|
|
*lsf = \&__lsf; |
23
|
|
|
|
|
|
|
*lsfa = \&__lsfa; |
24
|
|
|
|
|
|
|
*lsd = \&__lsd; |
25
|
|
|
|
|
|
|
*lsda = \&__lsda; |
26
|
|
|
|
|
|
|
*lsr = \&__lsr; |
27
|
|
|
|
|
|
|
*lsfr = \&__lsfr; |
28
|
|
|
|
|
|
|
*lsdr = \&__lsdr; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub __require_dir { |
32
|
4
|
|
|
4
|
|
715
|
my $arg = $_[0]; |
33
|
4
|
50
|
|
|
|
11
|
$arg or croak("Missing argument"); |
34
|
4
|
50
|
|
|
|
211
|
my $resolved_path = Cwd::abs_path($arg) |
35
|
|
|
|
|
|
|
or croak("Cwd::abs_path() not returning for '$arg'"); |
36
|
4
|
50
|
|
|
|
43
|
unless ( -d $resolved_path ){ |
37
|
4
|
50
|
|
|
|
216
|
unless( mkdir $resolved_path ){ |
38
|
0
|
|
|
|
|
0
|
warn("cant mkdir '$resolved_path'"); |
39
|
0
|
|
|
|
|
0
|
return undef; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
4
|
|
|
|
|
30
|
return $resolved_path; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#my $_d = Cwd::abs_path($_[0]) or croak("Bad or missing argument '@_'."); |
45
|
|
|
|
|
|
|
#-d $_d or mkdir $_d or warn("cant mkdir $_d") and return; |
46
|
|
|
|
|
|
|
#return $_d; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub __ls { |
50
|
11
|
100
|
|
11
|
|
886
|
$_[0] or croak("Bad or missing argument."); |
51
|
10
|
50
|
|
|
|
275
|
opendir(DIR, $_[0]) or die("Cant open dir '$_[0]', $!"); |
52
|
10
|
|
|
|
|
196
|
my @ls = grep { !/^\.+$/ } readdir DIR; |
|
65
|
|
|
|
|
208
|
|
53
|
10
|
|
|
|
|
120
|
closedir DIR; |
54
|
10
|
|
|
|
|
51
|
return @ls; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
sub __lsa { |
57
|
7
|
50
|
|
7
|
|
320
|
$_[0] or croak("Bad or missing argument"); |
58
|
7
|
50
|
|
|
|
353
|
my $abs = Cwd::abs_path($_[0]) or die("Can't resolve abs path to '@_'"); |
59
|
7
|
|
|
|
|
27
|
my @ls = map { "$abs/$_" } __ls($abs); |
|
30
|
|
|
|
|
63
|
|
60
|
7
|
|
|
|
|
201
|
return @ls; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# no leading path |
65
|
1
|
|
|
1
|
|
314
|
sub __lsf { return ( grep { -f "$_[0]/$_" } __ls( $_[0]) ) } |
|
5
|
|
|
|
|
69
|
|
66
|
1
|
|
|
1
|
|
328
|
sub __lsd { return ( grep { -d "$_[0]/$_" } __ls( $_[0]) ) } |
|
5
|
|
|
|
|
66
|
|
67
|
|
|
|
|
|
|
#*__lsd = \&__lsreaddir; this is stupidly broken |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# absolute path |
70
|
2
|
|
|
2
|
|
341
|
sub __lsfa { return ( grep -f, __lsa( $_[0]) ) } |
71
|
2
|
|
|
2
|
|
339
|
sub __lsda { return ( grep -d, __lsa( $_[0]) ) } |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# relative path to docroot |
74
|
1
|
|
|
1
|
|
17
|
sub __lsr { return ( map { __rel2docroot($_) } __lsa( $_[0]) ) } |
|
5
|
|
|
|
|
22
|
|
75
|
1
|
|
|
1
|
|
779
|
sub __lsfr { return ( map { __rel2docroot($_) } __lsfa( $_[0]) ) } |
|
2
|
|
|
|
|
10
|
|
76
|
1
|
|
|
1
|
|
328
|
sub __lsdr { return ( map { __rel2docroot($_) } __lsda( $_[0]) ) } |
|
3
|
|
|
|
|
14
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub __rel2docroot { |
79
|
10
|
50
|
|
10
|
|
35
|
$ENV{DOCUMENT_ROOT} or die("ENV DOCUMENT ROOT not set"); |
80
|
|
|
|
|
|
|
|
81
|
10
|
|
|
|
|
16
|
my $p = shift; |
82
|
10
|
50
|
|
|
|
21
|
$p or die('missing argument'); |
83
|
|
|
|
|
|
|
|
84
|
10
|
50
|
|
|
|
81
|
$p=~s/^$ENV{DOCUMENT_ROOT}// or return; |
85
|
10
|
|
|
|
|
36
|
return $p; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# see .pod |
91
|
|
|
|
|
|
|
|