line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Filter::Callbacks; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
143303
|
use strict; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
188
|
|
4
|
4
|
|
|
4
|
|
20
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
115
|
|
5
|
4
|
|
|
4
|
|
21
|
use base 'HTML::Parser'; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
11723
|
|
6
|
4
|
|
|
4
|
|
32716
|
use HTML::Filter::Callbacks::Tag; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
2458
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my %Handlers = ( |
11
|
|
|
|
|
|
|
start => [\&_handler, 'self,event,tokens,text,skipped_text'], |
12
|
|
|
|
|
|
|
end => [\&_handler, 'self,event,tokens,text,skipped_text'], |
13
|
|
|
|
|
|
|
end_document => [sub { $_[0]->_add_chunk($_[1]) }, 'self,skipped_text'], |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub init { |
17
|
16
|
|
|
16
|
1
|
9512
|
my ($self, %args) = @_; |
18
|
16
|
|
|
|
|
148
|
$self->_alloc_pstate; |
19
|
|
|
|
|
|
|
|
20
|
16
|
|
|
|
|
50
|
foreach my $event (keys %Handlers) { |
21
|
48
|
|
|
|
|
65
|
$self->handler($event => @{$Handlers{$event}}); |
|
48
|
|
|
|
|
328
|
|
22
|
|
|
|
|
|
|
} |
23
|
16
|
|
|
|
|
92
|
$self->{__tag} = HTML::Filter::Callbacks::Tag->new(%args); |
24
|
|
|
|
|
|
|
|
25
|
16
|
|
|
|
|
55
|
$self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub process { |
29
|
16
|
|
|
16
|
1
|
94
|
my ($self, $html) = @_; |
30
|
|
|
|
|
|
|
|
31
|
16
|
|
|
|
|
33
|
$self->{__res} = []; |
32
|
|
|
|
|
|
|
|
33
|
16
|
|
|
|
|
171
|
$self->parse($html); |
34
|
16
|
|
|
|
|
111
|
$self->eof; |
35
|
|
|
|
|
|
|
|
36
|
16
|
|
|
|
|
22
|
return join '', @{ $self->{__res} }; |
|
16
|
|
|
|
|
344
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub add_callbacks { |
40
|
16
|
|
|
16
|
1
|
866
|
my ($self, @callbacks) = @_; |
41
|
|
|
|
|
|
|
|
42
|
16
|
|
|
|
|
65
|
while (my ($tag, $handlers) = splice @callbacks, 0, 2) { |
43
|
37
|
|
|
|
|
93
|
foreach my $event (keys %$handlers) { |
44
|
47
|
|
|
|
|
78
|
my $cb = $handlers->{$event}; |
45
|
47
|
|
|
|
|
68
|
my $lc_tag = lc $tag; |
46
|
47
|
50
|
100
|
|
|
246
|
push @{ $self->{__cb}{$lc_tag}{$event} ||= [] }, $cb unless $self->{__seen}{"$lc_tag$event"}{$cb}++; |
|
47
|
|
|
|
|
455
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
7
|
|
100
|
7
|
1
|
61
|
sub stash { shift->{__stash} ||= {} } |
52
|
|
|
|
|
|
|
|
53
|
94
|
50
|
|
94
|
|
259
|
sub _add_chunk { push @{ $_[0]->{__res} }, $_[1] if defined $_[1] } |
|
94
|
|
|
|
|
679
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _handler { |
56
|
78
|
|
|
78
|
|
144
|
my ($self, $event, $tokens, $org, $skipped_text) = @_; |
57
|
78
|
|
|
|
|
259
|
$self->{__tag}->set($tokens, $org, $skipped_text); |
58
|
78
|
|
|
|
|
334
|
$self->_run($self->{__cb}{lc($self->{__tag}->name)}{$event}); |
59
|
78
|
100
|
|
|
|
10045
|
if ($self->{__cb}{'*'}) { |
60
|
3
|
|
|
|
|
9
|
$self->_run($self->{__cb}{'*'}{$event}); |
61
|
|
|
|
|
|
|
} |
62
|
78
|
|
|
|
|
239
|
$self->_add_chunk($self->{__tag}->as_string); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _run { |
66
|
81
|
|
|
81
|
|
167
|
my ($self, $callbacks) = @_; |
67
|
|
|
|
|
|
|
|
68
|
81
|
100
|
|
|
|
186
|
return unless $callbacks; |
69
|
34
|
|
|
|
|
56
|
foreach my $cb (@$callbacks) { |
70
|
40
|
|
|
|
|
3020
|
$cb->($self->{__tag}, $self); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |