| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# CommentToPod |
|
4
|
|
|
|
|
|
|
# Generate valid Pod header for packages and functions with |
|
5
|
|
|
|
|
|
|
# preceeding comments, like this. (see the source for this file. CommentToPod.pm) |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package App::CommentToPod; |
|
8
|
|
|
|
|
|
|
$App::CommentToPod::VERSION = '0.002'; |
|
9
|
|
|
|
|
|
|
# ABSTRACT: Turns comment above functions to pod. |
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
600
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
25
|
|
|
12
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
33
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
1
|
|
|
|
|
6
|
use Class::Tiny qw(), { |
|
15
|
|
|
|
|
|
|
podfile => "", |
|
16
|
|
|
|
|
|
|
package => "", |
|
17
|
|
|
|
|
|
|
mock_empty => 0, |
|
18
|
1
|
|
|
1
|
|
463
|
}; |
|
|
1
|
|
|
|
|
1510
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub addPod { |
|
22
|
6
|
|
|
6
|
1
|
3527
|
my $self = shift; |
|
23
|
6
|
|
|
|
|
8
|
my $file = shift; |
|
24
|
|
|
|
|
|
|
|
|
25
|
6
|
|
|
|
|
22
|
my @lines = split(/\n/, $file); |
|
26
|
|
|
|
|
|
|
|
|
27
|
6
|
|
|
|
|
9
|
my $c = 0; |
|
28
|
|
|
|
|
|
|
|
|
29
|
6
|
100
|
|
|
|
12
|
if (!$self->gotpod(\@lines)) { |
|
30
|
|
|
|
|
|
|
## add POD header |
|
31
|
5
|
|
|
|
|
10
|
$self->printpod(\@lines); |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
6
|
|
|
|
|
15
|
while ($c < scalar(@lines)) { |
|
35
|
23
|
100
|
100
|
|
|
314
|
if (!$self->package && $lines[$c] =~ /^package/) { |
|
36
|
1
|
|
|
|
|
9
|
$self->{package} = ($lines[$c] =~ m/package\ ([\w\:]+)/)[0] |
|
37
|
|
|
|
|
|
|
} |
|
38
|
23
|
|
|
|
|
130
|
$self->checkForComment(\@lines, \$c); |
|
39
|
23
|
|
|
|
|
82
|
$self->{podfile} .= $lines[$c] . "\n"; |
|
40
|
|
|
|
|
|
|
|
|
41
|
23
|
|
|
|
|
41
|
$c++; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
6
|
|
|
|
|
11
|
return 1; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub gotpod { |
|
49
|
6
|
|
|
6
|
1
|
8
|
my $self = shift; |
|
50
|
6
|
|
|
|
|
6
|
my $lines = shift; |
|
51
|
|
|
|
|
|
|
|
|
52
|
6
|
|
|
|
|
10
|
foreach my $l (@$lines) { |
|
53
|
27
|
100
|
|
|
|
48
|
if ($l =~ m/^=pod/) { |
|
54
|
1
|
|
|
|
|
2
|
return 1; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
} |
|
57
|
5
|
|
|
|
|
9
|
return 0; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub printpod { |
|
62
|
5
|
|
|
5
|
1
|
6
|
my $self = shift; |
|
63
|
5
|
|
|
|
|
5
|
my $lines = shift; |
|
64
|
|
|
|
|
|
|
|
|
65
|
5
|
|
|
|
|
7
|
my $comment = ""; |
|
66
|
5
|
|
|
|
|
6
|
my $c = 0; |
|
67
|
5
|
|
|
|
|
10
|
while ($self->lineIsCommentOrBlank($lines->[$c])) { |
|
68
|
7
|
|
|
|
|
10
|
my $l = $lines->[$c]; |
|
69
|
7
|
|
|
|
|
20
|
$l =~ s/^#/ /g; |
|
70
|
7
|
|
|
|
|
10
|
$comment .= $l . "\n"; |
|
71
|
7
|
|
|
|
|
8
|
$c++; |
|
72
|
7
|
50
|
|
|
|
14
|
last if $c > scalar(@$lines); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
5
|
50
|
|
|
|
13
|
if ($lines->[$c] !~ /^package/) { |
|
76
|
0
|
|
|
|
|
0
|
$self->{podfile} .= $comment; |
|
77
|
0
|
|
|
|
|
0
|
return 0; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
5
|
|
|
|
|
18
|
my $package = ($lines->[$c] =~ m/package\ ([\w\:]+)/)[0]; |
|
81
|
5
|
|
|
|
|
94
|
$self->package($package); |
|
82
|
|
|
|
|
|
|
|
|
83
|
5
|
|
|
|
|
36
|
my $podheader = ""; |
|
84
|
5
|
|
|
|
|
22
|
$podheader .= "=pod\n\n"; |
|
85
|
5
|
|
|
|
|
7
|
$podheader .= "=encoding utf8\n\n"; |
|
86
|
5
|
|
|
|
|
5
|
$podheader .= "=head1 NAME\n\n"; |
|
87
|
5
|
|
|
|
|
7
|
$podheader .= "$package\n\n"; |
|
88
|
5
|
|
|
|
|
5
|
$podheader .= "=head1 SYNOPSIS\n\n"; |
|
89
|
5
|
|
|
|
|
7
|
$podheader .= "$comment\n\n"; |
|
90
|
5
|
|
|
|
|
10
|
$podheader .= "=cut\n\n"; |
|
91
|
|
|
|
|
|
|
|
|
92
|
5
|
|
|
|
|
8
|
$podheader .= "=head2 Methods\n\n"; |
|
93
|
5
|
|
|
|
|
5
|
$podheader .= "=cut\n\n"; |
|
94
|
|
|
|
|
|
|
|
|
95
|
5
|
|
|
|
|
13
|
$self->{podfile} .= $podheader; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub checkForComment { |
|
100
|
23
|
|
|
23
|
0
|
24
|
my $self = shift; |
|
101
|
23
|
|
|
|
|
23
|
my $lines = shift; |
|
102
|
23
|
|
|
|
|
24
|
my $c = shift; |
|
103
|
|
|
|
|
|
|
|
|
104
|
23
|
100
|
|
|
|
46
|
if ($self->lineIsComment($lines->[$$c])) { |
|
105
|
10
|
|
|
|
|
20
|
$self->commentAboveSub($lines, $c); |
|
106
|
10
|
|
|
|
|
12
|
return; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# if mock_empty is enabled, generate a pod stub above |
|
110
|
|
|
|
|
|
|
# undocumented functions |
|
111
|
13
|
50
|
33
|
|
|
168
|
if ($self->mock_empty && $lines->[$$c] =~ m/^sub/){ |
|
112
|
0
|
|
|
|
|
0
|
my $fname = ($lines->[$$c] =~ m/sub\ (\w+)/)[0]; |
|
113
|
0
|
|
|
|
|
0
|
my $comment = "$fname(...) // not documented\n\n"; |
|
114
|
0
|
|
|
|
|
0
|
for(0 .. 1){ |
|
115
|
0
|
|
|
|
|
0
|
$comment .= " " . $lines->[$$c+$_] . "\n"; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
0
|
|
|
|
|
0
|
$comment .= " " . "...\n"; |
|
118
|
0
|
|
|
|
|
0
|
$self->commentToPod( $comment, $fname); |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub commentAboveSub { |
|
123
|
10
|
|
|
10
|
0
|
11
|
my $self = shift; |
|
124
|
10
|
|
|
|
|
10
|
my $lines = shift; |
|
125
|
10
|
|
|
|
|
10
|
my $c = shift; |
|
126
|
|
|
|
|
|
|
|
|
127
|
10
|
|
|
|
|
15
|
my $comment = ""; |
|
128
|
10
|
|
|
|
|
15
|
while ($self->lineIsComment($lines->[$$c])) { |
|
129
|
10
|
|
|
|
|
19
|
$comment .= $lines->[$$c] . "\n"; |
|
130
|
10
|
|
|
|
|
13
|
$$c++; |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
10
|
100
|
|
|
|
22
|
if ($lines->[$$c] !~ /^sub/) { |
|
134
|
7
|
|
|
|
|
12
|
$self->{podfile} .= $comment . "\n"; |
|
135
|
7
|
|
|
|
|
10
|
return 0; |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
3
|
|
|
|
|
9
|
my $fname = ($lines->[$$c] =~ m/sub\ (\w+)/)[0]; |
|
139
|
|
|
|
|
|
|
|
|
140
|
3
|
|
|
|
|
7
|
$self->commentToPod($comment, $fname); |
|
141
|
|
|
|
|
|
|
|
|
142
|
3
|
|
|
|
|
3
|
return 1; |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub lineIsComment { |
|
146
|
54
|
|
|
54
|
0
|
58
|
my $self = shift; |
|
147
|
54
|
|
|
|
|
61
|
my $l = shift; |
|
148
|
54
|
|
|
|
|
125
|
return $l =~ m/^#/; |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub lineIsBlank { |
|
152
|
12
|
|
|
12
|
0
|
14
|
my $self = shift; |
|
153
|
12
|
|
|
|
|
13
|
my $l = shift; |
|
154
|
12
|
|
|
|
|
26
|
return $l eq ''; |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub lineIsCommentOrBlank { |
|
158
|
12
|
|
|
12
|
0
|
15
|
my $self = shift; |
|
159
|
12
|
|
|
|
|
15
|
my $l = shift; |
|
160
|
12
|
100
|
|
|
|
17
|
return 1 if $self->lineIsBlank($l); |
|
161
|
11
|
|
|
|
|
17
|
return $self->lineIsComment($l); |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub commentToPod { |
|
166
|
3
|
|
|
3
|
1
|
4
|
my $self = shift; |
|
167
|
3
|
|
|
|
|
3
|
my $comment = shift; |
|
168
|
3
|
|
|
|
|
4
|
my $functionName = shift; |
|
169
|
|
|
|
|
|
|
|
|
170
|
3
|
|
|
|
|
3
|
my $podcomment = ""; |
|
171
|
3
|
|
|
|
|
3
|
$podcomment .= "=over 12\n\n"; |
|
172
|
3
|
|
|
|
|
6
|
$podcomment .= "=item C<$functionName>\n\n"; |
|
173
|
3
|
|
|
|
|
6
|
foreach my $l (split(/\n/, $comment)) { |
|
174
|
3
|
|
|
|
|
9
|
$l =~ s/^#\s?//g; |
|
175
|
3
|
|
|
|
|
6
|
$podcomment .= $l . "\n"; |
|
176
|
|
|
|
|
|
|
} |
|
177
|
3
|
|
|
|
|
12
|
$podcomment .= "\n=back\n\n=cut\n\n"; |
|
178
|
3
|
|
|
|
|
8
|
$self->{podfile} .= $podcomment; |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
1; |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
__END__ |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=pod |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=encoding UTF-8 |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 NAME |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
App::CommentToPod - Turns comment above functions to pod. |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 VERSION |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
version 0.002 |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
CommentToPod |
|
201
|
|
|
|
|
|
|
Generate valid Pod header for packages and functions with |
|
202
|
|
|
|
|
|
|
preceeding comments, like this. (see the source for this file. CommentToPod.pm) |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head2 Methods |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=over 12 |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=item C<addPod> |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Comments like this, over functions is I<rendered> to B<pod>, via |
|
211
|
|
|
|
|
|
|
L<App::CommentToPod>. Pod syntax is valid, example: |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
This is a code block |
|
214
|
|
|
|
|
|
|
as seen in paragraph over, you could add some pod trics like |
|
215
|
|
|
|
|
|
|
I<rendered> to B<pod>, via L<App::CommentToPod> |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=back |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=over 12 |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=item C<gotpod> |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
check if file got any pod section |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=back |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=over 12 |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=item C<printpod> |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
print pod header. |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=back |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=over 12 |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=item C<commentToPod> |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
commentToPod($comment, $functionName) turns a comment into a pod block. |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=back |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head1 NAME |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
App::CommentToPod |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=head1 AUTHOR |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
Kjell Kvinge <kjell@kvinge.biz> |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
This software is copyright (c) 2019 by Kjell Kvinge. |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
256
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=cut |