line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Plugin::TagRescue; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
217576
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
109
|
|
4
|
2
|
|
|
2
|
|
19294
|
use HTML::Parser 3.08; |
|
2
|
|
|
|
|
45829
|
|
|
2
|
|
|
|
|
1323
|
|
5
|
2
|
|
|
2
|
|
26
|
use vars qw($VERSION); |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
220
|
|
6
|
|
|
|
|
|
|
$VERSION = 0.06; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Template::Plugin; |
9
|
2
|
|
|
2
|
|
11
|
use base qw(Template::Plugin); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
7086
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
23847
|
use vars qw($FILTER_NAME); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
9495
|
|
12
|
|
|
|
|
|
|
$FILTER_NAME = 'html_except_for'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
1
|
|
|
1
|
1
|
69
|
my($self, $context, @args) = @_; |
16
|
1
|
|
33
|
|
|
7
|
my $name = $args[0] || $FILTER_NAME; |
17
|
1
|
|
|
|
|
5
|
$context->define_filter($name, $self->filter_factory, 1); |
18
|
1
|
|
|
|
|
34
|
return $self; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub filter_factory { |
22
|
1
|
|
|
1
|
0
|
4
|
my $self = shift; |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
12
|
my $p = HTML::Parser->new(api_version => 3); |
25
|
1
|
|
|
|
|
74
|
$p->handler(default => \&escape, 'event,text,tagname'); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
return sub { |
28
|
7
|
|
|
7
|
|
35019
|
my ($context, @tags) = @_; |
29
|
7
|
100
|
|
|
|
18
|
@tags = map { ref $_ eq 'ARRAY' ? @{$_} : $_ } @tags; |
|
9
|
|
|
|
|
45
|
|
|
3
|
|
|
|
|
16
|
|
30
|
7
|
|
|
|
|
23
|
reset_vars(@tags); |
31
|
|
|
|
|
|
|
return sub { |
32
|
7
|
|
|
|
|
260
|
$p->parse(shift); |
33
|
7
|
|
|
|
|
64
|
$p->eof; |
34
|
7
|
|
|
|
|
35
|
return get_result(); |
35
|
7
|
|
|
|
|
60
|
}; |
36
|
1
|
|
|
|
|
15
|
}; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
{ |
40
|
|
|
|
|
|
|
my $escape_html = escape_method(); |
41
|
|
|
|
|
|
|
my $result = ''; |
42
|
|
|
|
|
|
|
my @except = (); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub escape { |
45
|
83
|
|
|
83
|
0
|
142
|
my ($event, $text, $tagname) = @_; |
46
|
83
|
|
100
|
|
|
246
|
$tagname ||= ''; |
47
|
83
|
100
|
100
|
|
|
261
|
if ($event eq 'text' or !(grep {/^$tagname$/i} @except)) { |
|
74
|
|
|
|
|
797
|
|
48
|
63
|
|
|
|
|
126
|
$result .= $escape_html->($text); |
49
|
|
|
|
|
|
|
} else { |
50
|
20
|
|
|
|
|
86
|
$result .= $text; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
7
|
|
|
7
|
0
|
15
|
sub reset_vars { $result = ''; @except = @_; } |
|
7
|
|
|
|
|
21
|
|
55
|
7
|
|
|
7
|
0
|
89
|
sub get_result { return $result; } |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub escape_method { |
59
|
2
|
|
|
2
|
0
|
6
|
eval { |
60
|
2
|
|
|
|
|
3634
|
require Apache::Util; |
61
|
0
|
|
|
|
|
0
|
Apache::Util::escape_html(''); |
62
|
|
|
|
|
|
|
}; |
63
|
2
|
50
|
|
|
|
24
|
return \&Apache::Util::escape_html unless $@; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
return sub { |
66
|
63
|
|
|
63
|
|
84
|
my $text = shift; |
67
|
63
|
|
|
|
|
106
|
for ($text) { |
68
|
63
|
|
|
|
|
99
|
s/&/&/g; |
69
|
63
|
|
|
|
|
110
|
s/</g; |
70
|
63
|
|
|
|
|
101
|
s/>/>/g; |
71
|
63
|
|
|
|
|
159
|
s/"/"/g |
72
|
|
|
|
|
|
|
} |
73
|
63
|
|
|
|
|
347
|
return $text; |
74
|
2
|
|
|
|
|
661
|
}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
__END__ |