line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Goo::Thing::pm::Perl5ModuleInspector; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
############################################################################### |
6
|
|
|
|
|
|
|
# Nigel Hamilton |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# Copyright Nigel Hamilton 2003 |
9
|
|
|
|
|
|
|
# All rights reserved |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# Author: Nigel Hamilton |
12
|
|
|
|
|
|
|
# Filename: Perl5ModuleInspector.pm |
13
|
|
|
|
|
|
|
# Description: Generate documentation on a perl file based on documentation |
14
|
|
|
|
|
|
|
# standards like this file as an example |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
# Date Change |
17
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------- |
18
|
|
|
|
|
|
|
# 22/3/2003 Version 1 |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
############################################################################## |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
23
|
1
|
|
|
1
|
|
7
|
use Goo::Object; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
23
|
|
24
|
1
|
|
|
1
|
|
7
|
use Goo::FileUtilities; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
834
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# use ModuleLocations; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our @ISA = ("Goo::Object"); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
############################################################################## |
32
|
|
|
|
|
|
|
# |
33
|
|
|
|
|
|
|
# new - constructor |
34
|
|
|
|
|
|
|
# |
35
|
|
|
|
|
|
|
############################################################################## |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub new { |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
0
|
1
|
|
my ($class, $filename) = @_; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $this = $class->SUPER::new(); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# append filename to the end if need be |
44
|
|
|
|
|
|
|
# if ($filename !~ /\.pm$/) { $filename .= ".pm"; } |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
unless ($filename) { die("No filename to generate documentation."); } |
|
0
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
$this->{filename} = $filename; # the full filename + path |
49
|
0
|
|
|
|
|
|
$this->{program} = Goo::FileUtilities::get_file_as_string($filename); |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
return $this; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
############################################################################## |
57
|
|
|
|
|
|
|
# |
58
|
|
|
|
|
|
|
# get_program - return the fully slurped file |
59
|
|
|
|
|
|
|
# |
60
|
|
|
|
|
|
|
############################################################################## |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub get_program { |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
0
|
1
|
|
my ($this) = @_; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
return $this->{program}; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
############################################################################## |
72
|
|
|
|
|
|
|
# |
73
|
|
|
|
|
|
|
# get_uses_list - return a list of all the modules that this script uses |
74
|
|
|
|
|
|
|
# |
75
|
|
|
|
|
|
|
############################################################################## |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub get_uses_list { |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
0
|
1
|
|
my ($this) = @_; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my @modules = $this->{program} =~ m/^use\s+([\w\:]+)/mg; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# don't include strict or other pragmas |
84
|
0
|
|
|
|
|
|
return grep { $_ !~ /(strict|^[a-z])/ } @modules; |
|
0
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
############################################################################## |
90
|
|
|
|
|
|
|
# |
91
|
|
|
|
|
|
|
# get_methods - return a list of methods in the script |
92
|
|
|
|
|
|
|
# |
93
|
|
|
|
|
|
|
############################################################################## |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub get_methods { |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
0
|
1
|
|
my ($this) = @_; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
my @methods = $this->{program} =~ m/sub\s+(\w+)/mgi; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# add a main method |
102
|
0
|
|
|
|
|
|
unshift(@methods, "main"); |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
return @methods; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
############################################################################## |
110
|
|
|
|
|
|
|
# |
111
|
|
|
|
|
|
|
# get_method_signature - return a signature for a method |
112
|
|
|
|
|
|
|
# |
113
|
|
|
|
|
|
|
############################################################################## |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub get_method_signature { |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
0
|
1
|
|
my ($this, $method) = @_; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# hard wire a description for the special main method |
120
|
0
|
0
|
|
|
|
|
return "Main body" if ($method eq "main"); |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
return $this->{signatures}->{$method}; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
############################################################################## |
128
|
|
|
|
|
|
|
# |
129
|
|
|
|
|
|
|
# calculate_method_signatures - return a hash of method signatures |
130
|
|
|
|
|
|
|
# keyed on method name |
131
|
|
|
|
|
|
|
# |
132
|
|
|
|
|
|
|
############################################################################## |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub calculate_method_signatures { |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
0
|
1
|
|
my ($this) = @_; |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
$this->{signatures} = {}; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# there is always a main method |
141
|
0
|
|
|
|
|
|
$this->{signatures}->{main} = "use strict"; |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
foreach my $method ($this->get_methods()) { |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# match the method and signature |
146
|
0
|
|
|
|
|
|
$this->{program} =~ m/sub\s+$method\s+\{\s+my\s+\((.*?)\)/is; |
147
|
0
|
|
|
|
|
|
$this->{signatures}->{$method} = $1; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
############################################################################## |
155
|
|
|
|
|
|
|
# |
156
|
|
|
|
|
|
|
# get_full_path - return the full path |
157
|
|
|
|
|
|
|
# |
158
|
|
|
|
|
|
|
############################################################################## |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub get_full_path { |
161
|
|
|
|
|
|
|
|
162
|
0
|
|
|
0
|
1
|
|
my ($this) = @_; |
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
return $this->{filename}; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
############################################################################## |
170
|
|
|
|
|
|
|
# |
171
|
|
|
|
|
|
|
# get_filename - return the filename |
172
|
|
|
|
|
|
|
# |
173
|
|
|
|
|
|
|
############################################################################## |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub get_filename { |
176
|
|
|
|
|
|
|
|
177
|
0
|
|
|
0
|
1
|
|
my ($this) = @_; |
178
|
|
|
|
|
|
|
|
179
|
0
|
|
|
|
|
|
$this->{filename} =~ m|.*/(.*?)$|; |
180
|
|
|
|
|
|
|
|
181
|
0
|
|
|
|
|
|
return $1; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
############################################################################## |
187
|
|
|
|
|
|
|
# |
188
|
|
|
|
|
|
|
# has_constructor - does the program have a constructor? |
189
|
|
|
|
|
|
|
# |
190
|
|
|
|
|
|
|
############################################################################## |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
sub has_constructor { |
193
|
|
|
|
|
|
|
|
194
|
0
|
|
|
0
|
1
|
|
my ($this) = @_; |
195
|
|
|
|
|
|
|
|
196
|
0
|
|
|
|
|
|
my @constructor = grep { $_ eq "new" } $this->get_methods(); |
|
0
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
return scalar(@constructor) == 1; |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
############################################################################## |
204
|
|
|
|
|
|
|
# |
205
|
|
|
|
|
|
|
# get_matching_line_number - return the number of the line that matches |
206
|
|
|
|
|
|
|
# |
207
|
|
|
|
|
|
|
############################################################################## |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub get_matching_line_number { |
210
|
|
|
|
|
|
|
|
211
|
0
|
|
|
0
|
1
|
|
my ($this, $regex) = @_; |
212
|
|
|
|
|
|
|
|
213
|
0
|
|
|
|
|
|
my @lines = split(/\n/, $this->{program}); |
214
|
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
|
my $linecount = 0; |
216
|
|
|
|
|
|
|
|
217
|
0
|
|
|
|
|
|
foreach my $line (@lines) { |
218
|
|
|
|
|
|
|
|
219
|
0
|
|
|
|
|
|
$linecount++; |
220
|
|
|
|
|
|
|
|
221
|
0
|
0
|
|
|
|
|
if ($line =~ /$regex/) { |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
# add 5 to get into the body of the method |
224
|
0
|
|
|
|
|
|
return $linecount + 5; |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
############################################################################## |
233
|
|
|
|
|
|
|
# |
234
|
|
|
|
|
|
|
# get_author - return the name of the author |
235
|
|
|
|
|
|
|
# |
236
|
|
|
|
|
|
|
############################################################################## |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
sub get_author { |
239
|
|
|
|
|
|
|
|
240
|
0
|
|
|
0
|
1
|
|
my ($this) = @_; |
241
|
|
|
|
|
|
|
|
242
|
0
|
|
|
|
|
|
$this->{program} =~ m/Author:\s+(\w+)\s+(\w+)/; |
243
|
|
|
|
|
|
|
|
244
|
0
|
|
|
|
|
|
return $1 . " " . $2; |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
1; |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
__END__ |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head1 NAME |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Goo::Thing::pm::Perl5ModuleInspector - Inspect the DOM of a Perl5 module |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=head1 SYNOPSIS |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
use Goo::Thing::pm::Perl5ModuleInspector; |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=head1 DESCRIPTION |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=head1 METHODS |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=over |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=item new |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
constructor |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=item get_program |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
return the fully slurped file |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=item get_uses_list |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
return a list of all the modules that this script uses |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=item get_methods |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
return a list of methods in the script |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=item get_method_signature |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
return a signature for a method |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=item calculate_method_signatures |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
return a hash of method signatures |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
=item get_full_path |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
return the full path |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
=item get_filename |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
return the filename |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
=item get_description |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
get the module description |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=item has_constructor |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
does the program have a constructor? |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
=item get_matching_line_number |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
return the number of the line that matches |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
=item get_author |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
return the name of the author |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
=back |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
=head1 AUTHOR |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
Nigel Hamilton <nigel@trexy.com> |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
=head1 SEE ALSO |
326
|
|
|
|
|
|
|
|