| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HTML::PullParser; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
447
|
use strict; |
|
|
2
|
|
|
|
|
7
|
|
|
|
2
|
|
|
|
|
189
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
require HTML::Parser; |
|
6
|
|
|
|
|
|
|
our @ISA = qw(HTML::Parser); |
|
7
|
|
|
|
|
|
|
our $VERSION = '3.81'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
13
|
use Carp (); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
1466
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new |
|
12
|
|
|
|
|
|
|
{ |
|
13
|
11
|
|
|
11
|
1
|
144
|
my($class, %cnf) = @_; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Construct argspecs for the various events |
|
16
|
11
|
|
|
|
|
15
|
my %argspec; |
|
17
|
11
|
|
|
|
|
29
|
for (qw(start end text declaration comment process default)) { |
|
18
|
77
|
|
|
|
|
117
|
my $tmp = delete $cnf{$_}; |
|
19
|
77
|
100
|
|
|
|
146
|
next unless defined $tmp; |
|
20
|
63
|
|
|
|
|
106
|
$argspec{$_} = $tmp; |
|
21
|
|
|
|
|
|
|
} |
|
22
|
11
|
50
|
|
|
|
24
|
Carp::croak("Info not collected for any events") |
|
23
|
|
|
|
|
|
|
unless %argspec; |
|
24
|
|
|
|
|
|
|
|
|
25
|
11
|
|
|
|
|
21
|
my $file = delete $cnf{file}; |
|
26
|
11
|
|
|
|
|
18
|
my $doc = delete $cnf{doc}; |
|
27
|
11
|
50
|
66
|
|
|
39
|
Carp::croak("Can't parse from both 'doc' and 'file' at the same time") |
|
28
|
|
|
|
|
|
|
if defined($file) && defined($doc); |
|
29
|
11
|
50
|
66
|
|
|
42
|
Carp::croak("No 'doc' or 'file' given to parse from") |
|
30
|
|
|
|
|
|
|
unless defined($file) || defined($doc); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Create object |
|
33
|
11
|
|
|
|
|
17
|
$cnf{api_version} = 3; |
|
34
|
11
|
|
|
|
|
56
|
my $self = $class->SUPER::new(%cnf); |
|
35
|
|
|
|
|
|
|
|
|
36
|
11
|
|
|
|
|
43
|
my $accum = $self->{pullparser_accum} = []; |
|
37
|
11
|
|
|
|
|
37
|
while (my($event, $argspec) = each %argspec) { |
|
38
|
63
|
|
|
|
|
338
|
$self->SUPER::handler($event => $accum, $argspec); |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
11
|
100
|
|
|
|
25
|
if (defined $doc) { |
|
42
|
5
|
100
|
|
|
|
17
|
$self->{pullparser_str_ref} = ref($doc) ? $doc : \$doc; |
|
43
|
5
|
|
|
|
|
11
|
$self->{pullparser_str_pos} = 0; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
else { |
|
46
|
6
|
100
|
66
|
|
|
24
|
if (!ref($file) && ref(\$file) ne "GLOB") { |
|
47
|
4
|
|
|
|
|
466
|
require IO::File; |
|
48
|
4
|
|
100
|
|
|
8229
|
$file = IO::File->new($file, "r") || return; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
5
|
|
|
|
|
288
|
$self->{pullparser_file} = $file; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
10
|
|
|
|
|
46
|
$self; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub handler |
|
58
|
|
|
|
|
|
|
{ |
|
59
|
0
|
|
|
0
|
1
|
0
|
Carp::croak("Can't set handlers for HTML::PullParser"); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub get_token |
|
64
|
|
|
|
|
|
|
{ |
|
65
|
8296
|
|
|
8296
|
1
|
26311
|
my $self = shift; |
|
66
|
8296
|
|
100
|
|
|
9695
|
while (!@{$self->{pullparser_accum}} && !$self->{pullparser_eof}) { |
|
|
8431
|
|
|
|
|
14886
|
|
|
67
|
135
|
100
|
|
|
|
318
|
if (my $f = $self->{pullparser_file}) { |
|
|
|
50
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# must try to parse more from the file |
|
69
|
8
|
|
|
|
|
9
|
my $buf; |
|
70
|
8
|
100
|
|
|
|
112
|
if (read($f, $buf, 512)) { |
|
71
|
5
|
|
|
|
|
334
|
$self->parse($buf); |
|
72
|
|
|
|
|
|
|
} else { |
|
73
|
3
|
|
|
|
|
23
|
$self->eof; |
|
74
|
3
|
|
|
|
|
7
|
$self->{pullparser_eof}++; |
|
75
|
3
|
|
|
|
|
18
|
delete $self->{pullparser_file}; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
elsif (my $sref = $self->{pullparser_str_ref}) { |
|
79
|
|
|
|
|
|
|
# must try to parse more from the scalar |
|
80
|
127
|
|
|
|
|
164
|
my $pos = $self->{pullparser_str_pos}; |
|
81
|
127
|
|
|
|
|
257
|
my $chunk = substr($$sref, $pos, 512); |
|
82
|
127
|
|
|
|
|
8709
|
$self->parse($chunk); |
|
83
|
127
|
|
|
|
|
325
|
$pos += length($chunk); |
|
84
|
127
|
100
|
|
|
|
212
|
if ($pos < length($$sref)) { |
|
85
|
122
|
|
|
|
|
225
|
$self->{pullparser_str_pos} = $pos; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
else { |
|
88
|
5
|
|
|
|
|
27
|
$self->eof; |
|
89
|
5
|
|
|
|
|
11
|
$self->{pullparser_eof}++; |
|
90
|
5
|
|
|
|
|
11
|
delete $self->{pullparser_str_ref}; |
|
91
|
5
|
|
|
|
|
11
|
delete $self->{pullparser_str_pos}; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
else { |
|
95
|
0
|
|
|
|
|
0
|
die; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
} |
|
98
|
8296
|
|
|
|
|
9951
|
shift @{$self->{pullparser_accum}}; |
|
|
8296
|
|
|
|
|
13567
|
|
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub unget_token |
|
103
|
|
|
|
|
|
|
{ |
|
104
|
9
|
|
|
9
|
1
|
1311
|
my $self = shift; |
|
105
|
9
|
|
|
|
|
13
|
unshift @{$self->{pullparser_accum}}, @_; |
|
|
9
|
|
|
|
|
20
|
|
|
106
|
9
|
|
|
|
|
17
|
$self; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |