blib/lib/XHTML/Util.pm

filter: Statementstmt 78.4% 189 / 241 Branchbran 69.3% 61 / 88 Conditioncond 47.0% 24 / 51 MC/DCmcdc 33.3% 10 / 30 Subroutinesub 90.0% 27 / 30 Podpod 100% 12 / 12 totaltotal 71.4% 323 / 452 CC 81 SCAR 35.8
CC
81
Cov
72%
inline_stylesheets
171.9
_fragment_to_xhtml
72.0
_enpara_this_nodes_content
28.0
CRAP 35.9
↑ Summary
1 package XHTML::Util;
2 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶no warnings "uninitialized";
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 our $VERSION = "0.04";
6 15 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use Carp; # By verbosity?
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use Scalar::Util "blessed";
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use HTML::Tagset 3.02 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 ▶use HTML::Entities;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 15 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 15 ▶use HTML::Selector::XPath ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 15 ▶use HTML::TokeParser::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 # LWP::Simple, external styles
15 15 ▶use CSS::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 15 my $isKnown = \%HTML::Tagset::isKnown;
18 15 my $emptyElement = \%HTML::Tagset::emptyElement;
19 #my $canTighten = \%HTML::Tagset::canTighten;
20 #my $isHeadElement = \%HTML::Tagset::isHeadElement;
21 15 my $isBodyElement = \%HTML::Tagset::isBodyElement;
22 15 my $isPhraseMarkup = \%HTML::Tagset::isPhraseMarkup;
23 #my $isHeadOrBodyElement = \%HTML::Tagset::isHeadOrBodyElement;
24 #my $isList = \%HTML::Tagset::isList;
25 #my $isTableElement = \%HTML::Tagset::isTableElement;
26 15 my $isFormElement = \%HTML::Tagset::isFormElement;
27 #my $p_closure_barriers = \@HTML::Tagset::p_closure_barriers;
28  
29 # Accommodate HTML::TokeParser's idea of a "tag."
30 15 for my $t ( keys %{$emptyElement} ) { $isKnown->{"$t/"} = 1 }
31 750 my $isBlockLevel = { map {; $_ => 1 }
32 1395 ▶ grep { ! ( $isPhraseMarkup->{$_} || $isFormElement->{$_} ) }
Condition100%3/3
$isPhraseMarkup->{$_} || $isFormElement->{$_}
l!l&&r!l&&!r
540105750
MC/DC100%2/2
$isPhraseMarkup->{$_} || $isFormElement->{$_}
$isPhraseMarkup->{$_} $isFormElement->{$_}
Truth table100%3/3
A || B
A= $isPhraseMarkup->{$_}B= $isFormElement->{$_}
ABresult
1X1
011
000
33 15 keys %{$isBodyElement}
34 };
35  
36 14 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
37 14 my $class = shift;
38 14 my $self = bless {}, $class;
39 14 $self;
40 }
41  
42 5 ▶sub strip_tags {
Subroutine strip_tags: called CC=7 SCAR=19.6
Pod documented
43 5 my $self = shift;
44 5 my $content = shift;
45 5 my $xpath = HTML::Selector::XPath::selector_to_xpath(shift);
46 4 ▶ carp "No selector was given to strip_tags" and return $content unless $xpath;
Branch: 1 branch
BranchTrueFalseTotal
unless $xpath 1 3 4
Condition60%3/5
$xpath || carp('No selector was given to strip_tags') && (return $content)
l!l&&r!l&&!r
310
carp("No selector was given to strip_tags") and return $content
!ll
01
MC/DC0%0/2
$xpath || carp('No selector was given to strip_tags') && (return $content)
$xpath carp("No selector was given to strip_tags")
Truth table66%2/3
A || B
A= $xpathB= carp("No selector was given to strip_tags")
ABresult
1X1
011
000
47 3 ▶ my $root = blessed($content) =~ /\AXML::LibXML::/ ?
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($content) =~ /\AXML::LibXML::/ ? : 0 3 3
48 $content : $self->_fragment_to_body_node($content);
49  
50 3 my $doc = $root->getOwnerDocument;
51 3 for my $node ( $root->findnodes($xpath) )
52 {
53 2 my $fragment = $doc->createDocumentFragment;
54 2 for my $n ( $node->childNodes )
55 {
56 4 $fragment->appendChild($n);
57 }
58 2 $node->replaceNode($fragment);
59 }
60 3 my $out = "";
61 3 $out .= $_->serialize(1) for $root->childNodes;
62 3 _trim($out);
63 }
64  
65 8 ▶sub _trim {
Subroutine _trim: called CC=3 SCAR=11.0
66 8 s/\A\s+|\s+\z//g for @_;
67 8 ▶ wantarray ? @_ : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 5 8
68 }
69  
70 1 ▶sub remove { # Synonymous for remove_nodes, all gone.
Subroutine remove: called CC=7 SCAR=22.1
Pod documented
71 1 my $self = shift;
72 # my $content = shift;
73 1 ▶ my $content = $self->_sanitize_fragment(shift) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $content = $self->_sanitize_fragment(shift()) or return 1 0 1
74 1 my $xpath = HTML::Selector::XPath::selector_to_xpath(shift);
75 1 ▶ carp "No selector was given to strip_tags" and return $content unless $xpath;
Branch: 1 branch
BranchTrueFalseTotal
unless $xpath 0 1 1
Condition20%1/5
$xpath || carp('No selector was given to strip_tags') && (return $content)
l!l&&r!l&&!r
100
carp("No selector was given to strip_tags") and return $content
!ll
00
MC/DC0%0/2
$xpath || carp('No selector was given to strip_tags') && (return $content)
$xpath carp("No selector was given to strip_tags")
Truth table33%1/3
A || B
A= $xpathB= carp("No selector was given to strip_tags")
ABresult
1X1
011
000
76 1 ▶ my $root = blessed($content) =~ /\AXML::LibXML::/ ?
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($content) =~ /\AXML::LibXML::/ ? : 0 1 1
77 $content : $self->_fragment_to_body_node($content);
78  
79 1 $_->parentNode->removeChild($_) for $root->findnodes($xpath);
80 1 my $out = "";
81 1 $out .= $_->serialize(1) for $root->childNodes;
82 1 _trim($out);
83 }
84  
85 # No... ? requires object->call shuffling to work : sub enpara_tag { +shift->{enpara_tag} = shift || "p"; }
86  
87 4 ▶sub enpara {
Subroutine enpara: called CC=9 SCAR=22.2
Pod documented
88 4 my $self = shift;
89 4 ▶ my $content = $self->_sanitize_fragment(shift) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $content = $self->_sanitize_fragment(shift()) or return 4 0 4
90 4 my $selector = shift;
91  
92 4 ▶ my $root = blessed($content) eq 'XML::LibXML::Element' ?
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($content) eq 'XML::LibXML::Element' ? : 0 4 4
93 $content : $self->_fragment_to_body_node($content);
94  
95 4 $root->normalize;
96 4 my $doc = $root->getOwnerDocument;
97  
98 4 ▶ if ( my $xpath = HTML::Selector::XPath::selector_to_xpath($selector) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $xpath = HTML::Selector::XPath::selector_to_xpath($selector)) 2 2 4
99 {
100 NODE:
101 2 for my $designated_enpara ( $root->findnodes($xpath) )
102 {
103 4 ▶ next unless $designated_enpara->nodeType == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $designated_enpara->nodeType == 1 0 4 4
104 4 ▶ if ( $designated_enpara->nodeName eq 'pre' ) # I don't think so, honky.
Branch: 1 branch
BranchTrueFalseTotal
if ($designated_enpara->nodeName eq "pre") 1 3 4
105 {
106 # Expand or leave it alone? or ->validate it...?
107 1 carp "It makes no sense to enpara within a <pre/>; skipping";
108 1 next NODE;
109 }
110 3 ▶ next unless $isBlockLevel->{$designated_enpara->nodeName};
Branch: 1 branch
BranchTrueFalseTotal
unless $$isBlockLevel{$designated_enpara->nodeName} 0 3 3
111 3 _enpara_this_nodes_content($designated_enpara, $doc);
112 }
113 }
114 4 _enpara_this_nodes_content($root, $doc);
115 4 my $out = "";
116 4 $out .= $_->serialize(1) for $root->childNodes;
117 4 _trim($out);
118 }
119  
120 7 ▶sub _enpara_this_nodes_content {
Subroutine _enpara_this_nodes_content: called CC=28 SCAR=33.3
121 7 my ( $parent, $doc ) = @_;
122 7 my $lastChild = $parent->lastChild;
123 7 my @naked_block;
124 7 for my $node ( $parent->childNodes )
125 {
126 38 ▶ if ( $isBlockLevel->{$node->nodeName}
Branch: 2 branches
BranchTrueFalseTotal
if ($$isBlockLevel{$node->nodeName} or $node->nodeName eq 'a' and grep {$_->nodeName eq 'img';} $node->childNodes) { } 12 26 38
elsif ($node->nodeType == 3 and $node->nodeValue =~ /(?:[^\S\n]*\n){2,}/) { } 16 10 26
Condition66%4/6
$$isBlockLevel{$node->nodeName} or $node->nodeName eq "a" and grep {$_->nodeName eq "img";} $node->childNodes
l!l&&r!l&&!r
12026
$node->nodeName eq "a" and grep {$_->nodeName eq "img";} $node->childNodes
!ll&&!rl&&r
2510
MC/DC33%1/3
$$isBlockLevel{$node->nodeName} or $node->nodeName eq "a" and grep {$_->nodeName eq "img";} $node->childNodes
$$isBlockLevel{$node->nodeName} $node->nodeName eq "a" grep {$_->nodeName eq "img";} $node->childNodes
Truth table75%3/4
A or B and C
A= $$isBlockLevel{$node->nodeName}B= $node->nodeName eq "a"C= grep {$_->nodeName eq "img";} $node->childNodes
ABCresult
1XX1
0111
00X0
0100
127 or
128 $node->nodeName eq "a" # special case block level, so IGNORE
129 and
130 1 grep { $_->nodeName eq "img" } $node->childNodes
131 )
132 {
133 12 ▶ next unless @naked_block; # nothing to enblock
Branch: 1 branch
BranchTrueFalseTotal
unless @naked_block 10 2 12
134 2 my $p = $doc->createElement("p");
135 2 $p->setAttribute("enpara","enpara");
136 2 $p->appendChild($_) for @naked_block;
137 2 ▶ $parent->insertBefore( $p, $node )
Branch: 1 branch
BranchTrueFalseTotal
if $p->textContent =~ /\S/ 2 0 2
138 if $p->textContent =~ /\S/;
139 2 @naked_block = ();
140 }
141 ▶ elsif ( $node->nodeType == 3
Condition100%3/3
$node->nodeType == 3 and $node->nodeValue =~ /(?:[^\S\n]*\n){2,}/
!ll&&!rl&&r
5516
MC/DC100%2/2
$node->nodeType == 3 and $node->nodeValue =~ /(?:[^\S\n]*\n){2,}/
$node->nodeType == 3 $node->nodeValue =~ /(?:[^\S\n]*\n){2,}/
Truth table100%3/3
A and B
A= $node->nodeType == 3B= $node->nodeValue =~ /(?:[^\S\n]*\n){2,}/
ABresult
0X0
100
111
142 and
143 $node->nodeValue =~ /(?:[^\S\n]*\n){2,}/
144 )
145 {
146 16 my $text = $node->nodeValue;
147 16 my @text_part = map { $doc->createTextNode($_) }
148 split /([^\S\n]*\n){2,}/, $text;
149  
150 16 my @new_node;
151 16 ▶ for ( my $x = 0; $x < @text_part; $x++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($x < @text_part) 47 16 63
152 {
153 47 ▶ if ( $text_part[$x]->nodeValue =~ /\S/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($text_part[$x]->nodeValue =~ /\S/) { } 14 33 47
154 {
155 14 push @naked_block, $text_part[$x];
156 }
157 else # it's a blank newline node so _STOP_
158 {
159 33 ▶ next unless @naked_block;
Branch: 1 branch
BranchTrueFalseTotal
unless @naked_block 21 12 33
160 12 my $p = $doc->createElement("p");
161 12 $p->setAttribute("enpara","enpara");
162 12 $p->appendChild($_) for @naked_block;
163 12 @naked_block = ();
164 12 push @new_node, $p;
165 }
166 }
167 16 ▶ if ( @new_node )
Branch: 1 branch
BranchTrueFalseTotal
if (@new_node) 7 9 16
168 {
169 7 $parent->insertAfter($new_node[0], $node);
170 7 ▶ for ( my $x = 1; $x < @new_node; $x++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($x < @new_node) 5 7 12
171 {
172 5 $parent->insertAfter($new_node[$x], $new_node[$x-1]);
173 }
174 }
175 16 $node->unbindNode;
176 }
177 else
178 {
179 10 push @naked_block, $node; # if $node->nodeValue =~ /\S/;
180 }
181  
182 28 ▶ if ( $node->isSameNode( $lastChild )
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isSameNode($lastChild) and @naked_block) 5 23 28
Condition100%3/3
$node->isSameNode($lastChild) and @naked_block
!ll&&!rl&&r
2215
MC/DC100%2/2
$node->isSameNode($lastChild) and @naked_block
$node->isSameNode($lastChild) @naked_block
Truth table100%3/3
A and B
A= $node->isSameNode($lastChild)B= @naked_block
ABresult
0X0
100
111
183 and @naked_block )
184 {
185 5 my $p = $doc->createElement("p");
186 5 $p->setAttribute("enpara","enpara");
187 5 $p->appendChild($_) for ( @naked_block );
188 5 ▶ $parent->appendChild($p) if $p->textContent =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
if $p->textContent =~ /\S/ 4 1 5
189 }
190 }
191  
192 7 my $newline = $doc->createTextNode("\n");
193 7 my $br = $doc->createElement("br");
194  
195 7 for my $p ( $parent->findnodes('//p[@enpara="enpara"]') )
196 {
197 18 $p->removeAttribute("enpara");
198 18 $parent->insertBefore( $newline->cloneNode, $p );
199 18 $parent->insertAfter( $newline->cloneNode, $p );
200  
201 18 my $frag = $doc->createDocumentFragment();
202  
203 18 my @kids = $p->childNodes();
204 18 ▶ for ( my $i = 0; $i < @kids; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @kids) 23 18 41
205 {
206 23 my $kid = $kids[$i];
207 23 ▶ next unless $kid->nodeName eq "#text";
Branch: 1 branch
BranchTrueFalseTotal
unless $kid->nodeName eq "#text" 5 18 23
208 18 my $text = $kid->nodeValue;
209 18 ▶ $text =~ s/\A\r?\n// if $i == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $i == 0 16 2 18
210 18 ▶ $text =~ s/\r?\n\z// if $i == $#kids;
Branch: 1 branch
BranchTrueFalseTotal
if $i == $#kids 15 3 18
211  
212 18 my @lines = map { $doc->createTextNode($_) }
213 split /(\r?\n)/, $text;
214  
215 18 ▶ for ( my $i = 0; $i < @lines; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @lines) 24 18 42
216 {
217 24 $frag->appendChild($lines[$i]);
218 24 ▶ unless ( $i == $#lines
Branch: 1 branch
BranchTrueFalseTotal
unless ($i == $#lines or $lines[$i]->nodeValue =~ /\A\r?\n\z/) 3 21 24
Condition100%3/3
$i == $#lines or $lines[$i]->nodeValue =~ /\A\r?\n\z/
l!l&&r!l&&!r
1833
MC/DC100%2/2
$i == $#lines or $lines[$i]->nodeValue =~ /\A\r?\n\z/
$i == $#lines $lines[$i]->nodeValue =~ /\A\r?\n\z/
Truth table100%3/3
A or B
A= $i == $#linesB= $lines[$i]->nodeValue =~ /\A\r?\n\z/
ABresult
1X1
011
000
219 or
220 $lines[$i]->nodeValue =~ /\A\r?\n\z/ )
221 {
222 3 $frag->appendChild($br->cloneNode);
223 }
224 }
225 18 $kid->replaceNode($frag);
226 }
227 }
228 }
229  
230 1 ▶sub traverse { # traverse("/*") -> callback
Subroutine traverse: called CC=1 SCAR=0.0
Pod documented
231 1 my ( $self, $selector, $callback ) = @_;
232 1 croak "not implemented";
233 }
234  
235 1 ▶sub translate_tags {
Subroutine translate_tags: called CC=1 SCAR=0.0
Pod documented
236 1 croak "not implemented";
237 }
238  
239 1 ▶sub remove_style { # (* or [list])
Subroutine remove_style: called CC=1 SCAR=0.0
Pod documented
240 # just calls remove with args
241 1 croak "not implemented";
242 }
243  
244 1 ▶sub inline_stylesheets { # (names/paths) / external sheets allowed.
Subroutine inline_stylesheets: called CC=13 SCAR=51.5
Pod documented
245 1 croak "not implemented";
246 0 my $self = shift;
247 0 my $thing = shift;
248 # :before and :after stuff is still missing
249 # ?? <style type="text/css" title="currentStyle" media="screen">
250 # ?? needs to read "@import" and link rel="stylesheet" src=".."
251  
252 0 ▶ my $doc = $self->xml_parser->parse_html_string( $thing ) unless ref($thing);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $thing 0 0 0
253 0 ▶ $doc ||= $self->xml_parser->parse_html_file( $thing ) if -e $thing;
Branch: 1 branch
BranchTrueFalseTotal
if -e $thing 0 0 0
Condition0%0/3
$doc ||= $self->xml_parser->parse_html_file($thing)
l!l&&r!l&&!r
000
MC/DC0%0/2
$doc ||= $self->xml_parser->parse_html_file($thing)
$doc $self->xml_parser->parse_html_file($thing)
Truth table0%0/3
A ||= B
A= $docB= $self->xml_parser->parse_html_file($thing)
ABresult
1X1
011
000
254 0 ▶ $doc ||= $self->xml_parser->parse_html_string( join("",$thing->getlines) )
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($thing) and $thing->can("getlines") 0 0 0
Condition0%0/6
builtin::blessed($thing) and $thing->can("getlines")
!ll&&!rl&&r
000
$doc ||= $self->xml_parser->parse_html_string(join("", $thing->getlines))
l!l&&r!l&&!r
000
MC/DC0%0/2
builtin::blessed($thing) and $thing->can("getlines")
builtin::blessed($thing) $thing->can("getlines")
MC/DC0%0/2
$doc ||= $self->xml_parser->parse_html_string(join("", $thing->getlines))
$doc $self->xml_parser->parse_html_string(join("", $thing->getlines))
Truth table0%0/3
A and B
A= builtin::blessed($thing)B= $thing->can("getlines")
ABresult
0X0
100
111
Truth table0%0/3
A ||= B
A= $docB= $self->xml_parser->parse_html_string(join("", $thing->getlines))
ABresult
1X1
011
000
255 if blessed($thing) && $thing->can("getlines");
256  
257 0 my $root = $doc->documentElement();
258  
259 0 my $collected = "";
260 0 for my $sheet ( $root->findnodes("//style") )
261 {
262 # print $sheet->textContent, $/;
263 0 $collected .= $sheet->textContent;
264 }
265  
266 0 my $css = CSS::Tiny->read_string($collected);
267  
268 0 my %xpath_to_style;
269 0 for my $rule ( reverse sort keys %{$css} ) {
270 0 my $selector = HTML::Selector::XPath->new($rule);
271 0 $xpath_to_style{$selector->to_xpath} = $css->{$rule};
272 # Uncomment if you want to see the CSS-->xpath strings
273 # printf("%s\n%s\n%s\n\n",
274 # $rule,
275 # $selector->to_xpath,
276 # format_css($css->{$rule})
277 # );
278 }
279  
280 0 for my $xpath ( keys %xpath_to_style ) {
281 0 my $style = $xpath_to_style{$xpath};
282 0 for my $node ( $root->findnodes( $xpath ) ) {
283 0 ▶ if ( my $inline_css = $node->getAttributeNode("style") ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $inline_css = $node->getAttributeNode("style")) 0 0 0
284 0 my $fake_sheet = $node->nodeName .
285 "{" . $inline_css->getValue . "}";
286 0 my $css = CSS::Tiny->read_string($fake_sheet);
287 0 ▶ next unless $css;
Branch: 1 branch
BranchTrueFalseTotal
unless $css 0 0 0
288 0 %{$style} = (
289 0 %{$style},
290 0 %{$css->{$node->nodeName}}
291 );
292 }
293 0 $node->setAttribute("style", format_css($style));
294 0 $node->removeAttribute("class");
295 }
296 }
297 0 return $doc->toString(1);
298 }
299  
300 0 ▶sub _format_css {
Subroutine _format_css: not called CC=3 SCAR=24.8
301 0 ▶ my $css = shift || return '';
Condition0%0/2
shift() || (return '')
l!l
00
MC/DC0%0/1
shift() || (return '')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
302 0 my @pairs;
303 0 for my $attr ( keys %{$css} )
304 {
305 0 push @pairs, "$attr:$css->{$attr}";
306 }
307 0 join "; ", @pairs;
308 }
309  
310 1 ▶sub html_to_xhtml { # Handles docs or fragments.
Subroutine html_to_xhtml: called CC=1 SCAR=0.0
Pod documented
311 1 croak "not implemented";
312 }
313  
314 8 ▶sub _fragment_to_body_node {
Subroutine _fragment_to_body_node: called CC=1 SCAR=0.0
315 8 my $self = shift;
316 8 my $html = \$_[0];
317 8 my $parser = $self->xml_parser();
318 8 $parser->recover(1);
319 8 $parser->recover_silently(1);
320 8 my ( $body ) = $parser->parse_html_string("<body>".${$html}."</body>")->findnodes("//body");
321 8 return $body;
322 }
323  
324 6 ▶sub _sanitize_fragment {
Subroutine _sanitize_fragment: called CC=9 SCAR=22.0
325 6 my $self = shift;
326 6 ▶ my $fragment = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $fragment = shift() or return 6 0 6
327 # $self->_fragment_to_xhtml($fragment);
328 6 $fragment = Encode::decode_utf8($fragment);
329 6 my $p = HTML::TokeParser::Simple->new(\$fragment);
330 6 my $renew = "";
331 6 ▶ while ( my $token = $p->get_token )
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $p->get_token) 182 6 188
332 {
333 # warn sprintf("%10s %10s %s\n", $token->[-1], $token->get_tag, blessed($token));
334 182 ▶ if ( $isKnown->{$token->get_tag} )
Branch: 1 branch
BranchTrueFalseTotal
if ($$isKnown{$token->get_tag}) { } 92 90 182
335 {
336 92 ▶ if ( $token->is_start_tag )
Branch: 1 branch
BranchTrueFalseTotal
if ($token->is_start_tag) { } 48 44 92
337 {
338 48 my @pair;
339 48 for my $attr ( @{ $token->get_attrseq } )
340 {
341 25 ▶ next if $attr eq "/";
Branch: 1 branch
BranchTrueFalseTotal
if $attr eq "/" 1 24 25
342 24 push @pair, join("=", $attr, '"' . encode_entities(decode_entities($token->get_attr($attr))) . '"');
343 }
344 48 $renew .= "<" . join(" ", $token->get_tag, @pair);
345 48 ▶ $renew .= ( $token->get_attr("/") || $emptyElement->{$token->get_tag} ) ? "/>" : ">";
Branch: 1 branch
BranchTrueFalseTotal
$token->get_attr('/') || $$emptyElement{$token->get_tag} ? : 1 47 48
Condition66%2/3
$token->get_attr("/") or $$emptyElement{$token->get_tag}
l!l&&r!l&&!r
1047
MC/DC50%1/2
$token->get_attr("/") or $$emptyElement{$token->get_tag}
$token->get_attr("/") $$emptyElement{$token->get_tag}
Truth table66%2/3
A or B
A= $token->get_attr("/")B= $$emptyElement{$token->get_tag}
ABresult
1X1
011
000
346 }
347 else
348 {
349 44 $renew .= $token->as_is;
350 }
351 }
352 else
353 {
354 90 $renew .= encode_entities(decode_entities($token->as_is));
355 }
356 }
357 6 return $renew;
358 }
359  
360 0 ▶sub _fragment_to_xhtml {
Subroutine _fragment_to_xhtml: not called CC=8 SCAR=42.8
361 0 my $self = shift;
362 0 ▶ return unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
363 0 my $html = \$_[0];
364 0 my $doc = $self->_fragment_to_doc($html);
365 0 my ( $body ) = $doc->findnodes("//body");
366 0 my ( $head ) = $doc->findnodes("//head");
367 0 my $out = "";
368 0 ▶ my $target = $body || $head;
Condition0%0/3
$body || $head
l!l&&r!l&&!r
000
MC/DC0%0/2
$body || $head
$body $head
Truth table0%0/3
A || B
A= $bodyB= $head
ABresult
1X1
011
000
369 0 ▶ $target or return $out;
Branch: 1 branch
BranchTrueFalseTotal
$target or return $out 0 0 0
370 0 for my $kid ( $target->childNodes ) {
371 0 $kid->removeChild($_) for
372 0 ▶ grep { $_->nodeType == 3 and $_->data !~ /\w/ } $kid->childNodes;
Condition0%0/3
$_->nodeType == 3 && !($_->data =~ /\w/)
!ll&&!rl&&r
000
MC/DC0%0/2
$_->nodeType == 3 && !($_->data =~ /\w/)
$_->nodeType == 3 !($_->data =~ /\w/)
Truth table0%0/3
A && not(B)
A= $_->nodeType == 3B= !($_->data =~ /\w/)
ABresult
0X0
100
111
373 0 $out .= $kid->serialize(1);
374 }
375 0 ▶ return $out if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 0 0 0
376 0 ${$html} = $out;
377 }
378  
379 1 ▶sub validate { # Against DTDs!
Subroutine validate: called CC=1 SCAR=0.0
Pod documented
380 1 croak "not implemented";
381 }
382  
383 8 ▶sub xml_parser {
Subroutine xml_parser: called CC=3 SCAR=11.4
Pod documented
384 8 my $self = shift;
385 8 ▶ $self->{xml_parser} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 8 8
386 8 ▶ $self->{xml_parser} ||= XML::LibXML->new();
Condition66%2/3
$self->{"xml_parser"} ||= "XML::LibXML"->new
l!l&&r!l&&!r
350
MC/DC0%0/2
$self->{"xml_parser"} ||= "XML::LibXML"->new
$self->{"xml_parser"} "XML::LibXML"->new
Truth table66%2/3
A ||= B
A= $self->{"xml_parser"}B= "XML::LibXML"->new
ABresult
1X1
011
000
387 }
388  
389 0 ▶sub selector_to_xpath {
Subroutine selector_to_xpath: not called CC=1 SCAR=6.9
Pod documented
390 0 HTML::Selector::XPath::selector_to_xpath($_[1]);
391 }
392  
393 #sub html_parser {
394 # my $self = shift;
395 # $self->{html_parser} = shift if @_;
396 # $self->{html_parser} ||= HTML::TokeParser->new();
397 #}
398  
399 15 1;
400  
401 __END__
↑ Summary