line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Strip; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require DynaLoader; |
4
|
|
|
|
|
|
|
our @ISA = qw(DynaLoader); |
5
|
|
|
|
|
|
|
our $VERSION = '2.12'; |
6
|
|
|
|
|
|
|
bootstrap HTML::Strip $VERSION; |
7
|
|
|
|
|
|
|
|
8
|
12
|
|
|
12
|
|
766823
|
use 5.008; |
|
12
|
|
|
|
|
181
|
|
9
|
12
|
|
|
12
|
|
62
|
use warnings; |
|
12
|
|
|
|
|
19
|
|
|
12
|
|
|
|
|
334
|
|
10
|
12
|
|
|
12
|
|
60
|
use strict; |
|
12
|
|
|
|
|
22
|
|
|
12
|
|
|
|
|
298
|
|
11
|
|
|
|
|
|
|
|
12
|
12
|
|
|
12
|
|
59
|
use Carp; |
|
12
|
|
|
|
|
20
|
|
|
12
|
|
|
|
|
7854
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $_html_entities_p = eval { require HTML::Entities; 1 }; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my %defaults = ( |
17
|
|
|
|
|
|
|
striptags => [qw( title |
18
|
|
|
|
|
|
|
style |
19
|
|
|
|
|
|
|
script |
20
|
|
|
|
|
|
|
applet )], |
21
|
|
|
|
|
|
|
emit_spaces => 1, |
22
|
|
|
|
|
|
|
emit_newlines => 0, |
23
|
|
|
|
|
|
|
decode_entities => 1, |
24
|
|
|
|
|
|
|
filter => $_html_entities_p ? 'filter_entities' : undef, |
25
|
|
|
|
|
|
|
auto_reset => 0, |
26
|
|
|
|
|
|
|
debug => 0, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new { |
30
|
17
|
|
|
17
|
1
|
23017
|
my $class = shift; |
31
|
17
|
|
|
|
|
126
|
my $obj = _create(); |
32
|
17
|
|
|
|
|
42
|
bless $obj, $class; |
33
|
|
|
|
|
|
|
|
34
|
17
|
|
|
|
|
116
|
my %args = (%defaults, @_); |
35
|
17
|
|
|
|
|
113
|
while( my ($key, $value) = each %args ) { |
36
|
119
|
|
|
|
|
235
|
my $method = "set_${key}"; |
37
|
119
|
50
|
|
|
|
349
|
if( $obj->can($method) ) { |
38
|
119
|
|
|
|
|
443
|
$obj->$method($value); |
39
|
|
|
|
|
|
|
} else { |
40
|
0
|
|
|
|
|
0
|
Carp::carp "Invalid setting '$key'"; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
17
|
|
|
|
|
69
|
return $obj; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub set_striptags { |
47
|
19
|
|
|
19
|
1
|
76
|
my ($self, @tags) = @_; |
48
|
19
|
100
|
|
|
|
72
|
if( ref($tags[0]) eq 'ARRAY' ) { |
49
|
18
|
|
|
|
|
178
|
$self->_set_striptags_ref( $tags[0] ); |
50
|
|
|
|
|
|
|
} else { |
51
|
1
|
|
|
|
|
4
|
$self->_set_striptags_ref( \@tags ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
{ |
56
|
|
|
|
|
|
|
# an inside-out object approach |
57
|
|
|
|
|
|
|
# for the 'filter' attribute |
58
|
|
|
|
|
|
|
my %filter_of; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub set_filter { |
61
|
17
|
|
|
17
|
1
|
52
|
my ($self, $filter) = @_; |
62
|
17
|
|
|
|
|
120
|
$filter_of{0+$self} = $filter; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub filter { |
66
|
40
|
|
|
40
|
1
|
76
|
my $self = shift; |
67
|
40
|
|
|
|
|
117
|
return $filter_of{0+$self} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# XXX rename _xs_destroy() to DESTROY() in Strip.xs if removing this code |
71
|
|
|
|
|
|
|
sub DESTROY { |
72
|
17
|
|
|
17
|
|
4297
|
my $self = shift; |
73
|
17
|
|
|
|
|
76
|
delete $filter_of{0+$self}; |
74
|
17
|
|
|
|
|
963
|
$self->_xs_destroy; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# $decoded_string = $self->filter_entities( $string ) |
79
|
|
|
|
|
|
|
sub filter_entities { |
80
|
38
|
|
|
38
|
1
|
62
|
my $self = shift; |
81
|
38
|
50
|
|
|
|
135
|
if( $self->decode_entities ) { |
82
|
38
|
|
|
|
|
378
|
return HTML::Entities::decode($_[0]); |
83
|
|
|
|
|
|
|
} |
84
|
0
|
|
|
|
|
0
|
return $_[0]; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _do_filter { |
88
|
40
|
|
|
40
|
|
68
|
my $self = shift; |
89
|
40
|
|
|
|
|
89
|
my $filter = $self->filter; |
90
|
|
|
|
|
|
|
# no filter: return immediately |
91
|
40
|
100
|
|
|
|
139
|
return $_[0] unless defined $filter; |
92
|
|
|
|
|
|
|
|
93
|
39
|
100
|
|
|
|
99
|
if ( !ref $filter ) { # method name |
94
|
38
|
|
|
|
|
122
|
return $self->$filter( @_ ); |
95
|
|
|
|
|
|
|
} else { # code ref |
96
|
1
|
|
|
|
|
5
|
return $filter->( @_ ); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub parse { |
101
|
40
|
|
|
40
|
1
|
3359
|
my ($self, $text) = @_; |
102
|
40
|
|
|
|
|
421
|
my $stripped = $self->_strip_html( $text ); |
103
|
40
|
|
|
|
|
107
|
return $self->_do_filter( $stripped ); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub eof { |
107
|
24
|
|
|
24
|
1
|
406
|
my $self = shift; |
108
|
24
|
|
|
|
|
88
|
$self->_reset(); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
112
|
|
|
|
|
|
|
__END__ |