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