line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Parser; |
2
|
|
|
|
|
|
|
|
3
|
49
|
|
|
49
|
|
96594
|
use strict; |
|
49
|
|
|
|
|
247
|
|
|
49
|
|
|
|
|
35515
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '3.79'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require HTML::Entities; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require XSLoader; |
10
|
|
|
|
|
|
|
XSLoader::load('HTML::Parser', $VERSION); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new |
13
|
|
|
|
|
|
|
{ |
14
|
129
|
|
|
129
|
1
|
1563377
|
my $class = shift; |
15
|
129
|
|
|
|
|
270
|
my $self = bless {}, $class; |
16
|
129
|
|
|
|
|
359
|
return $self->init(@_); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub init |
21
|
|
|
|
|
|
|
{ |
22
|
129
|
|
|
129
|
0
|
188
|
my $self = shift; |
23
|
129
|
|
|
|
|
939
|
$self->_alloc_pstate; |
24
|
|
|
|
|
|
|
|
25
|
129
|
|
|
|
|
317
|
my %arg = @_; |
26
|
129
|
|
66
|
|
|
531
|
my $api_version = delete $arg{api_version} || (@_ ? 3 : 2); |
27
|
129
|
100
|
|
|
|
296
|
if ($api_version >= 4) { |
28
|
1
|
|
|
|
|
5
|
require Carp; |
29
|
1
|
|
|
|
|
182
|
Carp::croak("API version $api_version not supported " . |
30
|
|
|
|
|
|
|
"by HTML::Parser $VERSION"); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
128
|
100
|
|
|
|
276
|
if ($api_version < 3) { |
34
|
|
|
|
|
|
|
# Set up method callbacks compatible with HTML-Parser-2.xx |
35
|
47
|
|
|
|
|
372
|
$self->handler(text => "text", "self,text,is_cdata"); |
36
|
47
|
|
|
|
|
156
|
$self->handler(end => "end", "self,tagname,text"); |
37
|
47
|
|
|
|
|
167
|
$self->handler(process => "process", "self,token0,text"); |
38
|
47
|
|
|
|
|
155
|
$self->handler(start => "start", |
39
|
|
|
|
|
|
|
"self,tagname,attr,attrseq,text"); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$self->handler(comment => |
42
|
|
|
|
|
|
|
sub { |
43
|
82
|
|
|
82
|
|
4071
|
my($self, $tokens) = @_; |
44
|
82
|
|
|
|
|
140
|
for (@$tokens) { |
45
|
84
|
|
|
|
|
131
|
$self->comment($_); |
46
|
|
|
|
|
|
|
} |
47
|
47
|
|
|
|
|
281
|
}, "self,tokens"); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$self->handler(declaration => |
50
|
|
|
|
|
|
|
sub { |
51
|
10
|
|
|
10
|
|
322
|
my $self = shift; |
52
|
10
|
|
|
|
|
34
|
$self->declaration(substr($_[0], 2, -1)); |
53
|
47
|
|
|
|
|
189
|
}, "self,text"); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
128
|
100
|
|
|
|
296
|
if (my $h = delete $arg{handlers}) { |
57
|
3
|
50
|
|
|
|
10
|
$h = {@$h} if ref($h) eq "ARRAY"; |
58
|
3
|
|
|
|
|
13
|
while (my($event, $cb) = each %$h) { |
59
|
3
|
|
|
|
|
46
|
$self->handler($event => @$cb); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# In the end we try to assume plain attribute or handler |
64
|
128
|
|
|
|
|
482
|
while (my($option, $val) = each %arg) { |
65
|
101
|
100
|
|
|
|
452
|
if ($option =~ /^(\w+)_h$/) { |
|
|
50
|
|
|
|
|
|
66
|
57
|
|
|
|
|
722
|
$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
|
|
|
|
|
271
|
$self->$option($val); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
128
|
|
|
|
|
524
|
return $self; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub parse_file |
82
|
|
|
|
|
|
|
{ |
83
|
18
|
|
|
18
|
1
|
31813
|
my($self, $file) = @_; |
84
|
18
|
|
|
|
|
27
|
my $opened; |
85
|
18
|
100
|
100
|
|
|
84
|
if (!ref($file) && ref(\$file) ne "GLOB") { |
86
|
|
|
|
|
|
|
# Assume $file is a filename |
87
|
10
|
|
|
|
|
25
|
local(*F); |
88
|
10
|
50
|
|
|
|
375
|
open(F, "<", $file) || return undef; |
89
|
10
|
|
|
|
|
34
|
binmode(F); # should we? good for byte counts |
90
|
10
|
|
|
|
|
26
|
$opened++; |
91
|
10
|
|
|
|
|
56
|
$file = *F; |
92
|
|
|
|
|
|
|
} |
93
|
18
|
|
|
|
|
32
|
my $chunk = ''; |
94
|
18
|
|
|
|
|
324
|
while (read($file, $chunk, 512)) { |
95
|
8737
|
100
|
|
|
|
50578
|
$self->parse($chunk) || last; |
96
|
|
|
|
|
|
|
} |
97
|
18
|
100
|
|
|
|
245
|
close($file) if $opened; |
98
|
18
|
|
|
|
|
123
|
$self->eof; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub netscape_buggy_comment # legacy |
103
|
|
|
|
|
|
|
{ |
104
|
1
|
|
|
1
|
0
|
2556
|
my $self = shift; |
105
|
1
|
|
|
|
|
5
|
require Carp; |
106
|
1
|
|
|
|
|
143
|
Carp::carp("netscape_buggy_comment() is deprecated. " . |
107
|
|
|
|
|
|
|
"Please use the strict_comment() method instead"); |
108
|
1
|
|
|
|
|
46
|
my $old = !$self->strict_comment; |
109
|
1
|
50
|
|
|
|
4
|
$self->strict_comment(!shift) if @_; |
110
|
1
|
|
|
|
|
4
|
return $old; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# set up method stubs |
114
|
|
|
|
27056
|
1
|
|
sub text { } |
115
|
|
|
|
|
|
|
*start = \&text; |
116
|
|
|
|
|
|
|
*end = \&text; |
117
|
|
|
|
|
|
|
*comment = \&text; |
118
|
|
|
|
|
|
|
*declaration = \&text; |
119
|
|
|
|
|
|
|
*process = \&text; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__END__ |