line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::BaseDir; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
141957
|
use strict; |
|
5
|
|
|
|
|
27
|
|
|
5
|
|
|
|
|
148
|
|
4
|
5
|
|
|
5
|
|
24
|
use warnings; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
167
|
|
5
|
5
|
|
|
5
|
|
26
|
use Exporter 5.57 qw( import ); |
|
5
|
|
|
|
|
92
|
|
|
5
|
|
|
|
|
166
|
|
6
|
5
|
|
|
5
|
|
27
|
use File::Spec; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
127
|
|
7
|
5
|
|
|
5
|
|
27
|
use Config; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
5810
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: Use the Freedesktop.org base directory specification |
10
|
|
|
|
|
|
|
our $VERSION = '0.09'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
13
|
|
|
|
|
|
|
vars => [ qw( |
14
|
|
|
|
|
|
|
xdg_data_home xdg_data_dirs |
15
|
|
|
|
|
|
|
xdg_config_home xdg_config_dirs |
16
|
|
|
|
|
|
|
xdg_cache_home |
17
|
|
|
|
|
|
|
) ], |
18
|
|
|
|
|
|
|
lookup => [ qw( |
19
|
|
|
|
|
|
|
data_home data_dirs data_files |
20
|
|
|
|
|
|
|
config_home config_dirs config_files |
21
|
|
|
|
|
|
|
cache_home |
22
|
|
|
|
|
|
|
) ], |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
our @EXPORT_OK = ( |
25
|
|
|
|
|
|
|
qw(xdg_data_files xdg_config_files), |
26
|
|
|
|
|
|
|
map @$_, values %EXPORT_TAGS |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
if($^O eq 'MSWin32') |
30
|
|
|
|
|
|
|
{ |
31
|
|
|
|
|
|
|
*_rootdir = sub { 'C:\\' }; |
32
|
|
|
|
|
|
|
*_home = sub { $ENV{USERPROFILE} || $ENV{HOMEDRIVE}.$ENV{HOMEPATH} || 'C:\\' }; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
else |
35
|
|
|
|
|
|
|
{ |
36
|
14
|
|
|
14
|
|
121
|
*_rootdir = sub { File::Spec->rootdir }; |
37
|
10
|
50
|
33
|
10
|
|
678
|
*_home = sub { $ENV{HOME} || eval { [getpwuid($>)]->[7] } || File::Spec->rootdir }; |
|
0
|
|
|
|
|
0
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# OO method |
41
|
1
|
|
|
1
|
1
|
88
|
sub new { bless \$VERSION, shift } # what else is there to bless ? |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Variable methods |
44
|
15
|
100
|
|
15
|
1
|
86
|
sub xdg_data_home { $ENV{XDG_DATA_HOME} || File::Spec->catdir(_home(), qw/.local share/) } |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub xdg_data_dirs { |
47
|
|
|
|
|
|
|
( $ENV{XDG_DATA_DIRS} |
48
|
|
|
|
|
|
|
? _adapt($ENV{XDG_DATA_DIRS}) |
49
|
13
|
100
|
|
13
|
1
|
621
|
: (File::Spec->catdir(_rootdir(), qw/usr local share/), File::Spec->catdir(_rootdir(), qw/usr share/)) |
50
|
|
|
|
|
|
|
) |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
8
|
100
|
|
8
|
1
|
40
|
sub xdg_config_home {$ENV{XDG_CONFIG_HOME} || File::Spec->catdir(_home(), '.config') } |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub xdg_config_dirs { |
56
|
|
|
|
|
|
|
( $ENV{XDG_CONFIG_DIRS} |
57
|
|
|
|
|
|
|
? _adapt($ENV{XDG_CONFIG_DIRS}) |
58
|
7
|
100
|
|
7
|
1
|
24
|
: File::Spec->catdir(_rootdir(), qw/etc xdg/) |
59
|
|
|
|
|
|
|
) |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
3
|
100
|
|
3
|
1
|
15
|
sub xdg_cache_home { $ENV{XDG_CACHE_HOME} || File::Spec->catdir(_home(), '.cache') } |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _adapt { |
65
|
15
|
|
|
15
|
|
163
|
map { File::Spec->catdir( split(/\//, $_) ) } split /\Q$Config{path_sep}\E/, shift; |
|
44
|
|
|
|
|
333
|
|
66
|
|
|
|
|
|
|
# ':' defined in the spec, but ';' is standard on win32 |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Lookup methods |
70
|
3
|
|
|
3
|
1
|
3086
|
sub data_home { _catfile(xdg_data_home, @_) } |
71
|
|
|
|
|
|
|
|
72
|
6
|
|
|
6
|
1
|
3002
|
sub data_dirs { _find_files(\&_dir, \@_, xdg_data_home, xdg_data_dirs) } |
73
|
|
|
|
|
|
|
|
74
|
4
|
|
|
4
|
1
|
12
|
sub data_files { _find_files(\&_file, \@_, xdg_data_home, xdg_data_dirs) } |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
1
|
0
|
3
|
sub xdg_data_files { my @dirs = data_files(@_); return @dirs } |
|
1
|
|
|
|
|
7
|
|
77
|
|
|
|
|
|
|
|
78
|
1
|
|
|
1
|
1
|
3
|
sub config_home { _catfile(xdg_config_home, @_) } |
79
|
|
|
|
|
|
|
|
80
|
2
|
|
|
2
|
1
|
6
|
sub config_dirs { _find_files(\&_dir, \@_, xdg_config_home, xdg_config_dirs) } |
81
|
|
|
|
|
|
|
|
82
|
3
|
|
|
3
|
1
|
9
|
sub config_files { _find_files(\&_file, \@_, xdg_config_home, xdg_config_dirs) } |
83
|
|
|
|
|
|
|
|
84
|
1
|
|
|
1
|
0
|
3
|
sub xdg_config_files { my @dirs = config_files(@_); return @dirs } |
|
1
|
|
|
|
|
8
|
|
85
|
|
|
|
|
|
|
|
86
|
1
|
|
|
1
|
1
|
469
|
sub cache_home { _catfile(xdg_cache_home, @_) } |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _catfile { |
89
|
5
|
|
|
5
|
|
11
|
my $dir = shift; |
90
|
5
|
100
|
100
|
|
|
34
|
shift if ref $_[0] or $_[0] =~ /::/; # OO call |
91
|
5
|
|
|
|
|
70
|
return File::Spec->catfile($dir, @_); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub _find_files { |
95
|
15
|
|
|
15
|
|
26
|
my $type = shift; |
96
|
15
|
|
|
|
|
20
|
my $file = shift; |
97
|
15
|
100
|
100
|
|
|
94
|
shift @$file if ref $$file[0] or $$file[0] =~ /::/; # OO call |
98
|
|
|
|
|
|
|
#warn "Looking for: @$file\n in: @_\n"; |
99
|
15
|
100
|
|
|
|
42
|
if (wantarray) { ## no critic (Community::Wantarray) |
100
|
27
|
100
|
|
|
|
62
|
return grep { &$type( $_ ) && -r $_ } |
101
|
7
|
|
|
|
|
11
|
map { File::Spec->catfile($_, @$file) } @_; |
|
27
|
|
|
|
|
153
|
|
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
else { # prevent unnecessary stats by returning early |
104
|
8
|
|
|
|
|
17
|
for (@_) { |
105
|
18
|
|
|
|
|
138
|
my $path = File::Spec->catfile($_, @$file); |
106
|
18
|
100
|
66
|
|
|
44
|
return $path if &$type($path) && -r $path; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
2
|
|
|
|
|
14
|
return (); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
21
|
|
|
21
|
|
605
|
sub _dir { -d $_[0] } |
113
|
|
|
|
|
|
|
|
114
|
24
|
|
|
24
|
|
507
|
sub _file { -f $_[0] } |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
__END__ |