| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Config::Find::Unix; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.29'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
33
|
use strict; |
|
|
6
|
|
|
|
|
8
|
|
|
|
6
|
|
|
|
|
203
|
|
|
6
|
6
|
|
|
6
|
|
25
|
use warnings; |
|
|
6
|
|
|
|
|
7
|
|
|
|
6
|
|
|
|
|
144
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
|
28
|
use Carp; |
|
|
6
|
|
|
|
|
6
|
|
|
|
6
|
|
|
|
|
319
|
|
|
9
|
6
|
|
|
6
|
|
7129
|
use File::HomeDir; |
|
|
6
|
|
|
|
|
37335
|
|
|
|
6
|
|
|
|
|
474
|
|
|
10
|
6
|
|
|
6
|
|
2804
|
use Config::Find::Any; |
|
|
6
|
|
|
|
|
18
|
|
|
|
6
|
|
|
|
|
7651
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @ISA=qw(Config::Find::Any); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub app_dir { |
|
15
|
14
|
|
|
14
|
0
|
16
|
my ($class, $name)=@_; |
|
16
|
14
|
50
|
|
|
|
21
|
$name=$class->guess_script_name |
|
17
|
|
|
|
|
|
|
unless defined $name; |
|
18
|
|
|
|
|
|
|
|
|
19
|
14
|
|
|
|
|
18
|
my $ename = uc($name).'_HOME'; |
|
20
|
14
|
50
|
|
|
|
27
|
return $ENV{$ename} if (exists $ENV{$ename}); |
|
21
|
|
|
|
|
|
|
|
|
22
|
14
|
|
|
|
|
30
|
$class->parent_dir($class->guess_script_dir); |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _my_home { |
|
26
|
7
|
|
|
7
|
|
24
|
my $home = File::HomeDir->my_home; |
|
27
|
7
|
50
|
|
|
|
236
|
return $home if defined $home; |
|
28
|
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
0
|
my ($user, $dir) = (getpwuid $>)[0, 7]; |
|
30
|
|
|
|
|
|
|
|
|
31
|
0
|
0
|
|
|
|
0
|
return $dir if defined $dir; |
|
32
|
0
|
0
|
|
|
|
0
|
return "/home/$user" if defined $user; |
|
33
|
0
|
|
|
|
|
0
|
return "/" |
|
34
|
|
|
|
|
|
|
}; |
|
35
|
|
|
|
|
|
|
|
|
36
|
0
|
|
|
0
|
0
|
0
|
sub system_temp { '/tmp' } |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _var_dir { |
|
39
|
0
|
|
|
0
|
|
0
|
my ($class, $name, $more_name, $scope) = @_; |
|
40
|
|
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
0
|
if ($scope eq 'global') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
0
|
$class->my_catfile('/var', $name, $more_name); |
|
43
|
|
|
|
|
|
|
} elsif ($scope eq 'user') { |
|
44
|
0
|
|
|
|
|
0
|
File::Spec->catfile(_my_home(), '.'.$name, 'var', $more_name); |
|
45
|
|
|
|
|
|
|
} elsif ($scope eq 'app') { |
|
46
|
0
|
|
|
|
|
0
|
$class->my_catfile($class->app_dir($name), 'var', $more_name); |
|
47
|
|
|
|
|
|
|
} else { |
|
48
|
0
|
|
|
|
|
0
|
croak "scope '$scope' is not valid for var_dir method"; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _bin_dir { |
|
53
|
0
|
|
|
0
|
|
0
|
my ($class, $name, $more_name, $scope) = @_; |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
0
|
if ($scope eq 'global') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
0
|
'/usr/bin'; |
|
57
|
|
|
|
|
|
|
} elsif ($scope eq 'user') { |
|
58
|
0
|
|
|
|
|
0
|
File::Spec->catfile(_my_home(), 'bin'); |
|
59
|
|
|
|
|
|
|
} elsif ($scope eq 'app') { |
|
60
|
0
|
|
|
|
|
0
|
File::Spec->catfile($class->app_dir($name), 'bin'); |
|
61
|
|
|
|
|
|
|
} else { |
|
62
|
0
|
|
|
|
|
0
|
croak "scope '$scope' is not valid for bin_dir method"; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _lib_dir { |
|
67
|
0
|
|
|
0
|
|
0
|
my ($class, $name, $more_name, $scope) = @_; |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
0
|
if ($scope eq 'global') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
0
|
'/usr/lib'; |
|
71
|
|
|
|
|
|
|
} elsif ($scope eq 'user') { |
|
72
|
0
|
|
|
|
|
0
|
File::Spec->catfile(_my_home(), 'lib'); |
|
73
|
|
|
|
|
|
|
} elsif ($scope eq 'app') { |
|
74
|
0
|
|
|
|
|
0
|
File::Spec->catfile($class->app_dir($name), 'lib'); |
|
75
|
|
|
|
|
|
|
} else { |
|
76
|
0
|
|
|
|
|
0
|
croak "scope '$scope' is not valid for lib_dir method"; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub look_for_file { |
|
81
|
8
|
|
|
8
|
1
|
10
|
my ($class, $name, $write, $global)=@_; |
|
82
|
8
|
|
|
|
|
7
|
my $fn; |
|
83
|
|
|
|
|
|
|
|
|
84
|
8
|
100
|
|
|
|
9
|
if ($write) { |
|
85
|
2
|
100
|
|
|
|
5
|
if ($global) { |
|
86
|
1
|
|
|
|
|
5
|
my $fnwe=$class->add_extension($name, 'conf'); |
|
87
|
|
|
|
|
|
|
|
|
88
|
1
|
50
|
|
|
|
4
|
unless ($class->is_one_liner) { |
|
89
|
1
|
|
|
|
|
3
|
my $etc=File::Spec->catfile($class->app_dir($name), 'etc'); |
|
90
|
1
|
50
|
|
|
|
17
|
return File::Spec->catfile($etc, $fnwe) if -e $etc; |
|
91
|
|
|
|
|
|
|
|
|
92
|
1
|
|
|
|
|
3
|
$etc=File::Spec->catfile($class->app_dir($name), 'conf'); |
|
93
|
1
|
50
|
|
|
|
18
|
return File::Spec->catfile($etc, $fnwe) if -e $etc; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
0
|
return File::Spec->catfile('/etc', $fnwe); |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
1
|
|
|
|
|
2
|
return File::Spec->catfile(_my_home(), ".$name"); |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
} else { |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# looks in ~/.whatever |
|
104
|
6
|
50
|
|
|
|
11
|
unless ($global) { |
|
105
|
6
|
|
|
|
|
10
|
$fn=File::Spec->catfile(_my_home(), ".$name"); |
|
106
|
6
|
100
|
|
|
|
49
|
return $fn if -f $fn; |
|
107
|
3
|
|
|
|
|
5
|
for my $ext (qw(conf cfg)) { |
|
108
|
6
|
50
|
|
|
|
27
|
return "$fn.$ext" if -f "$fn.$ext"; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
3
|
|
|
|
|
6
|
for my $fnwe (map {$class->add_extension($name, $_)} qw(conf cfg)) { |
|
|
6
|
|
|
|
|
19
|
|
|
113
|
6
|
50
|
|
|
|
15
|
unless ($class->is_one_liner) { |
|
114
|
|
|
|
|
|
|
# looks in ./../etc/whatever.conf relative to the running script |
|
115
|
6
|
|
|
|
|
12
|
$fn=File::Spec->catfile($class->app_dir($name), 'etc', $fnwe); |
|
116
|
6
|
50
|
|
|
|
59
|
return $fn if -f $fn; |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# looks in ./../conf/whatever.conf relative to the running script |
|
119
|
6
|
|
|
|
|
12
|
$fn=File::Spec->catfile($class->app_dir($name), 'conf', $fnwe); |
|
120
|
6
|
50
|
|
|
|
73
|
return $fn if -f $fn; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# looks in /etc/whatever.conf |
|
124
|
6
|
|
|
|
|
28
|
$fn=File::Spec->catfile('/etc', $fnwe); |
|
125
|
6
|
50
|
|
|
|
47
|
return $fn if -f $fn; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
3
|
|
|
|
|
8
|
return; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub look_for_helper { |
|
133
|
0
|
|
|
0
|
0
|
|
my ($class, $dir, $helper)=@_; |
|
134
|
0
|
|
|
|
|
|
my $path=File::Spec->catfile($dir, $helper); |
|
135
|
0
|
0
|
|
|
|
|
-e $path |
|
136
|
|
|
|
|
|
|
or croak "helper '$helper' not found"; |
|
137
|
0
|
0
|
0
|
|
|
|
((-f $path or -l $path) and -x $path) |
|
|
|
|
0
|
|
|
|
|
|
138
|
|
|
|
|
|
|
or croak "helper '$helper' found at '$path' but it is not executable"; |
|
139
|
0
|
|
|
|
|
|
return $path |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub look_for_dir_file { |
|
143
|
0
|
|
|
0
|
1
|
|
my ($class, $dir, $name, $write, $global)=@_; |
|
144
|
0
|
|
|
|
|
|
my $fn; |
|
145
|
|
|
|
|
|
|
|
|
146
|
0
|
0
|
|
|
|
|
if ($write) { |
|
147
|
0
|
|
|
|
|
|
my $fnwe=$class->add_extension($name, 'conf'); |
|
148
|
0
|
0
|
|
|
|
|
if ($global) { |
|
149
|
0
|
0
|
|
|
|
|
unless ($class->is_one_liner) { |
|
150
|
0
|
|
|
|
|
|
my $etc=File::Spec->catfile($class->app_dir($dir), 'etc'); |
|
151
|
0
|
0
|
|
|
|
|
return File::Spec->catfile($etc, $dir, $fnwe) if -e $etc; |
|
152
|
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
$etc=File::Spec->catfile($class->app_dir($dir), 'conf'); |
|
154
|
0
|
0
|
|
|
|
|
return File::Spec->catfile($etc, $dir, $fnwe) if -e $etc; |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
return File::Spec->catfile('/etc', $dir, $fnwe); |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
return File::Spec->catfile(_my_home(), ".$dir", $fnwe); |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
} else { |
|
163
|
|
|
|
|
|
|
# looks in ~/.whatever |
|
164
|
0
|
|
|
|
|
|
for my $fnwe (map {$class->add_extension($name, $_)} qw(conf cfg)) { |
|
|
0
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
|
166
|
0
|
0
|
|
|
|
|
unless ($global) { |
|
167
|
0
|
|
|
|
|
|
my $fn=File::Spec->catfile(_my_home(), ".$dir", $fnwe); |
|
168
|
0
|
0
|
|
|
|
|
return $fn if -f $fn; |
|
169
|
|
|
|
|
|
|
} |
|
170
|
|
|
|
|
|
|
|
|
171
|
0
|
0
|
0
|
|
|
|
unless ($class->is_one_liner and not defined $dir) { |
|
172
|
|
|
|
|
|
|
# looks in ./../etc/whatever.conf relative to the running script |
|
173
|
0
|
|
|
|
|
|
$fn=File::Spec->catfile($class->app_dir($dir), 'etc', $dir, $fnwe); |
|
174
|
0
|
0
|
|
|
|
|
return $fn if -f $fn; |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
# looks in ./../conf/whatever.conf relative to the running script |
|
177
|
0
|
|
|
|
|
|
$fn=File::Spec->catfile($class->app_dir($dir), 'conf', $dir, $fnwe); |
|
178
|
0
|
0
|
|
|
|
|
return $fn if -f $fn; |
|
179
|
|
|
|
|
|
|
} |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
# looks in system /etc/whatever.conf |
|
182
|
0
|
|
|
|
|
|
$fn=File::Spec->catfile('/etc', $dir, $fnwe); |
|
183
|
0
|
0
|
|
|
|
|
return $fn if -f $fn; |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
} |
|
186
|
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
return; |
|
188
|
|
|
|
|
|
|
} |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
1; |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
__END__ |