| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
########################################### |
|
2
|
|
|
|
|
|
|
# File::Comments::Plugin::Perl |
|
3
|
|
|
|
|
|
|
# 2005, Mike Schilli |
|
4
|
|
|
|
|
|
|
########################################### |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
########################################### |
|
7
|
|
|
|
|
|
|
package File::Comments::Plugin::Perl; |
|
8
|
|
|
|
|
|
|
########################################### |
|
9
|
|
|
|
|
|
|
|
|
10
|
9
|
|
|
9
|
|
10101
|
use strict; |
|
|
9
|
|
|
|
|
20
|
|
|
|
9
|
|
|
|
|
309
|
|
|
11
|
9
|
|
|
9
|
|
50
|
use warnings; |
|
|
9
|
|
|
|
|
19
|
|
|
|
9
|
|
|
|
|
223
|
|
|
12
|
9
|
|
|
9
|
|
46
|
use File::Comments::Plugin; |
|
|
9
|
|
|
|
|
18
|
|
|
|
9
|
|
|
|
|
198
|
|
|
13
|
9
|
|
|
9
|
|
43
|
use Log::Log4perl qw(:easy); |
|
|
9
|
|
|
|
|
19
|
|
|
|
9
|
|
|
|
|
54
|
|
|
14
|
9
|
|
|
9
|
|
6833
|
use Sysadm::Install qw(:all); |
|
|
9
|
|
|
|
|
28
|
|
|
|
9
|
|
|
|
|
97
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
|
17
|
|
|
|
|
|
|
our @ISA = qw(File::Comments::Plugin::Makefile); |
|
18
|
|
|
|
|
|
|
our $USE_PPI = 1; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
########################################### |
|
21
|
|
|
|
|
|
|
sub applicable { |
|
22
|
|
|
|
|
|
|
########################################### |
|
23
|
7
|
|
|
7
|
0
|
17
|
my($self, $target, $cold_call) = @_; |
|
24
|
|
|
|
|
|
|
|
|
25
|
7
|
100
|
|
|
|
26
|
return 1 unless $cold_call; |
|
26
|
|
|
|
|
|
|
|
|
27
|
5
|
100
|
|
|
|
35
|
return 1 if $target->{content} =~ /^#!.*perl\b/; |
|
28
|
|
|
|
|
|
|
|
|
29
|
2
|
|
|
|
|
6
|
return 0; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
########################################### |
|
33
|
|
|
|
|
|
|
sub init { |
|
34
|
|
|
|
|
|
|
########################################### |
|
35
|
11
|
|
|
11
|
0
|
27
|
my($self) = @_; |
|
36
|
|
|
|
|
|
|
|
|
37
|
11
|
|
|
|
|
116
|
$self->register_suffix(".pl"); |
|
38
|
11
|
|
|
|
|
49
|
$self->register_suffix(".pm"); |
|
39
|
11
|
|
|
|
|
39
|
$self->register_suffix(".PM"); |
|
40
|
11
|
|
|
|
|
43
|
$self->register_suffix(".PL"); |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
########################################### |
|
44
|
|
|
|
|
|
|
sub type { |
|
45
|
|
|
|
|
|
|
########################################### |
|
46
|
0
|
|
|
0
|
0
|
0
|
my($self, $target) = @_; |
|
47
|
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
return "perl"; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
##################################################### |
|
52
|
|
|
|
|
|
|
sub comments { |
|
53
|
|
|
|
|
|
|
##################################################### |
|
54
|
4
|
|
|
4
|
0
|
9
|
my($self, $target) = @_; |
|
55
|
|
|
|
|
|
|
|
|
56
|
4
|
|
|
|
|
7
|
my $data = $target->{content}; |
|
57
|
4
|
|
|
|
|
5
|
my @comments; |
|
58
|
|
|
|
|
|
|
|
|
59
|
4
|
100
|
|
|
|
12
|
if($USE_PPI) { |
|
60
|
3
|
|
|
|
|
1253
|
require PPI; |
|
61
|
3
|
|
|
|
|
162562
|
my($end) = ($data =~ /^__END__(.*)/ms); |
|
62
|
3
|
|
|
|
|
17
|
@comments = $self->comments_parse_ppi($target, $data); |
|
63
|
3
|
100
|
|
|
|
33
|
push @comments, $end if defined $end; |
|
64
|
|
|
|
|
|
|
} else { |
|
65
|
1
|
|
|
|
|
9
|
require Pod::Parser; |
|
66
|
1
|
|
|
|
|
3
|
@comments = @{$self->comments_parse_simple($target, $data)}; |
|
|
1
|
|
|
|
|
5
|
|
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
4
|
|
|
|
|
24
|
return \@comments; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
##################################################### |
|
73
|
|
|
|
|
|
|
sub stripped { |
|
74
|
|
|
|
|
|
|
##################################################### |
|
75
|
1
|
|
|
1
|
0
|
3
|
my($self, $target) = @_; |
|
76
|
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
4
|
my $data = $target->{content}; |
|
78
|
1
|
|
|
|
|
5
|
$data =~ s/^__END__(.*)//ms; |
|
79
|
|
|
|
|
|
|
|
|
80
|
1
|
50
|
|
|
|
6
|
if($USE_PPI) { |
|
81
|
1
|
|
|
|
|
8
|
require PPI; |
|
82
|
1
|
|
|
|
|
6
|
my $doc = PPI::Document->new(\$data); |
|
83
|
|
|
|
|
|
|
|
|
84
|
1
|
50
|
|
|
|
2419
|
if($doc) { |
|
85
|
|
|
|
|
|
|
# Remove all that nasty documentation |
|
86
|
1
|
|
|
|
|
11
|
$doc->prune("PPI::Token::Pod"); |
|
87
|
1
|
|
|
|
|
932
|
$doc->prune("PPI::Token::Comment"); |
|
88
|
1
|
|
|
|
|
1071
|
my $stripped = $doc->serialize(); |
|
89
|
1
|
|
|
|
|
206
|
$doc->DESTROY; |
|
90
|
1
|
|
|
|
|
142
|
return $stripped; |
|
91
|
|
|
|
|
|
|
} else { |
|
92
|
|
|
|
|
|
|
# Parsing perl script failed. Just return everything. |
|
93
|
0
|
|
|
|
|
0
|
WARN "Parsing $target->{path} failed"; |
|
94
|
0
|
|
|
|
|
0
|
$doc->DESTROY; |
|
95
|
0
|
|
|
|
|
0
|
return $data; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
0
|
LOGDIE __PACKAGE__, "->stripped() only supported with PPI"; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
##################################################### |
|
103
|
|
|
|
|
|
|
sub comments_parse_ppi { |
|
104
|
|
|
|
|
|
|
##################################################### |
|
105
|
3
|
|
|
3
|
0
|
7
|
my($self, $target, $src) = @_; |
|
106
|
|
|
|
|
|
|
|
|
107
|
3
|
|
|
|
|
34
|
my $doc = PPI::Document->new(\$src); #bar |
|
108
|
3
|
|
|
|
|
8559
|
my @comments = (); |
|
109
|
|
|
|
|
|
|
|
|
110
|
3
|
50
|
|
|
|
14
|
if(!defined $doc) { |
|
111
|
|
|
|
|
|
|
# Parsing perl script failed. Just return everything. |
|
112
|
0
|
|
|
|
|
0
|
WARN "Parsing $target->{path} failed"; |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# Needs to be destroyed explicitely to avaoid memleaks |
|
115
|
0
|
|
|
|
|
0
|
$doc->DESTROY; |
|
116
|
0
|
|
|
|
|
0
|
return $src; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
$doc->find(sub { |
|
120
|
30
|
100
|
100
|
30
|
|
349
|
return if ref($_[1]) ne "PPI::Token::Comment" and |
|
121
|
|
|
|
|
|
|
ref($_[1]) ne "PPI::Token::Pod"; |
|
122
|
14
|
|
|
|
|
37
|
my $line = $_[1]->content(); |
|
123
|
|
|
|
|
|
|
# Delete leading '#' if it's a comment |
|
124
|
14
|
100
|
|
|
|
69
|
$line = substr($line, 1) if ref($_[1]) eq "PPI::Token::Comment"; |
|
125
|
14
|
|
|
|
|
21
|
chomp $line; |
|
126
|
14
|
|
|
|
|
34
|
push @comments, $line; |
|
127
|
3
|
|
|
|
|
30
|
}); |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# Needs to be destroyed explicitely to avaoid memleaks |
|
130
|
3
|
|
|
|
|
46
|
$doc->DESTROY; |
|
131
|
3
|
|
|
|
|
478
|
return @comments; |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
##################################################### |
|
135
|
|
|
|
|
|
|
sub comments_parse_simple { |
|
136
|
|
|
|
|
|
|
##################################################### |
|
137
|
1
|
|
|
1
|
0
|
2
|
my($self, $target, $src) = @_; |
|
138
|
|
|
|
|
|
|
|
|
139
|
1
|
|
|
|
|
14
|
my $comments = $self->extract_hashed_comments($target); |
|
140
|
|
|
|
|
|
|
|
|
141
|
1
|
|
|
|
|
8
|
my $pod = PodExtractor->new(); |
|
142
|
1
|
|
|
|
|
301
|
$pod->parse_from_file($target->{path}); |
|
143
|
1
|
|
|
|
|
2
|
push @$comments, @{$pod->pod_chunks()}; |
|
|
1
|
|
|
|
|
4
|
|
|
144
|
|
|
|
|
|
|
|
|
145
|
1
|
|
|
|
|
39
|
return $comments; |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
########################################### |
|
149
|
|
|
|
|
|
|
package PodExtractor; |
|
150
|
9
|
|
|
9
|
|
11887
|
use Log::Log4perl qw(:easy); |
|
|
9
|
|
|
|
|
20
|
|
|
|
9
|
|
|
|
|
55
|
|
|
151
|
|
|
|
|
|
|
our @ISA = qw(Pod::Parser); |
|
152
|
|
|
|
|
|
|
########################################### |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
########################################### |
|
155
|
|
|
|
|
|
|
sub new { |
|
156
|
|
|
|
|
|
|
########################################### |
|
157
|
1
|
|
|
1
|
|
3
|
my($class) = @_; |
|
158
|
|
|
|
|
|
|
|
|
159
|
1
|
|
|
|
|
3
|
my $self = { chunks => [] }; |
|
160
|
|
|
|
|
|
|
|
|
161
|
1
|
|
|
|
|
2
|
bless $self, $class; |
|
162
|
|
|
|
|
|
|
|
|
163
|
1
|
|
|
|
|
3
|
return $self; |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
########################################### |
|
167
|
|
|
|
|
|
|
sub textblock { |
|
168
|
|
|
|
|
|
|
########################################### |
|
169
|
1
|
|
|
1
|
|
2
|
my ($self, $paragraph, $line_num) = @_; |
|
170
|
|
|
|
|
|
|
|
|
171
|
1
|
|
|
|
|
2
|
push @{$self->{chunks}}, $paragraph; |
|
|
1
|
|
|
|
|
98
|
|
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
|
|
174
|
1
|
|
|
1
|
|
44
|
sub command {} |
|
175
|
0
|
|
|
0
|
|
0
|
sub verbatim {} |
|
176
|
0
|
|
|
0
|
|
0
|
sub interior_sequence {} |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
########################################### |
|
179
|
|
|
|
|
|
|
sub pod_chunks { |
|
180
|
|
|
|
|
|
|
########################################### |
|
181
|
1
|
|
|
1
|
|
2
|
my ($self) = @_; |
|
182
|
|
|
|
|
|
|
|
|
183
|
1
|
|
|
|
|
3
|
return $self->{chunks}; |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
1; |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
__END__ |