line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SHARYANTO::File::Util; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
46938
|
use 5.010001; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
32
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
3
|
use Cwd (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
263
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Exporter; |
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw(file_exists l_abs_path dir_empty); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.58'; # VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our %SPEC; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub file_exists { |
18
|
4
|
|
|
4
|
1
|
2357
|
my $path = shift; |
19
|
|
|
|
|
|
|
|
20
|
4
|
100
|
100
|
|
|
121
|
!(-l $path) && (-e _) || (-l _); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub l_abs_path { |
24
|
5
|
|
|
5
|
1
|
3550
|
my $path = shift; |
25
|
5
|
100
|
|
|
|
101
|
return Cwd::abs_path($path) unless (-l $path); |
26
|
|
|
|
|
|
|
|
27
|
4
|
|
|
|
|
7
|
$path =~ s!/\z!!; |
28
|
4
|
|
|
|
|
6
|
my ($parent, $leaf); |
29
|
4
|
50
|
|
|
|
24
|
if ($path =~ m!(.+)/(.+)!s) { |
30
|
4
|
|
|
|
|
52
|
$parent = Cwd::abs_path($1); |
31
|
4
|
50
|
|
|
|
10
|
return undef unless defined($path); |
32
|
4
|
|
|
|
|
5
|
$leaf = $2; |
33
|
|
|
|
|
|
|
} else { |
34
|
0
|
|
|
|
|
0
|
$parent = Cwd::getcwd(); |
35
|
0
|
|
|
|
|
0
|
$leaf = $path; |
36
|
|
|
|
|
|
|
} |
37
|
4
|
|
|
|
|
25
|
"$parent/$leaf"; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub dir_empty { |
41
|
5
|
|
|
5
|
1
|
2362
|
my ($dir) = @_; |
42
|
5
|
100
|
|
|
|
59
|
return undef unless (-d $dir); |
43
|
4
|
50
|
|
|
|
82
|
return undef unless opendir my($dh), $dir; |
44
|
4
|
100
|
|
|
|
66
|
my @d = grep {$_ ne '.' && $_ ne '..'} readdir($dh); |
|
11
|
|
|
|
|
42
|
|
45
|
4
|
|
|
|
|
9
|
my $res = !@d; |
46
|
|
|
|
|
|
|
#$log->tracef("dir_is_empty(%s)? %d", $dir, $res); |
47
|
4
|
|
|
|
|
37
|
$res; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1; |
51
|
|
|
|
|
|
|
# ABSTRACT: File-related utilities |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
__END__ |