line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Str::Filter; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
2482
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
118
|
|
4
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
158
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
22
|
use base qw(Exporter); |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
286
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
2745
|
use HTML::Strip; |
|
3
|
|
|
|
|
242479
|
|
|
3
|
|
|
|
|
2021
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our (@EXPORT_OK, %EXPORT_TAGS); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
@EXPORT_OK = qw( |
15
|
|
|
|
|
|
|
filter_leading_whitespace |
16
|
|
|
|
|
|
|
filter_trailing_whitespace |
17
|
|
|
|
|
|
|
filter_collapse_whitespace |
18
|
|
|
|
|
|
|
filter_control_characters |
19
|
|
|
|
|
|
|
filter_ascii_only |
20
|
|
|
|
|
|
|
filter_escape_pipes |
21
|
|
|
|
|
|
|
filter_end_brackets |
22
|
|
|
|
|
|
|
filter_html |
23
|
|
|
|
|
|
|
filter_style_tags |
24
|
|
|
|
|
|
|
); # on demand |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
%EXPORT_TAGS = ( |
27
|
|
|
|
|
|
|
ALL => [ @EXPORT_OK ], |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $stripper = HTML::Strip->new(); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
33
|
|
|
|
|
|
|
sub filter_leading_whitespace { |
34
|
2
|
100
|
|
2
|
1
|
4359
|
return unless $_[0]; |
35
|
1
|
|
|
|
|
4
|
$_[0] =~ s/\A\s+//msx; |
36
|
1
|
|
|
|
|
5
|
return 1; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
40
|
|
|
|
|
|
|
sub filter_trailing_whitespace { |
41
|
2
|
100
|
|
2
|
1
|
11
|
return unless $_[0]; |
42
|
1
|
|
|
|
|
5
|
$_[0] =~ s/\s+\Z//msx; |
43
|
1
|
|
|
|
|
5
|
return 1; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
47
|
|
|
|
|
|
|
sub filter_collapse_whitespace { |
48
|
2
|
100
|
|
2
|
1
|
17
|
return unless $_[0]; |
49
|
1
|
|
|
|
|
4
|
$_[0] =~ s/\s+/ /msxg; |
50
|
1
|
|
|
|
|
4
|
return 1; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
54
|
|
|
|
|
|
|
sub filter_control_characters { |
55
|
2
|
100
|
|
2
|
1
|
13
|
return unless $_[0]; |
56
|
1
|
|
|
|
|
5
|
$_[0] =~ s/[[:cntrl:]]//msxg; |
57
|
1
|
|
|
|
|
4
|
return 1; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
61
|
|
|
|
|
|
|
sub filter_ascii_only { |
62
|
2
|
100
|
|
2
|
1
|
12
|
return unless $_[0]; |
63
|
|
|
|
|
|
|
# substitute non-ascii characters with nuthin |
64
|
1
|
|
|
|
|
5
|
$_[0] =~ s/[^[:ascii:]]//msxg; |
65
|
1
|
|
|
|
|
5
|
return 1; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
69
|
|
|
|
|
|
|
sub filter_escape_pipes { |
70
|
2
|
100
|
|
2
|
1
|
12
|
return unless $_[0]; |
71
|
|
|
|
|
|
|
## no critic qw(ProhibitEscapedMetacharacters) |
72
|
1
|
|
|
|
|
3
|
$_[0] =~ s{\|}{\\|}msxg; |
73
|
|
|
|
|
|
|
## use critic |
74
|
1
|
|
|
|
|
4
|
return 1; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
78
|
|
|
|
|
|
|
sub filter_end_brackets { |
79
|
2
|
100
|
|
2
|
1
|
12
|
return unless $_[0]; |
80
|
1
|
|
|
|
|
4
|
$_[0] =~ s/\]\]//msxg; |
81
|
1
|
|
|
|
|
5
|
return 1; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
85
|
|
|
|
|
|
|
sub filter_html { |
86
|
2
|
100
|
|
2
|
1
|
12
|
return unless $_[0]; |
87
|
1
|
|
|
|
|
7
|
$_[0] = $stripper->parse($_[0]); |
88
|
1
|
|
|
|
|
36
|
$stripper->eof(); |
89
|
1
|
|
|
|
|
6
|
return 1; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
93
|
|
|
|
|
|
|
# this is not full|fool proof. The match between the tags could fail |
94
|
|
|
|
|
|
|
sub filter_style_tags { |
95
|
2
|
100
|
|
2
|
1
|
12
|
return unless $_[0]; |
96
|
|
|
|
|
|
|
## no critic qw(ProhibitUnusualDelimiters) |
97
|
1
|
|
|
|
|
15
|
$_[0] =~ s!<\s*(style)("[^"]*"|'[^']*'|[^'">])*>[^<]+\s*\1\s*>!!msxig; |
98
|
|
|
|
|
|
|
## use critic |
99
|
1
|
|
|
|
|
4
|
return 1; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |