| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Filter::Uncomment ; |
|
3
|
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
31838
|
use strict; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
78
|
|
|
5
|
2
|
|
|
2
|
|
11
|
use warnings ; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
80
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN |
|
8
|
|
|
|
|
|
|
{ |
|
9
|
2
|
|
|
2
|
|
9
|
use vars qw ($VERSION @EXPORT_OK %EXPORT_TAGS); |
|
|
2
|
|
|
|
|
5958
|
|
|
|
2
|
|
|
|
|
207
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
4
|
$VERSION = '0.03'; |
|
12
|
2
|
|
|
|
|
3
|
@EXPORT_OK = qw (); |
|
13
|
2
|
|
|
|
|
49
|
%EXPORT_TAGS = (); |
|
14
|
|
|
|
|
|
|
} |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
17
|
|
|
|
|
|
|
|
|
18
|
2
|
|
|
2
|
|
1982
|
use English qw( -no_match_vars ) ; |
|
|
2
|
|
|
|
|
7755
|
|
|
|
2
|
|
|
|
|
12
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
2
|
|
|
2
|
|
2682
|
use Readonly ; |
|
|
2
|
|
|
|
|
7235
|
|
|
|
2
|
|
|
|
|
143
|
|
|
21
|
|
|
|
|
|
|
Readonly my $EMPTY_STRING => q{} ; |
|
22
|
|
|
|
|
|
|
|
|
23
|
2
|
|
|
2
|
|
14
|
use Carp qw(carp croak confess) ; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
120
|
|
|
24
|
2
|
|
|
2
|
|
3264
|
use Filter::Simple ; |
|
|
2
|
|
|
|
|
68940
|
|
|
|
2
|
|
|
|
|
17
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 NAME |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Filter::Uncomment - Efficiently uncomment sections of your code |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
#~ use Filter::Uncomment qw(multi single) ; |
|
35
|
|
|
|
|
|
|
#~ use Filter::Uncomment qw(multi) ; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
use Filter::Uncomment |
|
38
|
|
|
|
|
|
|
GROUPS => |
|
39
|
|
|
|
|
|
|
{ |
|
40
|
|
|
|
|
|
|
multi => ['multi_line', 'multi line with spaces'] , |
|
41
|
|
|
|
|
|
|
single => ['single_line', 'single line with spaces'] , |
|
42
|
|
|
|
|
|
|
all => |
|
43
|
|
|
|
|
|
|
[ |
|
44
|
|
|
|
|
|
|
'multi_line', 'multi line with spaces', |
|
45
|
|
|
|
|
|
|
'single_line', 'single line with spaces', |
|
46
|
|
|
|
|
|
|
] , |
|
47
|
|
|
|
|
|
|
}; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$> perl -MFilter::Uncomment=multi test.pl |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
This module write code that you want be active in only certain circumstances. |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 DOCUMENTATION |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Contrast: |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
#example 1 |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
for my $variable (1 .. $lots) |
|
62
|
|
|
|
|
|
|
{ |
|
63
|
|
|
|
|
|
|
## debug Debug($variable) ; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
DoSomethingWith($value) ; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
with |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# example 2 |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
for my $variable (1 .. $lots) |
|
73
|
|
|
|
|
|
|
{ |
|
74
|
|
|
|
|
|
|
Debug($variable) if($debug) ; |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
DoSomethingWith($value) ; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
In example #2, you will always pay for checking the $debug variable. This might be significant in a |
|
80
|
|
|
|
|
|
|
very tight loop or when you have lots of sections you comment out. |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
B is a source code filter that will uncomment sections of perl code only on demand. |
|
83
|
|
|
|
|
|
|
The uncommenting is done before compile time, you pay only once for it at the program load time. |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Example #1 would effectively become: |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
#example 1, uncommented |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
for my $variable (1 .. $lots) |
|
90
|
|
|
|
|
|
|
{ |
|
91
|
|
|
|
|
|
|
Debug($variable) ; |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
DoSomethingWith($value) ; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
B can uncomment single line perl comments, or multiline perl comments. |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
## debug Debug($variable) ; |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=for flag |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
PerlCode() ; |
|
103
|
|
|
|
|
|
|
MorePerlCode() ; |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
## tag_can_be_a_single_word HereIsTheCode() ; |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
## or it can be a multiple wors separated by spaces HereIsTheCode() ; |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 Defining tags |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
use Filter::Uncomment |
|
115
|
|
|
|
|
|
|
GROUPS => |
|
116
|
|
|
|
|
|
|
{ |
|
117
|
|
|
|
|
|
|
# name # elements for each group |
|
118
|
|
|
|
|
|
|
multi => ['multi_line', 'multi line with spaces'] , |
|
119
|
|
|
|
|
|
|
single => ['single_line', 'single line with spaces'] , |
|
120
|
|
|
|
|
|
|
} ; |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 Uncommenting |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Uncommenting is most often done on the command line but can also be done from a module or your script. |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
From the command line: |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
perl -MFilter::Uncomment=multi script.pl |
|
129
|
|
|
|
|
|
|
perl -MFilter::Uncomment=multi -MFilter::Uncomment=single script.pl |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
From a module or script; |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
use Filter::Uncomment qw(multi single) ; |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
my (%activated, $setup) ; |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub import |
|
148
|
|
|
|
|
|
|
{ |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 import |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
This is automatically called for you by Perl |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=cut |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
my ($my_name, $argument_type, $argument_value, @other) = @_ ; |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
if(defined $argument_type) |
|
159
|
|
|
|
|
|
|
{ |
|
160
|
|
|
|
|
|
|
$setup = undef ; |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
if($argument_type =~ /^GROUPS$/sxm) |
|
163
|
|
|
|
|
|
|
{ |
|
164
|
|
|
|
|
|
|
unless(defined $argument_value && 'HASH' eq ref $argument_value) |
|
165
|
|
|
|
|
|
|
{ |
|
166
|
|
|
|
|
|
|
confess "Filter::Uncomment bad 'GROUPS' arguments!\n" ; |
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
$setup = $argument_value ; |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
else |
|
172
|
|
|
|
|
|
|
{ |
|
173
|
|
|
|
|
|
|
my @groups = defined $argument_value |
|
174
|
|
|
|
|
|
|
? ($argument_type, $argument_value, @other) |
|
175
|
|
|
|
|
|
|
: ($argument_type) ; |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
@activated{@groups} = (1 .. @groups) ; |
|
178
|
|
|
|
|
|
|
} |
|
179
|
|
|
|
|
|
|
} |
|
180
|
|
|
|
|
|
|
else |
|
181
|
|
|
|
|
|
|
{ |
|
182
|
|
|
|
|
|
|
carp "Filter::Uncomment needs arguments!\n" ; |
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
return(1) ; |
|
186
|
|
|
|
|
|
|
} |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
FILTER |
|
191
|
|
|
|
|
|
|
{ |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head2 FILTER |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
This is automatically called for you by Perl |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=cut |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
if($setup) |
|
200
|
|
|
|
|
|
|
{ |
|
201
|
|
|
|
|
|
|
my $coumpound_regex |
|
202
|
|
|
|
|
|
|
= join q[|], |
|
203
|
|
|
|
|
|
|
map {s{\ }{\\\ }sxgm ; $_ ;} # so we can use x option for regex |
|
204
|
|
|
|
|
|
|
map{@{$setup->{$_}}} # elements in the activated groups |
|
205
|
|
|
|
|
|
|
grep {exists $activated{$_}} # only activated groups |
|
206
|
|
|
|
|
|
|
keys %{$setup} ; # all the groups |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
#~ print "=> $coumpound_regex\n" ; |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
s{ |
|
211
|
|
|
|
|
|
|
^=for\s+ # a pod =for tag |
|
212
|
|
|
|
|
|
|
(?:$coumpound_regex)\s+ # tag and at least a space |
|
213
|
|
|
|
|
|
|
(.*?) # pod section content |
|
214
|
|
|
|
|
|
|
=cut # end of pod section |
|
215
|
|
|
|
|
|
|
} |
|
216
|
|
|
|
|
|
|
# section position in your code is kept, line number in errors will be right |
|
217
|
|
|
|
|
|
|
{ |
|
218
|
|
|
|
|
|
|
$1 # keep only pod section content |
|
219
|
|
|
|
|
|
|
}xgsm ; |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
s{ |
|
222
|
|
|
|
|
|
|
\#\# # two octopods |
|
223
|
|
|
|
|
|
|
(?:$coumpound_regex)\s+ # tag and at least a space |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
{ |
|
226
|
|
|
|
|
|
|
# replace with nothing |
|
227
|
|
|
|
|
|
|
}xgsm ; |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
} |
|
230
|
|
|
|
|
|
|
} ; |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
1 ; |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
None so far. |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head1 AUTHOR |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
Khemir Nadim ibn Hamouda |
|
243
|
|
|
|
|
|
|
CPAN ID: NKH |
|
244
|
|
|
|
|
|
|
mailto:nadim@khemir.net |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
This program is free software; you can redistribute |
|
249
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=head1 SUPPORT |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
perldoc Filter::Uncomment |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
You can also look for information at: |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=over 4 |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
L |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
Please report any bugs or feature requests to L . |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
We will be notified, and then you'll automatically be notified of progress on |
|
270
|
|
|
|
|
|
|
your bug as we make changes. |
|
271
|
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=item * Search CPAN |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
L |
|
275
|
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=back |
|
277
|
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
279
|
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
The excellent L. |
|
281
|
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=cut |