| 1 | package HTML::PullParser; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | require HTML::Parser; | |||||||||||||||||||||||||||
| 6 | 2 | our @ISA = qw(HTML::Parser); | |||||||||||||||||||||||||||
| 7 | 2 | our $VERSION = '3.87'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | sub new | ||||||||||||||||||||||||||||
| 12 | 11 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=14 SCAR=26.6
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | 11 | my($class, %cnf) = @_; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # Construct argspecs for the various events | ||||||||||||||||||||||||||||
| 16 | 11 | my %argspec; | |||||||||||||||||||||||||||
| 17 | 11 | for (qw(start end text declaration comment process default)) { | |||||||||||||||||||||||||||
| 18 | 77 | my $tmp = delete $cnf{$_}; | |||||||||||||||||||||||||||
| 19 | 77 | ▶ | next unless defined $tmp; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 63 | $argspec{$_} = $tmp; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | 11 | ▶ | Carp::croak("Info not collected for any events") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | unless %argspec; | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 11 | my $file = delete $cnf{file}; | |||||||||||||||||||||||||||
| 26 | 11 | my $doc = delete $cnf{doc}; | |||||||||||||||||||||||||||
| 27 | 11 | ▶ | Carp::croak("Can't parse from both 'doc' and 'file' at the same time") | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $file and defined $doc
MC/DC0%0/2
defined $file and defined $doc
defined $file
defined $doc
Truth table66%2/3
A and B
A= defined $fileB= defined $doc
| |||||||||||||||||||||||||||||
| 28 | if defined($file) && defined($doc); | ||||||||||||||||||||||||||||
| 29 | 11 | ▶ | Carp::croak("No 'doc' or 'file' given to parse from") | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $file or defined $doc
MC/DC0%0/2
defined $file or defined $doc
defined $file
defined $doc
Truth table66%2/3
A or B
A= defined $fileB= defined $doc
| |||||||||||||||||||||||||||||
| 30 | unless defined($file) || defined($doc); | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # Create object | ||||||||||||||||||||||||||||
| 33 | 11 | $cnf{api_version} = 3; | |||||||||||||||||||||||||||
| 34 | 11 | my $self = $class->SUPER::new(%cnf); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 11 | my $accum = $self->{pullparser_accum} = []; | |||||||||||||||||||||||||||
| 37 | 11 | ▶ | while (my($event, $argspec) = each %argspec) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 63 | $self->SUPER::handler($event => $accum, $argspec); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 11 | ▶ | if (defined $doc) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 5 | ▶ | $self->{pullparser_str_ref} = ref($doc) ? $doc : \$doc; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 5 | $self->{pullparser_str_pos} = 0; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | else { | ||||||||||||||||||||||||||||
| 46 | 6 | ▶ | if (!ref($file) && ref(\$file) ne "GLOB") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not ref $file and ref \$file ne "GLOB"
MC/DC50%1/2
not ref $file and ref \$file ne "GLOB"
not ref $file
ref \$file ne "GLOB"
Truth table66%2/3
not(A) and B
A= not ref $fileB= ref \$file ne "GLOB"
| |||||||||||||||||||||||||||||
| 47 | 4 | require IO::File; | |||||||||||||||||||||||||||
| 48 | 4 | ▶ | $file = IO::File->new($file, "r") || return; | ||||||||||||||||||||||||||
|
Condition100%2/2
'IO::File'->new($file, 'r') || (return)
MC/DC100%1/1
'IO::File'->new($file, 'r') || (return)
'IO::File'->new($file, 'r')
Truth table100%2/2
A
A= 'IO::File'->new($file, 'r')
| |||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 5 | $self->{pullparser_file} = $file; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 10 | $self; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | sub handler | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
handler: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | 0 | Carp::croak("Can't set handlers for HTML::PullParser"); | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | sub get_token | ||||||||||||||||||||||||||||
| 64 | 8296 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get_token: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 8296 | my $self = shift; | |||||||||||||||||||||||||||
| 66 | 8296 | ▶ | while (!@{$self->{pullparser_accum}} && !$self->{pullparser_eof}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@{$self->{"pullparser_accum"};} or $self->{"pullparser_eof"}
MC/DC100%2/2
@{$self->{"pullparser_accum"};} or $self->{"pullparser_eof"}
@{$self->{"pullparser_accum"};}
$self->{"pullparser_eof"}
Truth table100%3/3
A or B
A= @{$self->{"pullparser_accum"};}B= $self->{"pullparser_eof"}
| |||||||||||||||||||||||||||||
| 67 | 135 | ▶ | if (my $f = $self->{pullparser_file}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 68 | # must try to parse more from the file | ||||||||||||||||||||||||||||
| 69 | 8 | my $buf; | |||||||||||||||||||||||||||
| 70 | 8 | ▶ | if (read($f, $buf, 512)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 5 | $self->parse($buf); | |||||||||||||||||||||||||||
| 72 | } else { | ||||||||||||||||||||||||||||
| 73 | 3 | $self->eof; | |||||||||||||||||||||||||||
| 74 | 3 | $self->{pullparser_eof}++; | |||||||||||||||||||||||||||
| 75 | 3 | 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 | my $pos = $self->{pullparser_str_pos}; | |||||||||||||||||||||||||||
| 81 | 127 | my $chunk = substr($$sref, $pos, 512); | |||||||||||||||||||||||||||
| 82 | 127 | $self->parse($chunk); | |||||||||||||||||||||||||||
| 83 | 127 | $pos += length($chunk); | |||||||||||||||||||||||||||
| 84 | 127 | ▶ | if ($pos < length($$sref)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 122 | $self->{pullparser_str_pos} = $pos; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | else { | ||||||||||||||||||||||||||||
| 88 | 5 | $self->eof; | |||||||||||||||||||||||||||
| 89 | 5 | $self->{pullparser_eof}++; | |||||||||||||||||||||||||||
| 90 | 5 | delete $self->{pullparser_str_ref}; | |||||||||||||||||||||||||||
| 91 | 5 | delete $self->{pullparser_str_pos}; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | else { | ||||||||||||||||||||||||||||
| 95 | 0 | die; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | 8296 | shift @{$self->{pullparser_accum}}; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | sub unget_token | ||||||||||||||||||||||||||||
| 103 | 9 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
unget_token: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 104 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 105 | 9 | unshift @{$self->{pullparser_accum}}, @_; | |||||||||||||||||||||||||||
| 106 | 9 | $self; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 2 | 1; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | __END__ | ||||||||||||||||||||||||||||