| 1 | package HTML::HTML5::Parser; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | ## skip Test::Tabs | ||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use 5.008001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 11 | our $AUTOLOAD; | |||||||||||||||||||||||||||
| 9 | 11 | our $VERSION = '0.992'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 11 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 11 | ▶ | use HTML::HTML5::Parser::Error; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 11 | ▶ | use HTML::HTML5::Parser::TagSoupParser; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 11 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 11 | ▶ | use URI::file; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 11 | ▶ | use Encode qw(encode_utf8); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 11 | ▶ | use XML::LibXML; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 11 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||
| 20 | 11 | ▶ | croak "Please upgrade to XML::LibXML 1.94" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | if XML::LibXML->VERSION =~ /^1\.9[12]/; | ||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | sub new | ||||||||||||||||||||||||||||
| 25 | 705 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 705 | my $class = shift; | |||||||||||||||||||||||||||
| 27 | 705 | my %p = @_; | |||||||||||||||||||||||||||
| 28 | 705 | my $self = bless { | |||||||||||||||||||||||||||
| 29 | errors => [], | ||||||||||||||||||||||||||||
| 30 | parser => HTML::HTML5::Parser::TagSoupParser->new(%p), | ||||||||||||||||||||||||||||
| 31 | }, $class; | ||||||||||||||||||||||||||||
| 32 | 705 | return $self; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | sub parse_file | ||||||||||||||||||||||||||||
| 36 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
parse_file: called CC=10 SCAR=29.2
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | 4 | require HTML::HTML5::Parser::UA; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 40 | 4 | my $file = shift; | |||||||||||||||||||||||||||
| 41 | 4 | ▶ | my $opts = shift || {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 4 | ▶ | unless (blessed($file) and $file->isa('URI')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($file) and $file->isa("URI")
MC/DC0%0/2
builtin::blessed($file) and $file->isa("URI")
builtin::blessed($file)
$file->isa("URI")
Truth table33%1/3
A and B
A= builtin::blessed($file)B= $file->isa("URI")
| |||||||||||||||||||||||||||||
| 44 | { | ||||||||||||||||||||||||||||
| 45 | 4 | ▶ | if ($file =~ /^[a-z][a-z0-9_\.\+-]+:\S+$/i) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 2 | { $file = URI->new($file); } | |||||||||||||||||||||||||||
| 47 | else | ||||||||||||||||||||||||||||
| 48 | 2 | { $file = URI::file->new_abs($file); } | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 4 | my $response = HTML::HTML5::Parser::UA->get($file, $opts->{user_agent}); | |||||||||||||||||||||||||||
| 52 | croak "HTTP response code was not 200 OK. (Set \$opts{ignore_http_response_code} to ignore this error.)" | ||||||||||||||||||||||||||||
| 53 | 4 | ▶ | unless ($response->{success} || $opts->{ignore_http_response_code}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$response->{"success"} or $opts->{"ignore_http_response_code"}
MC/DC0%0/2
$response->{"success"} or $opts->{"ignore_http_response_code"}
$response->{"success"}
$opts->{"ignore_http_response_code"}
Truth table33%1/3
A or B
A= $response->{"success"}B= $opts->{"ignore_http_response_code"}
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 4 | my $content = $response->{decoded_content}; | |||||||||||||||||||||||||||
| 56 | 4 | my $c_type = $response->{headers}{'content-type'}; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 4 | $opts->{'response'} = $response; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 4 | ▶ | if ($c_type =~ /xml/i and not $opts->{'force_html'}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$c_type =~ /xml/i and not $opts->{"force_html"}
MC/DC0%0/2
$c_type =~ /xml/i and not $opts->{"force_html"}
$c_type =~ /xml/i
not $opts->{"force_html"}
Truth table33%1/3
A and not(B)
A= $c_type =~ /xml/iB= not $opts->{"force_html"}
| |||||||||||||||||||||||||||||
| 61 | { | ||||||||||||||||||||||||||||
| 62 | 0 | $opts->{'parser_used'} = 'XML::LibXML::Parser'; | |||||||||||||||||||||||||||
| 63 | 0 | my $xml_parser = XML::LibXML->new; | |||||||||||||||||||||||||||
| 64 | 0 | $xml_parser->validation(0); | |||||||||||||||||||||||||||
| 65 | 0 | $xml_parser->recover(2); | |||||||||||||||||||||||||||
| 66 | 0 | $xml_parser->base_uri($response->base); | |||||||||||||||||||||||||||
| 67 | $xml_parser->load_catalog($opts->{'xml_catalogue'}) | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if -r $opts->{'xml_catalogue'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | return $xml_parser->parse_string($content); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 4 | return $self->parse_string($content, $opts); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 11 | *parse_html_file = \&parse_file; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | sub parse_fh | ||||||||||||||||||||||||||||
| 77 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
parse_fh: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 79 | 1 | my $handle = shift; | |||||||||||||||||||||||||||
| 80 | 1 | ▶ | my $opts = shift || {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 1 | my $string = ''; | |||||||||||||||||||||||||||
| 83 | 1 | ▶ | while (<$handle>) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | { | ||||||||||||||||||||||||||||
| 85 | 3 | $string .= $_; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 1 | return $self->parse_string($string, $opts); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | 11 | *parse_html_fh = \&parse_fh; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | sub parse_string | ||||||||||||||||||||||||||||
| 93 | 708 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
parse_string: called CC=5 SCAR=17.4
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 708 | my $self = shift; | |||||||||||||||||||||||||||
| 95 | 708 | my $text = shift; | |||||||||||||||||||||||||||
| 96 | 708 | ▶ | my $opts = shift || {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
shift() || {}
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 708 | $self->{'errors'} = []; | |||||||||||||||||||||||||||
| 99 | 708 | $opts->{'parser_used'} = 'HTML::HTML5::Parser'; | |||||||||||||||||||||||||||
| 100 | 708 | my $dom = XML::LibXML::Document->createDocument; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 708 | ▶ | if (defined $opts->{'encoding'}||1) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
defined $opts->{"encoding"} or 1
MC/DC0%0/1
defined $opts->{"encoding"} or 1
defined $opts->{"encoding"}
Truth table50%1/2
A
A= defined $opts->{"encoding"}
| |||||||||||||||||||||||||||||
| 103 | { | ||||||||||||||||||||||||||||
| 104 | # XXX AGAIN DO THIS TO STOP ENORMOUS MEMORY LEAKS | ||||||||||||||||||||||||||||
| 105 | 708 | ▶ | if (utf8::is_utf8($text)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 2 | $text = encode_utf8($text); | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | 708 | my ($errh, $errors) = @{$self}{qw(error_handler errors)}; | |||||||||||||||||||||||||||
| 109 | $self->{parser}->parse_byte_string( | ||||||||||||||||||||||||||||
| 110 | $opts->{'encoding'}, $text, $dom, | ||||||||||||||||||||||||||||
| 111 | 2147 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 112 | 2147 | my $err = HTML::HTML5::Parser::Error->new(@_); | |||||||||||||||||||||||||||
| 113 | 2147 | ▶ | $errh->($err) if $errh; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 2147 | push @$errors, $err; | |||||||||||||||||||||||||||
| 115 | 708 | }); | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | else | ||||||||||||||||||||||||||||
| 118 | { | ||||||||||||||||||||||||||||
| 119 | 0 | ▶ | $self->{parser}->parse_char_string($text, $dom, sub{ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 120 | 0 | my $err = HTML::HTML5::Parser::Error->new(@_); | |||||||||||||||||||||||||||
| 121 | 0 | ▶ | $self->{error_handler}->($err) if $self->{error_handler}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 0 | push @{$self->{'errors'}}, $err; | |||||||||||||||||||||||||||
| 123 | 0 | }); | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 708 | return $dom; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | 11 | *parse_html_string = \&parse_string; | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | # TODO: noembed, noframes, noscript | ||||||||||||||||||||||||||||
| 131 | my %within = ( | ||||||||||||||||||||||||||||
| 132 | html => [qw/html/], | ||||||||||||||||||||||||||||
| 133 | frameset => [qw/html frameset/], | ||||||||||||||||||||||||||||
| 134 | frame => [qw/html frameset frame/], | ||||||||||||||||||||||||||||
| 135 | head => [qw/html head/], | ||||||||||||||||||||||||||||
| 136 | title => [qw/html head title/], | ||||||||||||||||||||||||||||
| 137 | style => [qw/html head style/], | ||||||||||||||||||||||||||||
| 138 | 55 | (map { $_ => undef } | |||||||||||||||||||||||||||
| 139 | qw/base link meta basefont bgsound/), | ||||||||||||||||||||||||||||
| 140 | body => [qw/html body/], | ||||||||||||||||||||||||||||
| 141 | script => [qw/html body script/], | ||||||||||||||||||||||||||||
| 142 | div => [qw/html body div/], | ||||||||||||||||||||||||||||
| 143 | 572 | (map { $_ => [qw/html body div/, $_] } | |||||||||||||||||||||||||||
| 144 | qw/a abbr acronym address applet area article aside big blockquote | ||||||||||||||||||||||||||||
| 145 | button center code details dir dl em fieldset figure font | ||||||||||||||||||||||||||||
| 146 | footer form h1 h2 h3 h4 h5 h6 header hgroup i iframe | ||||||||||||||||||||||||||||
| 147 | listing marquee menu nav nobr object ol p plaintext pre | ||||||||||||||||||||||||||||
| 148 | ruby s section small strike strong tt u ul xmp/), | ||||||||||||||||||||||||||||
| 149 | 121 | (map { $_ => undef } | |||||||||||||||||||||||||||
| 150 | qw/br col command datagrid embed hr img input keygen | ||||||||||||||||||||||||||||
| 151 | param wbr/), | ||||||||||||||||||||||||||||
| 152 | dd => [qw/html body dl dd/], | ||||||||||||||||||||||||||||
| 153 | dd => [qw/html body dl dt/], | ||||||||||||||||||||||||||||
| 154 | figcaption => [qw/html body figure/], | ||||||||||||||||||||||||||||
| 155 | li => [qw/html body ul li/], | ||||||||||||||||||||||||||||
| 156 | ul__li => [qw/html body ul li/], | ||||||||||||||||||||||||||||
| 157 | ol__li => [qw/html body ol li/], | ||||||||||||||||||||||||||||
| 158 | optgroup => [qw/html body form div select/], | ||||||||||||||||||||||||||||
| 159 | option => [qw/html body form div select/], | ||||||||||||||||||||||||||||
| 160 | rp => [qw/html body div ruby/], | ||||||||||||||||||||||||||||
| 161 | rt => [qw/html body div ruby/], | ||||||||||||||||||||||||||||
| 162 | select => [qw/html body form div select/], | ||||||||||||||||||||||||||||
| 163 | summary => [qw/html body div details/], | ||||||||||||||||||||||||||||
| 164 | table => [qw/html body table/], | ||||||||||||||||||||||||||||
| 165 | 66 | (map { $_ => [qw/html body table/, $_] } | |||||||||||||||||||||||||||
| 166 | qw/thead tfoot tbody tr caption colgroup/), | ||||||||||||||||||||||||||||
| 167 | 11 | (map { $_ => [qw/html body table tbody tr/, $_] } | |||||||||||||||||||||||||||
| 168 | qw/td th/), | ||||||||||||||||||||||||||||
| 169 | textarea => [qw/html body form div textarea/], | ||||||||||||||||||||||||||||
| 170 | ); | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | sub parse_balanced_chunk | ||||||||||||||||||||||||||||
| 173 | 12 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
parse_balanced_chunk: called CC=23 SCAR=32.9
Pod
documented
| |||||||||||||||||||||||||||||
| 174 | 12 | my ($self, $chunk, $o) = @_; | |||||||||||||||||||||||||||
| 175 | 12 | ▶ | my %options = %{ $o || {} }; | ||||||||||||||||||||||||||
|
Condition50%1/2
$o || {}
MC/DC0%0/1
$o || {}
$o
Truth table50%1/2
A
A= $o
| |||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 12 | ▶ | $options{as} = 'default' unless defined $options{as}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 12 | ▶ | my $w = $options{force_within} || $options{within} || 'div'; | ||||||||||||||||||||||||||
|
Condition60%3/5
$options{'force_within'} || $options{'within'} || 'div'
$options{"force_within"} or $options{"within"}
MC/DC0%0/2
$options{'force_within'} || $options{'within'} || 'div'
$options{"force_within"}
$options{"within"}
Truth table66%2/3
A or B
A= $options{"force_within"}B= $options{"within"}
| |||||||||||||||||||||||||||||
| 180 | 12 | my $ancestors = $within{ lc $w }; | |||||||||||||||||||||||||||
| 181 | 12 | ▶ | croak "Cannot parse chunk as if within $w." | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | if !defined $ancestors; | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 12 | my $parent = $ancestors->[-1]; | |||||||||||||||||||||||||||
| 185 | 12 | my $n = scalar(@$ancestors) - 2; | |||||||||||||||||||||||||||
| 186 | 12 | ▶ | my @a = $n ? @$ancestors[0 .. $n] : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 12 | my $uniq = sprintf('rand_id_%09d', int rand 1_000_000_000); | |||||||||||||||||||||||||||
| 189 | my $document = | ||||||||||||||||||||||||||||
| 190 | "<!doctype html>\n". | ||||||||||||||||||||||||||||
| 191 | 12 | (join q{}, map { "<$_>" } @a). | |||||||||||||||||||||||||||
| 192 | "<$parent id='$uniq'>". | ||||||||||||||||||||||||||||
| 193 | $chunk. | ||||||||||||||||||||||||||||
| 194 | ''.# "</$parent>". | ||||||||||||||||||||||||||||
| 195 | '';# (join q{}, map { "</$_>" } reverse @a); | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 12 | my $dom = $self->parse_html_string($document); | |||||||||||||||||||||||||||
| 198 | 12 | $parent = $dom->findnodes("//*[\@id='$uniq']")->get_node(1); | |||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 12 | ▶ | if ($options{debug}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 201 | { | ||||||||||||||||||||||||||||
| 202 | 0 | ▶ | if (exists &Test::More::diag) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | { | ||||||||||||||||||||||||||||
| 204 | 0 | Test::More::diag($document); | |||||||||||||||||||||||||||
| 205 | 0 | Test::More::diag($dom->toString); | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | else | ||||||||||||||||||||||||||||
| 208 | { | ||||||||||||||||||||||||||||
| 209 | 0 | warn $document."\n"; | |||||||||||||||||||||||||||
| 210 | 0 | warn $dom->toString."\n"; | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 12 | my @results = $parent->childNodes; | |||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 12 | ▶ | unless ($options{force_within}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | { | ||||||||||||||||||||||||||||
| 218 | 11 | ▶ | while ($parent) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 219 | { | ||||||||||||||||||||||||||||
| 220 | 50 | my $sibling = $parent->nextSibling; | |||||||||||||||||||||||||||
| 221 | 50 | ▶ | while ($sibling) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | { | ||||||||||||||||||||||||||||
| 223 | 4 | ▶ | unless ($sibling->nodeName =~ /^(head|body)$/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 224 | { | ||||||||||||||||||||||||||||
| 225 | $sibling->setAttribute('data-perl-html-html5-parser-outlier', 1) | ||||||||||||||||||||||||||||
| 226 | if $options{mark_outliers} | ||||||||||||||||||||||||||||
| 227 | 2 | ▶ | && $sibling->can('setAttribute'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$options{"mark_outliers"} and $sibling->can("setAttribute")
MC/DC0%0/2
$options{"mark_outliers"} and $sibling->can("setAttribute")
$options{"mark_outliers"}
$sibling->can("setAttribute")
Truth table66%2/3
A and B
A= $options{"mark_outliers"}B= $sibling->can("setAttribute")
| |||||||||||||||||||||||||||||
| 228 | 2 | push @results, $sibling; | |||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | 4 | $sibling = $sibling->nextSibling; | |||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 50 | $sibling = $parent->previousSibling; | |||||||||||||||||||||||||||
| 234 | 50 | ▶ | while ($sibling) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 235 | { | ||||||||||||||||||||||||||||
| 236 | 9 | ▶ | unless ($sibling->nodeName =~ /^(head|body)$/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | { | ||||||||||||||||||||||||||||
| 238 | $sibling->setAttribute('data-perl-html-html5-parser-outlier', 1) | ||||||||||||||||||||||||||||
| 239 | if $options{mark_outliers} | ||||||||||||||||||||||||||||
| 240 | 2 | ▶ | && $sibling->can('setAttribute'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$options{"mark_outliers"} and $sibling->can("setAttribute")
MC/DC50%1/2
$options{"mark_outliers"} and $sibling->can("setAttribute")
$options{"mark_outliers"}
$sibling->can("setAttribute")
Truth table66%2/3
A and B
A= $options{"mark_outliers"}B= $sibling->can("setAttribute")
| |||||||||||||||||||||||||||||
| 241 | 2 | unshift @results, $sibling; | |||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | 9 | $sibling = $sibling->previousSibling; | |||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 50 | $parent = $parent->parentNode; | |||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 12 | my $frag = XML::LibXML::DocumentFragment->new; | |||||||||||||||||||||||||||
| 251 | 12 | $frag->appendChild($_) foreach @results; | |||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 12 | ▶ | if (lc $options{as} eq 'list') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 254 | { | ||||||||||||||||||||||||||||
| 255 | 1 | ▶ | return wantarray ? @results : XML::LibXML::NodeList->new(@results); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 11 | ▶ | return wantarray ? @results : $frag; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | sub load_html | ||||||||||||||||||||||||||||
| 262 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
load_html: called CC=7 SCAR=20.0
Pod
documented
| |||||||||||||||||||||||||||||
| 263 | 4 | my $class_or_self = shift; | |||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | 4 | ▶ | my %args = map { ref($_) eq 'HASH' ? (%$_) : $_ } @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 266 | 4 | my $URI = delete($args{URI}); | |||||||||||||||||||||||||||
| 267 | 4 | ▶ | $URI = "$URI" if defined $URI; # stringify in case it is an URI object | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 268 | 4 | ▶ | my $parser = ref($class_or_self) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | ? $class_or_self | ||||||||||||||||||||||||||||
| 270 | : $class_or_self->new; | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | 4 | my $dom; | |||||||||||||||||||||||||||
| 273 | 4 | ▶ | if ( defined $args{location} ) | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 274 | 2 | { $dom = $parser->parse_file( "$args{location}" ) } | |||||||||||||||||||||||||||
| 275 | elsif ( defined $args{string} ) | ||||||||||||||||||||||||||||
| 276 | 1 | { $dom = $parser->parse_string( $args{string}, $URI ) } | |||||||||||||||||||||||||||
| 277 | elsif ( defined $args{IO} ) | ||||||||||||||||||||||||||||
| 278 | 1 | { $dom = $parser->parse_fh( $args{IO}, $URI ) } | |||||||||||||||||||||||||||
| 279 | else | ||||||||||||||||||||||||||||
| 280 | 0 | { croak("HTML::HTML5::Parser->load_html: specify location, string, or IO"); } | |||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 4 | return $dom; | |||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | sub load_xml | ||||||||||||||||||||||||||||
| 286 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
load_xml: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 287 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 288 | 0 | my $dom; | |||||||||||||||||||||||||||
| 289 | 0 | eval { | |||||||||||||||||||||||||||
| 290 | 0 | $dom = XML::LibXML->load_xml(@_); | |||||||||||||||||||||||||||
| 291 | }; | ||||||||||||||||||||||||||||
| 292 | 0 | ▶ | return $dom if blessed($dom); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 293 | 0 | return $self->load_html(@_); | |||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | sub AUTOLOAD | ||||||||||||||||||||||||||||
| 297 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||
| 298 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 299 | 0 | my $func = $AUTOLOAD; | |||||||||||||||||||||||||||
| 300 | 0 | $func =~ s/.*://; | |||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | # LibXML Push Parser. | ||||||||||||||||||||||||||||
| 303 | 0 | ▶ | if ($func =~ /^( parse_chunk | start_push | push | finish_push )$/xi) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 304 | { | ||||||||||||||||||||||||||||
| 305 | 0 | croak "Push parser ($func) not implemented by HTML::HTML5::Parser."; | |||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | # Misc LibXML functions with no compatible interface provided. | ||||||||||||||||||||||||||||
| 309 | 0 | ▶ | if ($func =~ /^( parse_balanced_chunk | parse_xml_chunk | | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 310 | process_?xincludes | get_last_error )$/xi) | ||||||||||||||||||||||||||||
| 311 | { | ||||||||||||||||||||||||||||
| 312 | 0 | croak "$func not implemented by HTML::HTML5::Parser."; | |||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | # Fixed options which are true. | ||||||||||||||||||||||||||||
| 316 | 0 | ▶ | if ($func =~ /^( recover | recover_silently | expand_entities | | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 317 | keep_blanks | no_network )$/xi) | ||||||||||||||||||||||||||||
| 318 | { | ||||||||||||||||||||||||||||
| 319 | 0 | my $set = shift; | |||||||||||||||||||||||||||
| 320 | 0 | ▶ | if ((!$set) && defined $set) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $set and defined $set
MC/DC0%0/2
not $set and defined $set
not $set
defined $set
Truth table0%0/3
not(A) and B
A= not $setB= defined $set
| |||||||||||||||||||||||||||||
| 321 | { | ||||||||||||||||||||||||||||
| 322 | 0 | carp "Option $func cannot be switched off."; | |||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||
| 324 | 0 | return 1; | |||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | # Fixed options which are false. | ||||||||||||||||||||||||||||
| 328 | 0 | ▶ | if ($func =~ /^( validation | pedantic_parser | line_numbers | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 329 | load_ext_dtd | complete_attributes | expand_xinclude | | ||||||||||||||||||||||||||||
| 330 | load_catalog | base_uri | gdome_dom | clean_namespaces )$/xi) | ||||||||||||||||||||||||||||
| 331 | { | ||||||||||||||||||||||||||||
| 332 | 0 | my $set = shift; | |||||||||||||||||||||||||||
| 333 | 0 | ▶ | if (($set) && defined $set) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$set and defined $set
MC/DC0%0/2
$set and defined $set
$set
defined $set
Truth table0%0/3
A and B
A= $setB= defined $set
| |||||||||||||||||||||||||||||
| 334 | { | ||||||||||||||||||||||||||||
| 335 | 0 | carp "Option $func cannot be switched on."; | |||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||
| 337 | 0 | return 0; | |||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | 0 | ▶ | carp "HTML::HTML5::Parser doesn't understand '$func'." if length $func; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | sub error_handler | ||||||||||||||||||||||||||||
| 344 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
error_handler: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 345 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 346 | 0 | ▶ | $self->{error_handler} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 347 | 0 | return $self->{error_handler}; | |||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | sub errors | ||||||||||||||||||||||||||||
| 351 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
errors: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 352 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 353 | 0 | return @{ $self->{errors} }; | |||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | sub compat_mode | ||||||||||||||||||||||||||||
| 357 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
compat_mode: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 358 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 359 | 0 | my $node = shift; | |||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | 0 | return $self->{parser}->_data($node)->{'manakai_compat_mode'}; | |||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | sub charset | ||||||||||||||||||||||||||||
| 365 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
charset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 366 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 367 | 2 | my $node = shift; | |||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | 2 | return $self->{parser}->_data($node)->{'charset'}; | |||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | sub dtd_public_id | ||||||||||||||||||||||||||||
| 373 | 688 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
dtd_public_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 374 | 688 | my $self = shift; | |||||||||||||||||||||||||||
| 375 | 688 | my $node = shift; | |||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | 688 | return $self->{parser}->_data($node)->{'DTD_PUBLIC_ID'}; | |||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | sub dtd_system_id | ||||||||||||||||||||||||||||
| 381 | 687 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
dtd_system_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 382 | 687 | my $self = shift; | |||||||||||||||||||||||||||
| 383 | 687 | my $node = shift; | |||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | 687 | return $self->{parser}->_data($node)->{'DTD_SYSTEM_ID'}; | |||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | sub dtd_element | ||||||||||||||||||||||||||||
| 389 | 687 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
dtd_element: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 390 | 687 | my $self = shift; | |||||||||||||||||||||||||||
| 391 | 687 | my $node = shift; | |||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | 687 | return $self->{parser}->_data($node)->{'DTD_ELEMENT'}; | |||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | sub source_line | ||||||||||||||||||||||||||||
| 397 | 10 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
source_line: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 398 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 399 | 10 | my $node = shift; | |||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | 10 | ▶ | my $data = ref $self ? $self->{parser}->_data($node) : | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 402 | HTML::HTML5::Parser::TagSoupParser::DATA($node); | ||||||||||||||||||||||||||||
| 403 | 10 | my $line = $data->{'manakai_source_line'}; | |||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | 10 | ▶ | if (wantarray) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 406 | { | ||||||||||||||||||||||||||||
| 407 | return ( | ||||||||||||||||||||||||||||
| 408 | $line, | ||||||||||||||||||||||||||||
| 409 | $data->{'manakai_source_column'}, | ||||||||||||||||||||||||||||
| 410 | 9 | ▶ | ($data->{'implied'} || 0), | ||||||||||||||||||||||||||
|
Condition100%2/2
$data->{'implied'} || 0
MC/DC100%1/1
$data->{'implied'} || 0
$data->{'implied'}
Truth table100%2/2
A
A= $data->{'implied'}
| |||||||||||||||||||||||||||||
| 411 | ); | ||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||
| 413 | else | ||||||||||||||||||||||||||||
| 414 | { | ||||||||||||||||||||||||||||
| 415 | 1 | return $line; | |||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | 0 | ▶ | sub DESTROY {} | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | __END__ | ||||||||||||||||||||||||||||