blib/lib/HTML/PullParser.pm

filter: Statementstmt 96.7% 60 / 62 Branchbran 84.6% 22 / 26 Conditioncond 78.5% 11 / 14 MC/DCmcdc 44.4% 4 / 9 Subroutinesub 83.3% 5 / 6 Podpod 100% 4 / 4 totaltotal 87.6% 106 / 121 CC 20 SCAR 23.2
CC
20
Cov
91%
new
14.3
get_token
7.0
handler
2.0
CRAP 10.2
« blib/lib/HTML/HeadParser.pm ↑ Summary blib/lib/HTML/TokeParser.pm »
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
BranchTrueFalseTotal
unless defined $tmp 14 63 77
20 63 $argspec{$_} = $tmp;
21 }
22 11 ▶ Carp::croak("Info not collected for any events")
Branch: 1 branch
BranchTrueFalseTotal
unless %argspec 0 11 11
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
BranchTrueFalseTotal
if defined $file and defined $doc 0 11 11
Condition66%2/3
defined $file and defined $doc
!ll&&!rl&&r
560
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
ABresult
0X0
100
111
28 if defined($file) && defined($doc);
29 11 ▶ Carp::croak("No 'doc' or 'file' given to parse from")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file or defined $doc 0 11 11
Condition66%2/3
defined $file or defined $doc
l!l&&r!l&&!r
650
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if (() = each %argspec) 63 11 74
38 63 $self->SUPER::handler($event => $accum, $argspec);
39 }
40  
41 11 ▶ if (defined $doc) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $doc) { } 5 6 11
42 5 ▶ $self->{pullparser_str_ref} = ref($doc) ? $doc : \$doc;
Branch: 1 branch
BranchTrueFalseTotal
ref $doc ? : 4 1 5
43 5 $self->{pullparser_str_pos} = 0;
44 }
45 else {
46 6 ▶ if (!ref($file) && ref(\$file) ne "GLOB") {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $file and ref \$file ne "GLOB") 4 2 6
Condition66%2/3
not ref $file and ref \$file ne "GLOB"
!ll&&!rl&&r
204
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"
ABresult
0X0
100
111
47 4 require IO::File;
48 4 ▶ $file = IO::File->new($file, "r") || return;
Condition100%2/2
'IO::File'->new($file, 'r') || (return)
l!l
31
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')
Aresult
11
00
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
BranchTrueFalseTotal
unless (@{$self->{"pullparser_accum"};} or $self->{"pullparser_eof"}) 135 8296 8431
Condition100%3/3
@{$self->{"pullparser_accum"};} or $self->{"pullparser_eof"}
l!l&&r!l&&!r
82915135
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"}
ABresult
1X1
011
000
67 135 ▶ if (my $f = $self->{pullparser_file}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $f = $self->{'pullparser_file'}) { } 8 127 135
elsif (my $sref = $self->{'pullparser_str_ref'}) { } 127 0 127
68 # must try to parse more from the file
69 8 my $buf;
70 8 ▶ if (read($f, $buf, 512)) {
Branch: 1 branch
BranchTrueFalseTotal
if (read $f, $buf, 512) { } 5 3 8
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
BranchTrueFalseTotal
if ($pos < length $$sref) { } 122 5 127
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__
« blib/lib/HTML/HeadParser.pm ↑ Summary blib/lib/HTML/TokeParser.pm »