line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::PullParser; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
412
|
use strict; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
130
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
require HTML::Parser; |
6
|
|
|
|
|
|
|
our @ISA = qw(HTML::Parser); |
7
|
|
|
|
|
|
|
our $VERSION = '3.79'; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
10
|
use Carp (); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
922
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new |
12
|
|
|
|
|
|
|
{ |
13
|
11
|
|
|
11
|
1
|
110
|
my($class, %cnf) = @_; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Construct argspecs for the various events |
16
|
11
|
|
|
|
|
14
|
my %argspec; |
17
|
11
|
|
|
|
|
20
|
for (qw(start end text declaration comment process default)) { |
18
|
77
|
|
|
|
|
82
|
my $tmp = delete $cnf{$_}; |
19
|
77
|
100
|
|
|
|
93
|
next unless defined $tmp; |
20
|
63
|
|
|
|
|
91
|
$argspec{$_} = $tmp; |
21
|
|
|
|
|
|
|
} |
22
|
11
|
50
|
|
|
|
23
|
Carp::croak("Info not collected for any events") |
23
|
|
|
|
|
|
|
unless %argspec; |
24
|
|
|
|
|
|
|
|
25
|
11
|
|
|
|
|
15
|
my $file = delete $cnf{file}; |
26
|
11
|
|
|
|
|
14
|
my $doc = delete $cnf{doc}; |
27
|
11
|
50
|
66
|
|
|
28
|
Carp::croak("Can't parse from both 'doc' and 'file' at the same time") |
28
|
|
|
|
|
|
|
if defined($file) && defined($doc); |
29
|
11
|
50
|
66
|
|
|
48
|
Carp::croak("No 'doc' or 'file' given to parse from") |
30
|
|
|
|
|
|
|
unless defined($file) || defined($doc); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Create object |
33
|
11
|
|
|
|
|
18
|
$cnf{api_version} = 3; |
34
|
11
|
|
|
|
|
44
|
my $self = $class->SUPER::new(%cnf); |
35
|
|
|
|
|
|
|
|
36
|
11
|
|
|
|
|
26
|
my $accum = $self->{pullparser_accum} = []; |
37
|
11
|
|
|
|
|
30
|
while (my($event, $argspec) = each %argspec) { |
38
|
63
|
|
|
|
|
264
|
$self->SUPER::handler($event => $accum, $argspec); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
11
|
100
|
|
|
|
19
|
if (defined $doc) { |
42
|
5
|
100
|
|
|
|
12
|
$self->{pullparser_str_ref} = ref($doc) ? $doc : \$doc; |
43
|
5
|
|
|
|
|
7
|
$self->{pullparser_str_pos} = 0; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
else { |
46
|
6
|
100
|
66
|
|
|
20
|
if (!ref($file) && ref(\$file) ne "GLOB") { |
47
|
4
|
|
|
|
|
439
|
require IO::File; |
48
|
4
|
|
100
|
|
|
6626
|
$file = IO::File->new($file, "r") || return; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
5
|
|
|
|
|
301
|
$self->{pullparser_file} = $file; |
52
|
|
|
|
|
|
|
} |
53
|
10
|
|
|
|
|
38
|
$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
|
19037
|
my $self = shift; |
66
|
8296
|
|
100
|
|
|
6726
|
while (!@{$self->{pullparser_accum}} && !$self->{pullparser_eof}) { |
|
8431
|
|
|
|
|
10850
|
|
67
|
135
|
100
|
|
|
|
242
|
if (my $f = $self->{pullparser_file}) { |
|
|
50
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# must try to parse more from the file |
69
|
8
|
|
|
|
|
8
|
my $buf; |
70
|
8
|
100
|
|
|
|
102
|
if (read($f, $buf, 512)) { |
71
|
5
|
|
|
|
|
257
|
$self->parse($buf); |
72
|
|
|
|
|
|
|
} else { |
73
|
3
|
|
|
|
|
20
|
$self->eof; |
74
|
3
|
|
|
|
|
4
|
$self->{pullparser_eof}++; |
75
|
3
|
|
|
|
|
16
|
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
|
|
|
|
|
115
|
my $pos = $self->{pullparser_str_pos}; |
81
|
127
|
|
|
|
|
214
|
my $chunk = substr($$sref, $pos, 512); |
82
|
127
|
|
|
|
|
6150
|
$self->parse($chunk); |
83
|
127
|
|
|
|
|
214
|
$pos += length($chunk); |
84
|
127
|
100
|
|
|
|
178
|
if ($pos < length($$sref)) { |
85
|
122
|
|
|
|
|
169
|
$self->{pullparser_str_pos} = $pos; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
else { |
88
|
5
|
|
|
|
|
29
|
$self->eof; |
89
|
5
|
|
|
|
|
11
|
$self->{pullparser_eof}++; |
90
|
5
|
|
|
|
|
6
|
delete $self->{pullparser_str_ref}; |
91
|
5
|
|
|
|
|
9
|
delete $self->{pullparser_str_pos}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
else { |
95
|
0
|
|
|
|
|
0
|
die; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
8296
|
|
|
|
|
6842
|
shift @{$self->{pullparser_accum}}; |
|
8296
|
|
|
|
|
10007
|
|
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub unget_token |
103
|
|
|
|
|
|
|
{ |
104
|
9
|
|
|
9
|
1
|
944
|
my $self = shift; |
105
|
9
|
|
|
|
|
9
|
unshift @{$self->{pullparser_accum}}, @_; |
|
9
|
|
|
|
|
18
|
|
106
|
9
|
|
|
|
|
12
|
$self; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |