blib/lib/HTML/Parser.pm

filter: Statementstmt 96.9% 63 / 65 Branchbran 86.6% 26 / 30 Conditioncond 83.3% 5 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 8 / 8 Podpod 60.0% 3 / 5 totaltotal 90.6% 107 / 118 CC 19 SCAR 19.5
CC
19
Cov
93%
init
11.1
parse_file
7.0
netscape_buggy_comment
2.0
CRAP 7.0
« blib/lib/HTML/TokeParser.pm ↑ Summary blib/lib/HTML/Entities.pm »
1 package HTML::Parser;
2  
3 49 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 49 our $VERSION = '3.87';
6  
7 49 require HTML::Entities;
8  
9 49 require XSLoader;
10 49 XSLoader::load('HTML::Parser', $VERSION);
11  
12 sub new
13 129 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod documented
14 129 my $class = shift;
15 129 my $self = bless {}, $class;
16 129 return $self->init(@_);
17 }
18  
19  
20 sub init
21 129 ▶{
Subroutine init: called CC=11 SCAR=24.1
Pod undocumented
22 129 my $self = shift;
23 129 $self->_alloc_pstate;
24  
25 129 my %arg = @_;
26 129 ▶ my $api_version = delete $arg{api_version} || (@_ ? 3 : 2);
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 23 46 69
Condition66%2/3
delete $arg{'api_version'} || (@_ ? 3 : 2)
l!l&&r!l&&!r
60690
MC/DC0%0/2
delete $arg{'api_version'} || (@_ ? 3 : 2)
delete $arg{'api_version'} (@_ ? 3 : 2)
Truth table66%2/3
A || B
A= delete $arg{'api_version'}B= (@_ ? 3 : 2)
ABresult
1X1
011
000
27 129 ▶ if ($api_version >= 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($api_version >= 4) 1 128 129
28 1 require Carp;
29 1 Carp::croak("API version $api_version not supported " .
30 "by HTML::Parser $VERSION");
31 }
32  
33 128 ▶ if ($api_version < 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($api_version < 3) 47 81 128
34 # Set up method callbacks compatible with HTML-Parser-2.xx
35 47 $self->handler(text => "text", "self,text,is_cdata");
36 47 $self->handler(end => "end", "self,tagname,text");
37 47 $self->handler(process => "process", "self,token0,text");
38 47 $self->handler(start => "start",
39 "self,tagname,attr,attrseq,text");
40  
41 $self->handler(comment =>
42 53 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
43 53 my($self, $tokens) = @_;
44 53 for (@$tokens) {
45 55 $self->comment($_);
46 }
47 47 }, "self,tokens");
48  
49 $self->handler(declaration =>
50 10 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
51 10 my $self = shift;
52 10 $self->declaration(substr($_[0], 2, -1));
53 47 }, "self,text");
54 }
55  
56 128 ▶ if (my $h = delete $arg{handlers}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $h = delete $arg{"handlers"}) 3 125 128
57 3 ▶ $h = {@$h} if ref($h) eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if ref $h eq "ARRAY" 0 3 3
58 3 ▶ while (my($event, $cb) = each %$h) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$h) 3 3 6
59 3 $self->handler($event => @$cb);
60 }
61 }
62  
63 # In the end we try to assume plain attribute or handler
64 128 ▶ while (my($option, $val) = each %arg) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %arg) 101 128 229
65 101 ▶ if ($option =~ /^(\w+)_h$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($option =~ /^(\w+)_h$/) { } 57 44 101
elsif ($option =~ /^(text|start|end|process|declaration|comment)$/) { } 0 44 44
66 57 $self->handler($1 => @$val);
67 }
68 elsif ($option =~ /^(text|start|end|process|declaration|comment)$/) {
69 0 require Carp;
70 0 Carp::croak("Bad constructor option '$option'");
71 }
72 else {
73 44 $self->$option($val);
74 }
75 }
76  
77 128 return $self;
78 }
79  
80  
81 sub parse_file
82 18 ▶{
Subroutine parse_file: called CC=7 SCAR=19.5
Pod documented
83 18 my($self, $file) = @_;
84 18 my $opened;
85 18 ▶ if (!ref($file) && ref(\$file) ne "GLOB") {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $file and ref \$file ne "GLOB") 10 8 18
Condition100%3/3
not ref $file and ref \$file ne "GLOB"
!ll&&!rl&&r
6210
MC/DC100%2/2
not ref $file and ref \$file ne "GLOB"
not ref $file ref \$file ne "GLOB"
Truth table100%3/3
not(A) and B
A= not ref $fileB= ref \$file ne "GLOB"
ABresult
0X0
100
111
86 # Assume $file is a filename
87 10 local(*F);
88 10 ▶ open(F, "<", $file) || return undef;
Branch: 1 branch
BranchTrueFalseTotal
open F, "<", $file or return undef 10 0 10
89 10 binmode(F); # should we? good for byte counts
90 10 $opened++;
91 10 $file = *F;
92 }
93 18 my $chunk = '';
94 18 ▶ while (read($file, $chunk, 512)) {
Branch: 1 branch
BranchTrueFalseTotal
if (read $file, $chunk, 512) 5006 16 5022
95 5006 ▶ $self->parse($chunk) || last;
Branch: 1 branch
BranchTrueFalseTotal
$self->parse($chunk) or last 5004 2 5006
96 }
97 18 ▶ close($file) if $opened;
Branch: 1 branch
BranchTrueFalseTotal
if $opened 10 8 18
98 18 $self->eof;
99 }
100  
101  
102 sub netscape_buggy_comment # legacy
103 1 ▶{
Subroutine netscape_buggy_comment: called CC=2 SCAR=7.0
Pod undocumented
104 1 my $self = shift;
105 1 require Carp;
106 1 Carp::carp("netscape_buggy_comment() is deprecated. " .
107 "Please use the strict_comment() method instead");
108 1 my $old = !$self->strict_comment;
109 1 ▶ $self->strict_comment(!shift) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
110 1 return $old;
111 }
112  
113 # set up method stubs
114 15504 ▶sub text { }
Subroutine text: called CC=1 SCAR=0.0
Pod documented
115 49 *start = \&text;
116 49 *end = \&text;
117 49 *comment = \&text;
118 49 *declaration = \&text;
119 49 *process = \&text;
120  
121 49 1;
122  
123 __END__
« blib/lib/HTML/TokeParser.pm ↑ Summary blib/lib/HTML/Entities.pm »