| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package File::MoreUtil; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
|
4
|
|
|
|
|
|
|
our $DATE = '2020-05-30'; # DATE |
|
5
|
|
|
|
|
|
|
our $DIST = 'File-MoreUtil'; # DIST |
|
6
|
|
|
|
|
|
|
our $VERSION = '0.624'; # VERSION |
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
79552
|
use 5.010001; |
|
|
1
|
|
|
|
|
12
|
|
|
9
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
15
|
|
|
10
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
18
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
4
|
use Cwd (); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
1672
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
require Exporter; |
|
15
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
16
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
|
17
|
|
|
|
|
|
|
file_exists |
|
18
|
|
|
|
|
|
|
l_abs_path |
|
19
|
|
|
|
|
|
|
dir_empty |
|
20
|
|
|
|
|
|
|
dir_has_files |
|
21
|
|
|
|
|
|
|
dir_has_dot_files |
|
22
|
|
|
|
|
|
|
dir_has_non_dot_files |
|
23
|
|
|
|
|
|
|
dir_has_subdirs |
|
24
|
|
|
|
|
|
|
dir_has_non_subdirs |
|
25
|
|
|
|
|
|
|
dir_has_dot_subdirs |
|
26
|
|
|
|
|
|
|
dir_has_non_dot_subdirs |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
get_dir_entries |
|
29
|
|
|
|
|
|
|
get_dir_dot_entries |
|
30
|
|
|
|
|
|
|
get_dir_subdirs |
|
31
|
|
|
|
|
|
|
get_dir_non_subdirs |
|
32
|
|
|
|
|
|
|
get_dir_dot_subdirs |
|
33
|
|
|
|
|
|
|
get_dir_non_dot_subdirs |
|
34
|
|
|
|
|
|
|
get_dir_files |
|
35
|
|
|
|
|
|
|
get_dir_dot_files |
|
36
|
|
|
|
|
|
|
get_dir_non_dot_files |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
our %SPEC; |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub file_exists { |
|
42
|
4
|
|
|
4
|
1
|
1746
|
my $path = shift; |
|
43
|
|
|
|
|
|
|
|
|
44
|
4
|
100
|
100
|
|
|
76
|
!(-l $path) && (-e _) || (-l _); |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub l_abs_path { |
|
48
|
5
|
|
|
5
|
1
|
3036
|
my $path = shift; |
|
49
|
5
|
100
|
|
|
|
88
|
return Cwd::abs_path($path) unless (-l $path); |
|
50
|
|
|
|
|
|
|
|
|
51
|
4
|
|
|
|
|
12
|
$path =~ s!/\z!!; |
|
52
|
4
|
|
|
|
|
17
|
my ($parent, $leaf); |
|
53
|
4
|
50
|
|
|
|
22
|
if ($path =~ m!(.+)/(.+)!s) { |
|
54
|
4
|
|
|
|
|
66
|
$parent = Cwd::abs_path($1); |
|
55
|
4
|
50
|
|
|
|
11
|
return undef unless defined($path); |
|
56
|
4
|
|
|
|
|
9
|
$leaf = $2; |
|
57
|
|
|
|
|
|
|
} else { |
|
58
|
0
|
|
|
|
|
0
|
$parent = Cwd::getcwd(); |
|
59
|
0
|
|
|
|
|
0
|
$leaf = $path; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
4
|
|
|
|
|
24
|
"$parent/$leaf"; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub dir_empty { |
|
65
|
8
|
|
|
8
|
1
|
6163
|
my ($dir) = @_; |
|
66
|
8
|
100
|
|
|
|
104
|
return undef unless (-d $dir); |
|
67
|
7
|
50
|
|
|
|
167
|
return undef unless opendir my($dh), $dir; |
|
68
|
7
|
|
|
|
|
108
|
while (defined(my $e = readdir $dh)) { |
|
69
|
18
|
100
|
100
|
|
|
76
|
next if $e eq '.' || $e eq '..'; |
|
70
|
6
|
|
|
|
|
103
|
return 0; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
1
|
|
|
|
|
21
|
1; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub dir_has_files { |
|
76
|
10
|
|
|
10
|
1
|
21
|
my ($dir) = @_; |
|
77
|
10
|
100
|
|
|
|
126
|
return undef unless (-d $dir); |
|
78
|
9
|
50
|
|
|
|
200
|
return undef unless opendir my($dh), $dir; |
|
79
|
9
|
|
|
|
|
115
|
while (defined(my $e = readdir $dh)) { |
|
80
|
22
|
100
|
100
|
|
|
96
|
next if $e eq '.' || $e eq '..'; |
|
81
|
8
|
100
|
|
|
|
112
|
next unless -f "$dir/$e"; |
|
82
|
4
|
|
|
|
|
57
|
return 1; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
5
|
|
|
|
|
68
|
0; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub dir_has_dot_files { |
|
88
|
10
|
|
|
10
|
1
|
23
|
my ($dir) = @_; |
|
89
|
10
|
100
|
|
|
|
128
|
return undef unless (-d $dir); |
|
90
|
9
|
50
|
|
|
|
271
|
return undef unless opendir my($dh), $dir; |
|
91
|
9
|
|
|
|
|
113
|
while (defined(my $e = readdir $dh)) { |
|
92
|
24
|
100
|
100
|
|
|
105
|
next if $e eq '.' || $e eq '..'; |
|
93
|
8
|
100
|
|
|
|
44
|
next unless $e =~ /\A\./; |
|
94
|
3
|
100
|
|
|
|
42
|
next unless -f "$dir/$e"; |
|
95
|
2
|
|
|
|
|
52
|
return 1; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
7
|
|
|
|
|
97
|
0; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub dir_has_non_dot_files { |
|
101
|
10
|
|
|
10
|
1
|
20
|
my ($dir) = @_; |
|
102
|
10
|
100
|
|
|
|
127
|
return undef unless (-d $dir); |
|
103
|
9
|
50
|
|
|
|
197
|
return undef unless opendir my($dh), $dir; |
|
104
|
9
|
|
|
|
|
126
|
while (defined(my $e = readdir $dh)) { |
|
105
|
24
|
100
|
100
|
|
|
106
|
next if $e eq '.' || $e eq '..'; |
|
106
|
8
|
100
|
|
|
|
34
|
next if $e =~ /\A\./; |
|
107
|
5
|
100
|
|
|
|
67
|
next unless -f "$dir/$e"; |
|
108
|
2
|
|
|
|
|
32
|
return 1; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
7
|
|
|
|
|
98
|
0; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub dir_has_subdirs { |
|
114
|
12
|
|
|
12
|
1
|
21
|
my ($dir) = @_; |
|
115
|
12
|
100
|
|
|
|
147
|
return undef unless (-d $dir); |
|
116
|
11
|
50
|
|
|
|
238
|
return undef unless opendir my($dh), $dir; |
|
117
|
11
|
|
|
|
|
135
|
while (defined(my $e = readdir $dh)) { |
|
118
|
29
|
100
|
100
|
|
|
116
|
next if $e eq '.' || $e eq '..'; |
|
119
|
10
|
100
|
|
|
|
156
|
next if -l "$dir/$e"; |
|
120
|
4
|
100
|
|
|
|
18
|
next unless -d _; |
|
121
|
2
|
|
|
|
|
27
|
return 1; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
9
|
|
|
|
|
125
|
0; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub dir_has_non_subdirs { |
|
127
|
9
|
|
|
9
|
1
|
17
|
my ($dir) = @_; |
|
128
|
9
|
100
|
|
|
|
113
|
return undef unless (-d $dir); |
|
129
|
8
|
50
|
|
|
|
167
|
return undef unless opendir my($dh), $dir; |
|
130
|
8
|
|
|
|
|
96
|
while (defined(my $e = readdir $dh)) { |
|
131
|
21
|
100
|
100
|
|
|
91
|
next if $e eq '.' || $e eq '..'; |
|
132
|
7
|
100
|
|
|
|
108
|
return 1 if -l "$dir/$e"; |
|
133
|
4
|
100
|
|
|
|
40
|
return 1 if !(-d _); |
|
134
|
|
|
|
|
|
|
} |
|
135
|
3
|
|
|
|
|
40
|
0; |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub dir_has_dot_subdirs { |
|
139
|
6
|
|
|
6
|
1
|
13
|
my ($dir) = @_; |
|
140
|
6
|
100
|
|
|
|
75
|
return undef unless (-d $dir); |
|
141
|
5
|
50
|
|
|
|
115
|
return undef unless opendir my($dh), $dir; |
|
142
|
5
|
|
|
|
|
61
|
while (defined(my $e = readdir $dh)) { |
|
143
|
13
|
100
|
100
|
|
|
62
|
next if $e eq '.' || $e eq '..'; |
|
144
|
4
|
100
|
|
|
|
19
|
next unless $e =~ /\A\./; |
|
145
|
2
|
50
|
|
|
|
22
|
next if -l "$dir/$e"; |
|
146
|
2
|
100
|
|
|
|
13
|
next unless -d _; |
|
147
|
1
|
|
|
|
|
15
|
return 1; |
|
148
|
|
|
|
|
|
|
} |
|
149
|
4
|
|
|
|
|
84
|
0; |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub dir_has_non_dot_subdirs { |
|
153
|
6
|
|
|
6
|
1
|
12
|
my ($dir) = @_; |
|
154
|
6
|
100
|
|
|
|
74
|
return undef unless (-d $dir); |
|
155
|
5
|
50
|
|
|
|
111
|
return undef unless opendir my($dh), $dir; |
|
156
|
5
|
|
|
|
|
72
|
while (defined(my $e = readdir $dh)) { |
|
157
|
12
|
100
|
100
|
|
|
60
|
next if $e eq '.' || $e eq '..'; |
|
158
|
4
|
100
|
|
|
|
17
|
next if $e =~ /\A\./; |
|
159
|
2
|
50
|
|
|
|
22
|
next if -l "$dir/$e"; |
|
160
|
2
|
100
|
|
|
|
8
|
next unless -d _; |
|
161
|
1
|
|
|
|
|
14
|
return 1; |
|
162
|
|
|
|
|
|
|
} |
|
163
|
4
|
|
|
|
|
55
|
0; |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub get_dir_entries { |
|
167
|
2
|
|
|
2
|
1
|
3032
|
my ($dir) = @_; |
|
168
|
2
|
|
100
|
|
|
39
|
$dir //= "."; |
|
169
|
2
|
50
|
|
|
|
52
|
opendir my($dh), $dir or die "Can't opendir $dir: $!"; |
|
170
|
2
|
100
|
|
|
|
39
|
my @res = grep { $_ ne '.' && $_ ne '..' } readdir $dh; |
|
|
9
|
|
|
|
|
37
|
|
|
171
|
2
|
|
|
|
|
20
|
closedir $dh; # we're so nice |
|
172
|
2
|
|
|
|
|
26
|
@res; |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub get_dir_dot_entries { |
|
176
|
1
|
|
|
1
|
1
|
3
|
my ($dir) = @_; |
|
177
|
1
|
|
50
|
|
|
6
|
$dir //= "."; |
|
178
|
1
|
50
|
|
|
|
26
|
opendir my($dh), $dir or die "Can't opendir $dir: $!"; |
|
179
|
1
|
100
|
100
|
|
|
18
|
my @res = grep { $_ ne '.' && $_ ne '..' && /\A\./ } readdir $dh; |
|
|
6
|
|
|
|
|
31
|
|
|
180
|
1
|
|
|
|
|
10
|
closedir $dh; # we're so nice |
|
181
|
1
|
|
|
|
|
10
|
@res; |
|
182
|
|
|
|
|
|
|
} |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub get_dir_files { |
|
185
|
1
|
|
|
1
|
1
|
3
|
my ($dir) = @_; |
|
186
|
1
|
|
50
|
|
|
6
|
$dir //= "."; |
|
187
|
1
|
50
|
|
|
|
26
|
opendir my($dh), $dir or die "Can't opendir $dir: $!"; |
|
188
|
1
|
100
|
100
|
|
|
18
|
my @res = grep { $_ ne '.' && $_ ne '..' && -f } readdir $dh; |
|
|
6
|
|
|
|
|
56
|
|
|
189
|
1
|
|
|
|
|
10
|
closedir $dh; # we're so nice |
|
190
|
1
|
|
|
|
|
11
|
@res; |
|
191
|
|
|
|
|
|
|
} |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub get_dir_dot_files { |
|
194
|
1
|
|
|
1
|
1
|
3
|
my ($dir) = @_; |
|
195
|
1
|
|
50
|
|
|
6
|
$dir //= "."; |
|
196
|
1
|
50
|
|
|
|
25
|
opendir my($dh), $dir or die "Can't opendir $dir: $!"; |
|
197
|
1
|
100
|
100
|
|
|
17
|
my @res = grep { $_ ne '.' && $_ ne '..' && /\A\./ && -f } readdir $dh; |
|
|
6
|
|
100
|
|
|
51
|
|
|
198
|
1
|
|
|
|
|
10
|
closedir $dh; # we're so nice |
|
199
|
1
|
|
|
|
|
9
|
@res; |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
sub get_dir_non_dot_files { |
|
203
|
1
|
|
|
1
|
1
|
2
|
my ($dir) = @_; |
|
204
|
1
|
|
50
|
|
|
7
|
$dir //= "."; |
|
205
|
1
|
50
|
|
|
|
23
|
opendir my($dh), $dir or die "Can't opendir $dir: $!"; |
|
206
|
1
|
100
|
100
|
|
|
17
|
my @res = grep { $_ ne '.' && $_ ne '..' && !/\A\./ && -f } readdir $dh; |
|
|
6
|
|
100
|
|
|
49
|
|
|
207
|
1
|
|
|
|
|
10
|
closedir $dh; # we're so nice |
|
208
|
1
|
|
|
|
|
9
|
@res; |
|
209
|
|
|
|
|
|
|
} |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub get_dir_subdirs { |
|
212
|
2
|
|
|
2
|
1
|
4
|
my ($dir) = @_; |
|
213
|
2
|
|
100
|
|
|
10
|
$dir //= "."; |
|
214
|
2
|
50
|
|
|
|
49
|
opendir my($dh), $dir or die "Can't opendir $dir: $!"; |
|
215
|
2
|
100
|
100
|
|
|
30
|
my @res = grep { $_ ne '.' && $_ ne '..' && !(-l) && (-d _) } readdir $dh; |
|
|
9
|
|
66
|
|
|
95
|
|
|
216
|
2
|
|
|
|
|
21
|
closedir $dh; # we're so nice |
|
217
|
2
|
|
|
|
|
19
|
@res; |
|
218
|
|
|
|
|
|
|
} |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
sub get_dir_non_subdirs { |
|
221
|
2
|
|
|
2
|
1
|
4
|
my ($dir) = @_; |
|
222
|
2
|
|
100
|
|
|
11
|
$dir //= "."; |
|
223
|
2
|
50
|
|
|
|
48
|
opendir my($dh), $dir or die "Can't opendir $dir: $!"; |
|
224
|
2
|
100
|
66
|
|
|
33
|
my @res = grep { $_ ne '.' && $_ ne '..' && ((-l) || !(-d _)) } readdir $dh; |
|
|
9
|
|
100
|
|
|
87
|
|
|
225
|
2
|
|
|
|
|
20
|
closedir $dh; # we're so nice |
|
226
|
2
|
|
|
|
|
19
|
@res; |
|
227
|
|
|
|
|
|
|
} |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
sub get_dir_dot_subdirs { |
|
230
|
1
|
|
|
1
|
1
|
3
|
my ($dir) = @_; |
|
231
|
1
|
|
50
|
|
|
6
|
$dir //= "."; |
|
232
|
1
|
50
|
|
|
|
24
|
opendir my($dh), $dir or die "Can't opendir $dir: $!"; |
|
233
|
1
|
100
|
100
|
|
|
17
|
my @res = grep { $_ ne '.' && $_ ne '..' && /\A\./ && !(-l) && (-d _) } readdir $dh; |
|
|
6
|
|
100
|
|
|
64
|
|
|
|
|
|
66
|
|
|
|
|
|
234
|
1
|
|
|
|
|
21
|
closedir $dh; # we're so nice |
|
235
|
1
|
|
|
|
|
10
|
@res; |
|
236
|
|
|
|
|
|
|
} |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
sub get_dir_non_dot_subdirs { |
|
239
|
1
|
|
|
1
|
1
|
3
|
my ($dir) = @_; |
|
240
|
1
|
|
50
|
|
|
8
|
$dir //= "."; |
|
241
|
1
|
50
|
|
|
|
24
|
opendir my($dh), $dir or die "Can't opendir $dir: $!"; |
|
242
|
1
|
100
|
100
|
|
|
17
|
my @res = grep { $_ ne '.' && $_ ne '..' && !/\A\./ && !(-l) && (-d _) } readdir $dh; |
|
|
6
|
|
100
|
|
|
78
|
|
|
|
|
|
66
|
|
|
|
|
|
243
|
1
|
|
|
|
|
10
|
closedir $dh; # we're so nice |
|
244
|
1
|
|
|
|
|
10
|
@res; |
|
245
|
|
|
|
|
|
|
} |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
1; |
|
248
|
|
|
|
|
|
|
# ABSTRACT: File-related utilities |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
__END__ |