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.10'; |
6
|
|
|
|
|
|
|
bootstrap HTML::Strip $VERSION; |
7
|
|
|
|
|
|
|
|
8
|
12
|
|
|
12
|
|
175258
|
use 5.008; |
|
12
|
|
|
|
|
29
|
|
9
|
12
|
|
|
12
|
|
42
|
use warnings; |
|
12
|
|
|
|
|
14
|
|
|
12
|
|
|
|
|
282
|
|
10
|
12
|
|
|
12
|
|
43
|
use strict; |
|
12
|
|
|
|
|
11
|
|
|
12
|
|
|
|
|
187
|
|
11
|
|
|
|
|
|
|
|
12
|
12
|
|
|
12
|
|
34
|
use Carp; |
|
12
|
|
|
|
|
13
|
|
|
12
|
|
|
|
|
5928
|
|
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
|
|
|
|
|
|
|
decode_entities => 1, |
23
|
|
|
|
|
|
|
filter => $_html_entities_p ? 'filter_entities' : undef, |
24
|
|
|
|
|
|
|
auto_reset => 0, |
25
|
|
|
|
|
|
|
debug => 0, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new { |
29
|
17
|
|
|
17
|
1
|
11427
|
my $class = shift; |
30
|
17
|
|
|
|
|
89
|
my $obj = _create(); |
31
|
17
|
|
|
|
|
29
|
bless $obj, $class; |
32
|
|
|
|
|
|
|
|
33
|
17
|
|
|
|
|
169
|
my %args = (%defaults, @_); |
34
|
17
|
|
|
|
|
82
|
while( my ($key, $value) = each %args ) { |
35
|
102
|
|
|
|
|
120
|
my $method = "set_${key}"; |
36
|
102
|
50
|
|
|
|
306
|
if( $obj->can($method) ) { |
37
|
102
|
|
|
|
|
365
|
$obj->$method($value); |
38
|
|
|
|
|
|
|
} else { |
39
|
0
|
|
|
|
|
0
|
Carp::carp "Invalid setting '$key'"; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
17
|
|
|
|
|
59
|
return $obj; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub set_striptags { |
46
|
19
|
|
|
19
|
1
|
46
|
my ($self, @tags) = @_; |
47
|
19
|
100
|
|
|
|
73
|
if( ref($tags[0]) eq 'ARRAY' ) { |
48
|
18
|
|
|
|
|
135
|
$self->_set_striptags_ref( $tags[0] ); |
49
|
|
|
|
|
|
|
} else { |
50
|
1
|
|
|
|
|
21
|
$self->_set_striptags_ref( \@tags ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
{ |
55
|
|
|
|
|
|
|
# an inside-out object approach |
56
|
|
|
|
|
|
|
# for the 'filter' attribute |
57
|
|
|
|
|
|
|
my %filter_of; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub set_filter { |
60
|
17
|
|
|
17
|
1
|
30
|
my ($self, $filter) = @_; |
61
|
17
|
|
|
|
|
120
|
$filter_of{0+$self} = $filter; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub filter { |
65
|
40
|
|
|
40
|
1
|
41
|
my $self = shift; |
66
|
40
|
|
|
|
|
98
|
return $filter_of{0+$self} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# XXX rename _xs_destroy() to DESTROY() in Strip.xs if removing this code |
70
|
|
|
|
|
|
|
sub DESTROY { |
71
|
17
|
|
|
17
|
|
2948
|
my $self = shift; |
72
|
17
|
|
|
|
|
59
|
delete $filter_of{0+$self}; |
73
|
17
|
|
|
|
|
237
|
$self->_xs_destroy; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# $decoded_string = $self->filter_entities( $string ) |
78
|
|
|
|
|
|
|
sub filter_entities { |
79
|
38
|
|
|
38
|
1
|
40
|
my $self = shift; |
80
|
38
|
50
|
|
|
|
116
|
if( $self->decode_entities ) { |
81
|
38
|
|
|
|
|
339
|
return HTML::Entities::decode($_[0]); |
82
|
|
|
|
|
|
|
} |
83
|
0
|
|
|
|
|
0
|
return $_[0]; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub _do_filter { |
87
|
40
|
|
|
40
|
|
50
|
my $self = shift; |
88
|
40
|
|
|
|
|
72
|
my $filter = $self->filter; |
89
|
|
|
|
|
|
|
# no filter: return immediately |
90
|
40
|
100
|
|
|
|
93
|
return $_[0] unless defined $filter; |
91
|
|
|
|
|
|
|
|
92
|
39
|
100
|
|
|
|
77
|
if ( !ref $filter ) { # method name |
93
|
38
|
|
|
|
|
98
|
return $self->$filter( @_ ); |
94
|
|
|
|
|
|
|
} else { # code ref |
95
|
1
|
|
|
|
|
3
|
return $filter->( @_ ); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub parse { |
100
|
40
|
|
|
40
|
1
|
1912
|
my ($self, $text) = @_; |
101
|
40
|
|
|
|
|
620
|
my $stripped = $self->_strip_html( $text ); |
102
|
40
|
|
|
|
|
89
|
return $self->_do_filter( $stripped ); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub eof { |
106
|
24
|
|
|
24
|
1
|
296
|
my $self = shift; |
107
|
24
|
|
|
|
|
102
|
$self->_reset(); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
111
|
|
|
|
|
|
|
__END__ |