| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Config::Find::Any; |
|
2
|
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
27
|
use strict; |
|
|
5
|
|
|
|
|
11
|
|
|
|
5
|
|
|
|
|
375
|
|
|
4
|
5
|
|
|
5
|
|
72
|
use warnings; |
|
|
5
|
|
|
|
|
6
|
|
|
|
5
|
|
|
|
|
196
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
23
|
use Carp; |
|
|
5
|
|
|
|
|
7
|
|
|
|
5
|
|
|
|
|
369
|
|
|
7
|
5
|
|
|
5
|
|
29
|
use File::Spec; |
|
|
5
|
|
|
|
|
5
|
|
|
|
5
|
|
|
|
|
114
|
|
|
8
|
5
|
|
|
5
|
|
24
|
use File::Which; |
|
|
5
|
|
|
|
|
7
|
|
|
|
5
|
|
|
|
|
312
|
|
|
9
|
5
|
|
|
5
|
|
2545
|
use IO::File; |
|
|
5
|
|
|
|
|
64678
|
|
|
|
5
|
|
|
|
|
10627
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# private methods |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub _find { |
|
14
|
6
|
|
|
6
|
|
16
|
my ($class, $write, $global, @names)=@_; |
|
15
|
|
|
|
|
|
|
|
|
16
|
6
|
|
|
|
|
14
|
for my $n (@names) { |
|
17
|
8
|
|
|
|
|
10
|
my $fn; |
|
18
|
8
|
50
|
|
|
|
27
|
if ($n=~/^(.*?)\/(.*)$/) { |
|
19
|
0
|
|
|
|
|
0
|
my ($dir, $file)=($1, $2); |
|
20
|
0
|
|
|
|
|
0
|
$fn=$class->look_for_dir_file($dir, $file, $write, $global); |
|
21
|
|
|
|
|
|
|
} else { |
|
22
|
8
|
|
|
|
|
36
|
$fn=$class->look_for_file($n, $write, $global); |
|
23
|
|
|
|
|
|
|
} |
|
24
|
8
|
100
|
|
|
|
45
|
return $fn if defined $fn; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
8
|
return undef; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _open { |
|
31
|
0
|
|
|
0
|
|
0
|
my ($class, $write, $global, $fn)=@_; |
|
32
|
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
0
|
if ($write) { |
|
34
|
0
|
|
|
|
|
0
|
$class->create_parent_dir($fn); |
|
35
|
0
|
|
|
|
|
0
|
return IO::File->new($fn, 'w'); |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
0
|
0
|
|
|
|
0
|
defined($fn) ? IO::File->new($fn, 'r') : undef; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _install { |
|
42
|
0
|
|
|
0
|
|
0
|
my ($class, $orig, $write, $global, $fn)=@_; |
|
43
|
0
|
0
|
|
|
|
0
|
croak "install mode has to be 'write'" unless $write; |
|
44
|
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
0
|
my $oh=IO::File->new($orig, 'r') |
|
46
|
|
|
|
|
|
|
or croak "unable to open '$orig'"; |
|
47
|
0
|
0
|
|
|
|
0
|
my $fh=$class->_open($write, $global, $fn) |
|
48
|
|
|
|
|
|
|
or croak "unable to create config file '$fn'"; |
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
0
|
while(<$oh>) { $fh->print($_) } |
|
|
0
|
|
|
|
|
0
|
|
|
51
|
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
0
|
close $fh |
|
53
|
|
|
|
|
|
|
or die "unable to write config file '$fn'"; |
|
54
|
0
|
0
|
|
|
|
0
|
close $oh |
|
55
|
|
|
|
|
|
|
or die "unable to read '$orig'"; |
|
56
|
0
|
|
|
|
|
0
|
return $fn; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _temp_dir { |
|
60
|
0
|
|
|
0
|
|
0
|
my ($class, $name, $more_name, $scope)=@_; |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
my $stemp=$class->system_temp; |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
0
|
if ($scope eq 'global') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
0
|
$class->my_catdir($stemp, $name, $more_name) |
|
66
|
|
|
|
|
|
|
} elsif ($scope eq 'user') { |
|
67
|
0
|
|
|
|
|
0
|
$class->my_catdir($stemp, $class->my_getlogin, $name, $more_name) |
|
68
|
|
|
|
|
|
|
} elsif ($scope eq 'app') { |
|
69
|
0
|
|
|
|
|
0
|
$class->my_catdir($class->app_dir($name), 'tmp', $more_name) |
|
70
|
|
|
|
|
|
|
} elsif ($scope eq 'process') { |
|
71
|
0
|
|
|
|
|
0
|
$class->my_catdir($stemp, $class->my_getlogin, $name, $$, $more_name) |
|
72
|
|
|
|
|
|
|
} else { |
|
73
|
0
|
|
|
|
|
0
|
croak "scope '$scope' is not valid for temp_dir method"; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# public methods, to be overridden |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub look_for_file { |
|
80
|
0
|
|
|
0
|
1
|
0
|
my $class=shift; |
|
81
|
0
|
|
|
|
|
0
|
die "unimplemented virtual method $class->look_for_file() called"; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub look_for_dir_file { |
|
85
|
0
|
|
|
0
|
1
|
0
|
my $class=shift; |
|
86
|
0
|
|
|
|
|
0
|
die "unimplemented virtual method $class->look_for_dir_file() called"; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# public methods, inherited by sub-classes |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub guess_full_script_name { |
|
92
|
14
|
|
|
14
|
1
|
217
|
my $path = (File::Spec->splitpath($0))[1]; |
|
93
|
14
|
50
|
|
|
|
45
|
if ($path eq '') { |
|
94
|
0
|
0
|
|
|
|
0
|
if (my $script = File::Which::which($0)) { |
|
95
|
0
|
|
|
|
|
0
|
return File::Spec->rel2abs($script); |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
14
|
50
|
|
|
|
539
|
return File::Spec->rel2abs($0) if -e $0; |
|
100
|
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
0
|
carp "unable to determine script '$0' location"; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub guess_script_name { |
|
105
|
0
|
|
|
0
|
1
|
0
|
my $name; |
|
106
|
0
|
|
|
|
|
0
|
(undef, undef, $name)=File::Spec->splitpath($0); |
|
107
|
0
|
0
|
|
|
|
0
|
$name=~/^(.+)\..*$/ and return $1; |
|
108
|
0
|
0
|
|
|
|
0
|
return undef if $name eq ''; |
|
109
|
0
|
|
|
|
|
0
|
return $name; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub guess_script_dir { |
|
113
|
14
|
|
|
14
|
1
|
22
|
my $class=shift; |
|
114
|
14
|
|
|
|
|
44
|
my $script=$class->guess_full_script_name; |
|
115
|
14
|
|
|
|
|
149
|
my ($unit, $dir)=File::Spec->splitpath($script, 0); |
|
116
|
14
|
|
|
|
|
249
|
File::Spec->catpath($unit, $dir, ''); |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
7
|
|
|
7
|
1
|
36
|
sub is_one_liner { return $0 eq '-e' } |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub add_extension { |
|
122
|
7
|
|
|
7
|
1
|
12
|
my ($class, $name, $ext)=@_; |
|
123
|
7
|
50
|
|
|
|
22
|
return $name if ($name=~/\./); |
|
124
|
7
|
|
|
|
|
30
|
return $name.'.'.$ext; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub create_parent_dir { |
|
128
|
0
|
|
|
0
|
1
|
0
|
my ($class, $fn)=@_; |
|
129
|
0
|
|
|
|
|
0
|
my $parent=$class->parent_dir($fn); |
|
130
|
0
|
0
|
|
|
|
0
|
if (-e $parent) { |
|
131
|
0
|
0
|
|
|
|
0
|
-d $parent |
|
132
|
|
|
|
|
|
|
or croak "'$parent' exists but is not a directory"; |
|
133
|
0
|
0
|
|
|
|
0
|
-W $parent |
|
134
|
|
|
|
|
|
|
or croak "not allowed to write on directory '$parent'"; |
|
135
|
|
|
|
|
|
|
} else { |
|
136
|
0
|
|
|
|
|
0
|
$class->create_parent_dir($parent); |
|
137
|
0
|
0
|
|
|
|
0
|
mkdir $parent |
|
138
|
|
|
|
|
|
|
or die "unable to create directory '$parent' ($!)"; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub parent_dir { |
|
143
|
14
|
|
|
14
|
1
|
22
|
my ($class, $dir)=@_; |
|
144
|
|
|
|
|
|
|
# print "creating dir $dir\n"; |
|
145
|
14
|
|
|
|
|
96
|
my @dirs=File::Spec->splitdir($dir); |
|
146
|
14
|
50
|
|
|
|
47
|
pop(@dirs) eq '' and pop(@dirs); |
|
147
|
14
|
50
|
|
|
|
263
|
File::Spec->catfile(@dirs ? @dirs : File::Spec->rootdir); |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub create_dir { |
|
151
|
0
|
|
|
0
|
1
|
|
my ($class, $dir)=@_; |
|
152
|
0
|
0
|
|
|
|
|
if (-e $dir) { |
|
153
|
0
|
0
|
|
|
|
|
-d $dir or croak "'$dir' exists but is not a directory"; |
|
154
|
|
|
|
|
|
|
} else { |
|
155
|
0
|
|
|
|
|
|
$class->create_parent_dir($dir); |
|
156
|
0
|
0
|
|
|
|
|
mkdir $dir |
|
157
|
|
|
|
|
|
|
or die "unable to create directory '$dir' ($!)"; |
|
158
|
|
|
|
|
|
|
} |
|
159
|
0
|
|
|
|
|
|
$dir; |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub my_catfile { |
|
163
|
0
|
|
|
0
|
1
|
|
my $class=shift; |
|
164
|
0
|
0
|
|
|
|
|
pop @_ unless defined $_[-1]; |
|
165
|
0
|
|
|
|
|
|
File::Spec->catfile(@_); |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub my_catdir { |
|
169
|
0
|
|
|
0
|
1
|
|
my $class=shift; |
|
170
|
0
|
0
|
|
|
|
|
pop @_ unless defined $_[-1]; |
|
171
|
0
|
|
|
|
|
|
File::Spec->catdir(@_); |
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub my_getlogin { |
|
175
|
0
|
|
|
0
|
1
|
|
my $login=getlogin(); |
|
176
|
0
|
0
|
|
|
|
|
$login = '_UNKNOW_' unless defined $login; |
|
177
|
0
|
|
|
|
|
|
$login; |
|
178
|
|
|
|
|
|
|
} |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
1; |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
__END__ |