line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
########################################### |
2
|
|
|
|
|
|
|
# File::Comments -- 2005, Mike Schilli |
3
|
|
|
|
|
|
|
########################################### |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
########################################### |
6
|
|
|
|
|
|
|
package File::Comments; |
7
|
|
|
|
|
|
|
########################################### |
8
|
|
|
|
|
|
|
|
9
|
9
|
|
|
9
|
|
1223674
|
use strict; |
|
9
|
|
|
|
|
24
|
|
|
9
|
|
|
|
|
304
|
|
10
|
9
|
|
|
9
|
|
58
|
use warnings; |
|
9
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
334
|
|
11
|
9
|
|
|
9
|
|
1283
|
use Log::Log4perl qw(:easy); |
|
9
|
|
|
|
|
57181
|
|
|
9
|
|
|
|
|
65
|
|
12
|
9
|
|
|
9
|
|
6273
|
use Sysadm::Install qw(:all); |
|
9
|
|
|
|
|
46737
|
|
|
9
|
|
|
|
|
54
|
|
13
|
9
|
|
|
9
|
|
6981
|
use File::Basename; |
|
9
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
752
|
|
14
|
|
|
|
|
|
|
use Module::Pluggable |
15
|
9
|
|
|
|
|
66
|
require => 1, |
16
|
|
|
|
|
|
|
#search_path => [qw(File::Comments::Plugin)], |
17
|
9
|
|
|
9
|
|
8195
|
; |
|
9
|
|
|
|
|
86857
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = "0.08"; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
########################################### |
22
|
|
|
|
|
|
|
sub new { |
23
|
|
|
|
|
|
|
########################################### |
24
|
11
|
|
|
11
|
1
|
2742
|
my($class, %options) = @_; |
25
|
|
|
|
|
|
|
|
26
|
11
|
|
|
|
|
98
|
my $self = { |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
cold_calls => 1, |
29
|
|
|
|
|
|
|
default_plugin => undef, |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
suffixes => {}, |
32
|
|
|
|
|
|
|
bases => {}, |
33
|
|
|
|
|
|
|
plugins => [], |
34
|
|
|
|
|
|
|
%options, |
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
|
37
|
11
|
|
|
|
|
41
|
bless $self, $class; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Init plugins |
40
|
11
|
|
|
|
|
50
|
$self->init(); |
41
|
|
|
|
|
|
|
|
42
|
11
|
|
|
|
|
70
|
return $self; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
########################################### |
46
|
|
|
|
|
|
|
sub init { |
47
|
|
|
|
|
|
|
########################################### |
48
|
11
|
|
|
11
|
0
|
27
|
my($self) = @_; |
49
|
|
|
|
|
|
|
|
50
|
11
|
|
|
|
|
80
|
$self->{plugins} = []; |
51
|
|
|
|
|
|
|
|
52
|
11
|
|
|
|
|
80
|
for($self->plugins()) { |
53
|
99
|
|
|
|
|
81885
|
DEBUG "Initializing plugin $_"; |
54
|
99
|
|
|
|
|
1364
|
my $plugin = $_->new(mothership => $self); |
55
|
99
|
|
|
|
|
122
|
push @{$self->{plugins}}, $plugin; |
|
99
|
|
|
|
|
255
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
########################################### |
60
|
|
|
|
|
|
|
sub find_plugin { |
61
|
|
|
|
|
|
|
########################################### |
62
|
18
|
|
|
18
|
0
|
37
|
my($self) = @_; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Is there a suffix handler defined? |
65
|
18
|
100
|
100
|
|
|
165
|
if(defined $self->{target}->{suffix} and |
66
|
|
|
|
|
|
|
exists $self->{suffixes}->{$self->{target}->{suffix}}) { |
67
|
|
|
|
|
|
|
|
68
|
10
|
|
|
|
|
56
|
DEBUG "Searching for plugin handling suffix $self->{target}->{suffix}"; |
69
|
|
|
|
|
|
|
|
70
|
10
|
|
|
|
|
73
|
for my $plugin (@{$self->{suffixes}->{$self->{target}->{suffix}}}) { |
|
10
|
|
|
|
|
44
|
|
71
|
10
|
|
|
|
|
62
|
DEBUG "Checking if ", ref $plugin, |
72
|
|
|
|
|
|
|
" is applicable for suffix ", |
73
|
|
|
|
|
|
|
"'$self->{target}->{suffix}'"; |
74
|
10
|
50
|
|
|
|
145
|
if($plugin->applicable($self->{target})) { |
75
|
10
|
|
|
|
|
38
|
DEBUG ref($plugin), " accepted"; |
76
|
10
|
|
|
|
|
73
|
return $plugin; |
77
|
|
|
|
|
|
|
} else { |
78
|
0
|
|
|
|
|
0
|
DEBUG ref($plugin), " rejected"; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Is there a base handler defined? |
84
|
8
|
100
|
66
|
|
|
79
|
if(defined $self->{target}->{file_base} and |
85
|
|
|
|
|
|
|
exists $self->{bases}->{$self->{target}->{file_base}}) { |
86
|
|
|
|
|
|
|
|
87
|
2
|
|
|
|
|
11
|
DEBUG "Searching for plugin handling base $self->{target}->{file_base}"; |
88
|
|
|
|
|
|
|
|
89
|
2
|
|
|
|
|
12
|
for my $plugin (@{$self->{bases}->{$self->{target}->{file_base}}}) { |
|
2
|
|
|
|
|
8
|
|
90
|
2
|
|
|
|
|
11
|
DEBUG "Checking if ", ref $plugin, |
91
|
|
|
|
|
|
|
" is applicable for base ", |
92
|
|
|
|
|
|
|
"'$self->{target}->{file_base}'"; |
93
|
2
|
50
|
|
|
|
26
|
if($plugin->applicable($self->{target})) { |
94
|
2
|
|
|
|
|
7
|
DEBUG ref($plugin), " accepted"; |
95
|
2
|
|
|
|
|
15
|
return $plugin; |
96
|
|
|
|
|
|
|
} else { |
97
|
0
|
|
|
|
|
0
|
DEBUG ref($plugin), " rejected"; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# Hmm ... no volunteers yet. |
103
|
6
|
100
|
|
|
|
25
|
return undef unless $self->{cold_calls}; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# Go from door to door and check if some plugin wants to |
106
|
|
|
|
|
|
|
# handle it. Set the 'cold_call' flag to let the plugin know |
107
|
|
|
|
|
|
|
# about our desparate move. |
108
|
5
|
|
|
|
|
10
|
for my $plugin (@{$self->{plugins}}) { |
|
5
|
|
|
|
|
17
|
|
109
|
39
|
|
|
|
|
312
|
DEBUG "Checking if ", ref $plugin, " is applicable for ", |
110
|
|
|
|
|
|
|
"file '$self->{target}->{path}' (cold call)"; |
111
|
39
|
100
|
|
|
|
373
|
if($plugin->applicable($self->{target}, 1)) { |
112
|
3
|
|
|
|
|
8
|
DEBUG "Cold call accepted"; |
113
|
3
|
|
|
|
|
19
|
return $plugin; |
114
|
|
|
|
|
|
|
} else { |
115
|
36
|
|
|
|
|
74
|
DEBUG "Cold call rejected"; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
2
|
|
|
|
|
16
|
return undef; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
########################################### |
123
|
|
|
|
|
|
|
sub guess_type { |
124
|
|
|
|
|
|
|
########################################### |
125
|
0
|
|
|
0
|
1
|
0
|
my($self, $target) = @_; |
126
|
|
|
|
|
|
|
|
127
|
0
|
0
|
|
|
|
0
|
if(ref $target) { |
128
|
0
|
|
|
|
|
0
|
$self->{target} = $target; |
129
|
|
|
|
|
|
|
} else { |
130
|
0
|
|
|
|
|
0
|
$self->{target} = File::Comments::Target->new(path => $target); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
0
|
my $plugin = $self->find_plugin(); |
134
|
|
|
|
|
|
|
|
135
|
0
|
0
|
|
|
|
0
|
if(! defined $plugin) { |
136
|
0
|
|
|
|
|
0
|
ERROR "No plugin found to handle $target"; |
137
|
0
|
|
|
|
|
0
|
return undef; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
0
|
return $plugin->type(); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
########################################### |
144
|
|
|
|
|
|
|
sub comments { |
145
|
|
|
|
|
|
|
########################################### |
146
|
14
|
|
|
14
|
1
|
1455717
|
my($self, $target) = @_; |
147
|
|
|
|
|
|
|
|
148
|
14
|
|
|
|
|
70
|
return $_[0]->dispatch($target, "comments"); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
########################################### |
152
|
|
|
|
|
|
|
sub stripped { |
153
|
|
|
|
|
|
|
########################################### |
154
|
4
|
|
|
4
|
1
|
8837
|
my($self, $target) = @_; |
155
|
|
|
|
|
|
|
|
156
|
4
|
|
|
|
|
21
|
return $_[0]->dispatch($target, "stripped"); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
########################################### |
160
|
|
|
|
|
|
|
sub dispatch { |
161
|
|
|
|
|
|
|
########################################### |
162
|
18
|
|
|
18
|
0
|
42
|
my($self, $target, $function) = @_; |
163
|
|
|
|
|
|
|
|
164
|
18
|
50
|
|
|
|
72
|
if(ref $target) { |
165
|
0
|
|
|
|
|
0
|
$self->{target} = $target; |
166
|
|
|
|
|
|
|
} else { |
167
|
18
|
|
|
|
|
129
|
$self->{target} = File::Comments::Target->new(path => $target); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
18
|
|
|
|
|
122
|
my $plugin = $self->find_plugin(); |
171
|
|
|
|
|
|
|
|
172
|
18
|
100
|
|
|
|
66
|
if(! defined $plugin) { |
173
|
3
|
100
|
|
|
|
14
|
if($self->{default_plugin}) { |
174
|
1
|
|
|
|
|
3
|
$plugin = $self->{default_plugin}; |
175
|
|
|
|
|
|
|
} else { |
176
|
2
|
|
|
|
|
16
|
ERROR "Type of $target couldn't be determined"; |
177
|
|
|
|
|
|
|
# Just return and empty list |
178
|
2
|
|
|
|
|
20
|
return undef; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
16
|
|
|
|
|
102
|
DEBUG "Calling ", ref $plugin, |
183
|
|
|
|
|
|
|
" to handle $self->{target}->{path}"; |
184
|
|
|
|
|
|
|
|
185
|
16
|
|
|
|
|
226
|
return $plugin->$function($self->{target}); |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
########################################### |
189
|
|
|
|
|
|
|
sub register_suffix { |
190
|
|
|
|
|
|
|
########################################### |
191
|
286
|
|
|
286
|
0
|
388
|
my($self, $suffix, $plugin_obj) = @_; |
192
|
|
|
|
|
|
|
|
193
|
286
|
|
|
|
|
893
|
DEBUG "Registering ", ref $plugin_obj, |
194
|
|
|
|
|
|
|
" as a handler for suffix $suffix"; |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
# Could be more than one, line them up |
197
|
286
|
|
|
|
|
1612
|
push @{$self->{suffixes}->{$suffix}}, $plugin_obj; |
|
286
|
|
|
|
|
1345
|
|
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
########################################### |
201
|
|
|
|
|
|
|
sub suffix_registered { |
202
|
|
|
|
|
|
|
########################################### |
203
|
1
|
|
|
1
|
1
|
5
|
my($self, $suffix) = @_; |
204
|
|
|
|
|
|
|
|
205
|
1
|
|
|
|
|
8
|
return exists $self->{suffixes}->{$suffix}; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
########################################### |
209
|
|
|
|
|
|
|
sub register_base { |
210
|
|
|
|
|
|
|
########################################### |
211
|
22
|
|
|
22
|
0
|
40
|
my($self, $base, $plugin_obj) = @_; |
212
|
|
|
|
|
|
|
|
213
|
22
|
|
|
|
|
104
|
DEBUG "Registering ", ref $plugin_obj, |
214
|
|
|
|
|
|
|
" as a handler for base $base"; |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
# Could be more than one, line them up |
217
|
22
|
|
|
|
|
129
|
push @{$self->{bases}->{$base}}, $plugin_obj; |
|
22
|
|
|
|
|
143
|
|
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
################################################## |
221
|
|
|
|
|
|
|
# Poor man's Class::Struct |
222
|
|
|
|
|
|
|
################################################## |
223
|
|
|
|
|
|
|
sub make_accessor { |
224
|
|
|
|
|
|
|
################################################## |
225
|
54
|
|
|
54
|
0
|
142
|
my($package, $name) = @_; |
226
|
|
|
|
|
|
|
|
227
|
9
|
|
|
9
|
|
10897
|
no strict qw(refs); |
|
9
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
1138
|
|
228
|
|
|
|
|
|
|
|
229
|
54
|
|
|
|
|
176
|
my $code = <
|
230
|
|
|
|
|
|
|
*{"$package\\::$name"} = sub { |
231
|
|
|
|
|
|
|
my(\$self, \$value) = \@_; |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
if(defined \$value) { |
234
|
|
|
|
|
|
|
\$self->{$name} = \$value; |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
if(exists \$self->{$name}) { |
237
|
|
|
|
|
|
|
return (\$self->{$name}); |
238
|
|
|
|
|
|
|
} else { |
239
|
|
|
|
|
|
|
return ""; |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
EOT |
243
|
54
|
50
|
|
|
|
66
|
if(! defined *{"$package\::$name"}) { |
|
54
|
|
|
|
|
327
|
|
244
|
54
|
50
|
|
0
|
|
6372
|
eval $code or die "$@"; |
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
########################################### |
249
|
|
|
|
|
|
|
package File::Comments::Target; |
250
|
|
|
|
|
|
|
########################################### |
251
|
9
|
|
|
9
|
|
54
|
use Sysadm::Install qw(:all); |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
101
|
|
252
|
9
|
|
|
9
|
|
3358
|
use File::Basename; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
750
|
|
253
|
9
|
|
|
9
|
|
159
|
use Log::Log4perl qw(:easy); |
|
9
|
|
|
|
|
20
|
|
|
9
|
|
|
|
|
86
|
|
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
########################################### |
256
|
|
|
|
|
|
|
sub new { |
257
|
|
|
|
|
|
|
########################################### |
258
|
18
|
|
|
18
|
|
60
|
my($class, %options) = @_; |
259
|
|
|
|
|
|
|
|
260
|
18
|
|
|
|
|
136
|
my $self = { |
261
|
|
|
|
|
|
|
path => undef, |
262
|
|
|
|
|
|
|
dir => undef, |
263
|
|
|
|
|
|
|
file_name => undef, |
264
|
|
|
|
|
|
|
file_base => undef, |
265
|
|
|
|
|
|
|
content => undef, |
266
|
|
|
|
|
|
|
suffix => undef, |
267
|
|
|
|
|
|
|
%options, |
268
|
|
|
|
|
|
|
}; |
269
|
|
|
|
|
|
|
|
270
|
18
|
|
|
|
|
121
|
bless $self, $class; |
271
|
|
|
|
|
|
|
|
272
|
18
|
|
|
|
|
132
|
$self->load($self->{path}, $self->{content}); |
273
|
|
|
|
|
|
|
|
274
|
18
|
|
|
|
|
203
|
return $self; |
275
|
|
|
|
|
|
|
} |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
########################################### |
278
|
|
|
|
|
|
|
sub load { |
279
|
|
|
|
|
|
|
########################################### |
280
|
18
|
|
|
18
|
|
38
|
my($self, $path, $content) = @_; |
281
|
|
|
|
|
|
|
|
282
|
18
|
50
|
|
|
|
104
|
$self->{content} = $content unless $content; |
283
|
18
|
|
|
|
|
38
|
$self->{path} = $path; |
284
|
18
|
50
|
|
|
|
127
|
$self->{content} = slurp $path unless defined $self->{content}; |
285
|
|
|
|
|
|
|
|
286
|
18
|
|
|
|
|
3495
|
$self->{file_name} = basename($path); |
287
|
|
|
|
|
|
|
|
288
|
18
|
|
|
|
|
545
|
$self->{dir} = dirname($path); |
289
|
18
|
|
|
|
|
38
|
$self->{suffix} = undef; |
290
|
18
|
|
|
|
|
42
|
$self->{file_base} = $self->{file_name}; |
291
|
|
|
|
|
|
|
|
292
|
18
|
100
|
|
|
|
108
|
if(index($self->{file_name}, ".") >= 0) { |
293
|
12
|
|
|
|
|
88
|
($self->{file_base}, $self->{suffix}) = |
294
|
|
|
|
|
|
|
($self->{file_name} =~ m#(.+)(\.[^.]*$)#); |
295
|
|
|
|
|
|
|
} |
296
|
|
|
|
|
|
|
|
297
|
18
|
|
|
|
|
65
|
DEBUG "Loaded file path=", def($path), |
298
|
|
|
|
|
|
|
" name=", def($self->{file_name}), |
299
|
|
|
|
|
|
|
" dir=", def($self->{dir}), |
300
|
|
|
|
|
|
|
" suffix=", def($self->{suffix}), |
301
|
|
|
|
|
|
|
" base=", def($self->{file_base}); |
302
|
|
|
|
|
|
|
} |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
########################################### |
305
|
|
|
|
|
|
|
sub def { |
306
|
|
|
|
|
|
|
########################################### |
307
|
90
|
100
|
|
90
|
|
373
|
return $_[0] if defined $_[0]; |
308
|
6
|
|
|
|
|
18
|
return "**undef**"; |
309
|
|
|
|
|
|
|
} |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
File::Comments::make_accessor("File::Comments::Target", $_) |
312
|
|
|
|
|
|
|
for qw(path file_name file_base content suffix dir); |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
1; |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
__END__ |