line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Parser; |
2
|
|
|
|
|
|
|
|
3
|
49
|
|
|
49
|
|
101755
|
use strict; |
|
49
|
|
|
|
|
310
|
|
|
49
|
|
|
|
|
42758
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '3.80'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require HTML::Entities; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require XSLoader; |
10
|
|
|
|
|
|
|
XSLoader::load('HTML::Parser', $VERSION); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new |
13
|
|
|
|
|
|
|
{ |
14
|
129
|
|
|
129
|
1
|
1926749
|
my $class = shift; |
15
|
129
|
|
|
|
|
337
|
my $self = bless {}, $class; |
16
|
129
|
|
|
|
|
450
|
return $self->init(@_); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub init |
21
|
|
|
|
|
|
|
{ |
22
|
129
|
|
|
129
|
0
|
227
|
my $self = shift; |
23
|
129
|
|
|
|
|
1094
|
$self->_alloc_pstate; |
24
|
|
|
|
|
|
|
|
25
|
129
|
|
|
|
|
442
|
my %arg = @_; |
26
|
129
|
|
66
|
|
|
639
|
my $api_version = delete $arg{api_version} || (@_ ? 3 : 2); |
27
|
129
|
100
|
|
|
|
409
|
if ($api_version >= 4) { |
28
|
1
|
|
|
|
|
6
|
require Carp; |
29
|
1
|
|
|
|
|
201
|
Carp::croak("API version $api_version not supported " . |
30
|
|
|
|
|
|
|
"by HTML::Parser $VERSION"); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
128
|
100
|
|
|
|
341
|
if ($api_version < 3) { |
34
|
|
|
|
|
|
|
# Set up method callbacks compatible with HTML-Parser-2.xx |
35
|
47
|
|
|
|
|
444
|
$self->handler(text => "text", "self,text,is_cdata"); |
36
|
47
|
|
|
|
|
208
|
$self->handler(end => "end", "self,tagname,text"); |
37
|
47
|
|
|
|
|
194
|
$self->handler(process => "process", "self,token0,text"); |
38
|
47
|
|
|
|
|
204
|
$self->handler(start => "start", |
39
|
|
|
|
|
|
|
"self,tagname,attr,attrseq,text"); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$self->handler(comment => |
42
|
|
|
|
|
|
|
sub { |
43
|
79
|
|
|
79
|
|
5115
|
my($self, $tokens) = @_; |
44
|
79
|
|
|
|
|
167
|
for (@$tokens) { |
45
|
81
|
|
|
|
|
176
|
$self->comment($_); |
46
|
|
|
|
|
|
|
} |
47
|
47
|
|
|
|
|
863
|
}, "self,tokens"); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$self->handler(declaration => |
50
|
|
|
|
|
|
|
sub { |
51
|
10
|
|
|
10
|
|
366
|
my $self = shift; |
52
|
10
|
|
|
|
|
39
|
$self->declaration(substr($_[0], 2, -1)); |
53
|
47
|
|
|
|
|
225
|
}, "self,text"); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
128
|
100
|
|
|
|
388
|
if (my $h = delete $arg{handlers}) { |
57
|
3
|
50
|
|
|
|
13
|
$h = {@$h} if ref($h) eq "ARRAY"; |
58
|
3
|
|
|
|
|
16
|
while (my($event, $cb) = each %$h) { |
59
|
3
|
|
|
|
|
44
|
$self->handler($event => @$cb); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# In the end we try to assume plain attribute or handler |
64
|
128
|
|
|
|
|
612
|
while (my($option, $val) = each %arg) { |
65
|
101
|
100
|
|
|
|
591
|
if ($option =~ /^(\w+)_h$/) { |
|
|
50
|
|
|
|
|
|
66
|
57
|
|
|
|
|
865
|
$self->handler($1 => @$val); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
elsif ($option =~ /^(text|start|end|process|declaration|comment)$/) { |
69
|
0
|
|
|
|
|
0
|
require Carp; |
70
|
0
|
|
|
|
|
0
|
Carp::croak("Bad constructor option '$option'"); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
else { |
73
|
44
|
|
|
|
|
381
|
$self->$option($val); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
128
|
|
|
|
|
643
|
return $self; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub parse_file |
82
|
|
|
|
|
|
|
{ |
83
|
18
|
|
|
18
|
1
|
53096
|
my($self, $file) = @_; |
84
|
18
|
|
|
|
|
34
|
my $opened; |
85
|
18
|
100
|
100
|
|
|
103
|
if (!ref($file) && ref(\$file) ne "GLOB") { |
86
|
|
|
|
|
|
|
# Assume $file is a filename |
87
|
10
|
|
|
|
|
36
|
local(*F); |
88
|
10
|
50
|
|
|
|
396
|
open(F, "<", $file) || return undef; |
89
|
10
|
|
|
|
|
45
|
binmode(F); # should we? good for byte counts |
90
|
10
|
|
|
|
|
26
|
$opened++; |
91
|
10
|
|
|
|
|
70
|
$file = *F; |
92
|
|
|
|
|
|
|
} |
93
|
18
|
|
|
|
|
44
|
my $chunk = ''; |
94
|
18
|
|
|
|
|
377
|
while (read($file, $chunk, 512)) { |
95
|
8147
|
100
|
|
|
|
66619
|
$self->parse($chunk) || last; |
96
|
|
|
|
|
|
|
} |
97
|
18
|
100
|
|
|
|
281
|
close($file) if $opened; |
98
|
18
|
|
|
|
|
154
|
$self->eof; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub netscape_buggy_comment # legacy |
103
|
|
|
|
|
|
|
{ |
104
|
1
|
|
|
1
|
0
|
4183
|
my $self = shift; |
105
|
1
|
|
|
|
|
7
|
require Carp; |
106
|
1
|
|
|
|
|
181
|
Carp::carp("netscape_buggy_comment() is deprecated. " . |
107
|
|
|
|
|
|
|
"Please use the strict_comment() method instead"); |
108
|
1
|
|
|
|
|
54
|
my $old = !$self->strict_comment; |
109
|
1
|
50
|
|
|
|
5
|
$self->strict_comment(!shift) if @_; |
110
|
1
|
|
|
|
|
5
|
return $old; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# set up method stubs |
114
|
|
|
|
25028
|
1
|
|
sub text { } |
115
|
|
|
|
|
|
|
*start = \&text; |
116
|
|
|
|
|
|
|
*end = \&text; |
117
|
|
|
|
|
|
|
*comment = \&text; |
118
|
|
|
|
|
|
|
*declaration = \&text; |
119
|
|
|
|
|
|
|
*process = \&text; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__END__ |