line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Filter::Unpound; |
2
|
|
|
|
|
|
|
# Simplest version, just this line: |
3
|
|
|
|
|
|
|
# use Filter::Simple sub { s/^\s*#!#//gsm; }; |
4
|
1
|
|
|
1
|
|
718
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
346
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
my @keywords; |
7
|
|
|
|
|
|
|
my $CmtRE; |
8
|
|
|
|
|
|
|
my ($code,$all); |
9
|
|
|
|
|
|
|
our $VERSION=1.1; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub import { |
12
|
|
|
|
|
|
|
my $thispack=shift; |
13
|
|
|
|
|
|
|
@keywords=(grep !/[^A-Za-z0-9_]/, @_); # Only single words, no metachars, ok? |
14
|
|
|
|
|
|
|
$CmtRE=join q(|),@keywords; |
15
|
|
|
|
|
|
|
# Only filter if things are specified, otherwise we'll remove way too |
16
|
|
|
|
|
|
|
# many comments. |
17
|
|
|
|
|
|
|
if ($CmtRE) { |
18
|
|
|
|
|
|
|
$code=sub { |
19
|
|
|
|
|
|
|
# Shorthand for print |
20
|
|
|
|
|
|
|
s/#[A-Za-z0-9_#]*\b(?:${CmtRE})\b[A-Za-z0-9_#]*>\s+(.*)$/print <
|
21
|
|
|
|
|
|
|
s/#[A-Za-z0-9_#]*\b(?:${CmtRE})\b[A-Za-z0-9_#]*#\s+//g; |
22
|
|
|
|
|
|
|
}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
$all=sub { |
25
|
|
|
|
|
|
|
s/^(?:${CmtRE})$//gms; |
26
|
|
|
|
|
|
|
s/^\s*;\s*(?:(?:my\s+)?\$\w+\s*=\s*)?<<\s*'(?:$CmtRE)'\s*(?:#.*)?$//gms; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
else { |
30
|
|
|
|
|
|
|
$code=sub { ; }; |
31
|
|
|
|
|
|
|
$all=sub { ; }; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
# Allow access to keywords, commentre... read-only, you shouldn't try to set. |
35
|
0
|
|
|
0
|
0
|
|
sub keywords () { return @keywords; } |
36
|
0
|
|
|
0
|
0
|
|
sub CmtRE () { return $CmtRE; } |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
1
|
|
2042
|
use Filter::Simple; |
|
1
|
|
|
|
|
45017
|
|
|
1
|
|
|
|
|
11
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# As I discovered with pain, since I was working on a v5.8 |
41
|
|
|
|
|
|
|
# installation, Filter::Simple has a bug in FILTER_ONLY in v5.8, but |
42
|
|
|
|
|
|
|
# not in v5.10 (I don't know about v5.9). So versions below v5.10 |
43
|
|
|
|
|
|
|
# will get a plain FILTER. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
if ($] >= 5.010) { |
46
|
|
|
|
|
|
|
FILTER_ONLY |
47
|
|
|
|
|
|
|
code => sub { &$code }, |
48
|
|
|
|
|
|
|
all => sub { &$all }; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
else { |
51
|
|
|
|
|
|
|
FILTER { |
52
|
|
|
|
|
|
|
&$code; |
53
|
|
|
|
|
|
|
&$all; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
__END__ |