Zoom/Parser/BuiltIn.pm

filter: Statementstmt 96.5% 56 / 58 Branchbran 90.9% 20 / 22 Conditioncond 100% 5 / 5 MC/DCmcdc 100% 3 / 3 Subroutinesub 90.9% 10 / 11 Podpod 0.0% 0 / 4 totaltotal 91.2% 94 / 103 SCAR 26.4
CC
14
Cov
95%
_hacky_tag_parser
10.0
_hacky_attribute_parser
5.1
html_unescape
2.0
CRAP 14.0
« Zoom/FilterStream.pm ↑ Summary Zoom.pm »
1 package HTML::Zoom::Parser::BuiltIn;
2  
3 14 ▶use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use base qw(HTML::Zoom::SubObject);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 sub html_to_events {
7 90 ▶ my ($self, $text) = @_;
Subroutine html_to_events: called CC=1 SCAR=0.0
Pod undocumented
8 90 my @events;
9 90 ▶ _hacky_tag_parser($text => sub { push @events, $_[0] });
Subroutine __ANON__: called CC=1 SCAR=0.0
10 90 return \@events;
11 }
12  
13 sub html_to_stream {
14 29 ▶ my ($self, $text) = @_;
Subroutine html_to_stream: called CC=1 SCAR=0.0
Pod undocumented
15 return $self->_zconfig->stream_utils
16 29 ->stream_from_array(@{$self->html_to_events($text)});
17 }
18  
19 sub _hacky_tag_parser {
20 90 ▶ my ($text, $handler) = @_;
Subroutine _hacky_tag_parser: called CC=10 SCAR=23.0
21 90 $text =~ m{^([^<]*)}g;
22 90 ▶ if ( length $1 ) { # leading PCDATA
Branch: 1 branch
BranchTrueFalseTotal
if (length $1) 1 89 90
23 1 $handler->({ type => 'TEXT', raw => $1 });
24 }
25 90 ▶ while (
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ m[ ( (?:[^<]*) < (?: ( / )? ( [^/!<>\s"'=]+ ) ( (?:"[^"]*"|'[^']*'|[^/"'<>])+? )? | (!-- .*? -- | ![^\-] .*? ) ) (\s*/\s*)? > ) ([^<]*) ]gsx) 673 90 763
26 $text =~ m{
27 (
28 (?:[^<]*) < (?:
29 ( / )? ( [^/!<>\s"'=]+ )
30 ( (?:"[^"]*"|'[^']*'|[^/"'<>])+? )?
31 |
32 (!-- .*? -- | ![^\-] .*? )
33 ) (\s*/\s*)? >
34 )
35 ([^<]*)
36 }sxg
37 ) {
38 673 my ($whole, $is_close, $tag_name, $attributes, $is_special,
39 $in_place_close, $content)
40 = ($1, $2, $3, $4, $5, $6, $7, $8);
41 673 ▶ if ($is_special) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_special) { } 1 672 673
42 1 $handler->({ type => 'SPECIAL', raw => $whole });
43 } else {
44 672 $tag_name =~ tr/A-Z/a-z/;
45 672 ▶ if ($is_close) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_close) { } 317 355 672
46 317 $handler->({ type => 'CLOSE', name => $tag_name, raw => $whole });
47 } else {
48 355 ▶ $attributes = '' if !defined($attributes) or $attributes =~ /^ +$/;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $attributes or $attributes =~ /^ +$/ 137 218 355
Condition100%3/3
not defined $attributes or $attributes =~ /^ +$/
l!l&&r!l&&!r
10235218
MC/DC100%2/2
not defined $attributes or $attributes =~ /^ +$/
not defined $attributes $attributes =~ /^ +$/
Truth table100%3/3
not(A) or B
A= not defined $attributesB= $attributes =~ /^ +$/
ABresult
1X1
011
000
49 355 ▶ $handler->({
Condition100%2/2
$attributes || ''
l!l
218137
MC/DC100%1/1
$attributes || ''
$attributes
Truth table100%2/2
A
A= $attributes
Aresult
11
00
50 type => 'OPEN',
51 name => $tag_name,
52 is_in_place_close => $in_place_close,
53 _hacky_attribute_parser($attributes),
54 raw_attrs => $attributes||'',
55 raw => $whole,
56 });
57 355 ▶ if ($in_place_close) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_place_close) 38 317 355
58 38 $handler->({
59 type => 'CLOSE', name => $tag_name, raw => '',
60 is_in_place_close => 1
61 });
62 }
63 }
64 }
65 673 ▶ if (length $content) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $content) 497 176 673
66 497 $handler->({ type => 'TEXT', raw => $content });
67 }
68 }
69 }
70  
71 sub _hacky_attribute_parser {
72 355 ▶ my ($attr_text) = @_;
Subroutine _hacky_attribute_parser: called CC=5 SCAR=16.3
73 355 my (%attrs, @attr_names);
74 355 ▶ while (
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_text =~ / ([^\s\=\"\']+)(\s*=\s*(?:(")(.*?)"|(')(.*?)'|([^'"\s=]+)['"]*))? /gsx) 251 355 606
75 $attr_text =~ m{
76 ([^\s\=\"\']+)(\s*=\s*(?:(")(.*?)"|(')(.*?)'|([^'"\s=]+)['"]*))?
77 }sgx
78 ) {
79 251 my $key = $1;
80 251 my $test = $2;
81 251 ▶ my $val = ( $3 ? $4 : ( $5 ? $6 : $7 ));
Branch: 2 branches
BranchTrueFalseTotal
$3 ? : 248 3 251
$5 ? : 3 0 3
82 251 my $lckey = lc($key);
83 251 ▶ if ($test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($test) { } 251 0 251
84 251 $attrs{$lckey} = _simple_unescape($val);
85 } else {
86 0 $attrs{$lckey} = $lckey;
87 }
88 251 push(@attr_names, $lckey);
89 }
90 355 (attrs => \%attrs, attr_names => \@attr_names);
91 }
92  
93 sub _simple_unescape {
94 251 ▶ my $str = shift;
Subroutine _simple_unescape: called CC=1 SCAR=0.0
95 251 $str =~ s/&quot;/"/g;
96 251 $str =~ s/&lt;/</g;
97 251 $str =~ s/&gt;/>/g;
98 251 $str =~ s/&amp;/&/g;
99 251 $str;
100 }
101  
102 sub _simple_escape {
103 130 ▶ my $str = shift;
Subroutine _simple_escape: called CC=1 SCAR=0.0
104 130 $str =~ s/&/&amp;/g;
105 130 $str =~ s/"/&quot;/g;
106 130 $str =~ s/</&lt;/g;
107 130 $str =~ s/>/&gt;/g;
108 130 $str;
109 }
110  
111 130 ▶sub html_escape { _simple_escape($_[1]) }
Subroutine html_escape: called CC=1 SCAR=0.0
Pod undocumented
112  
113 0 ▶sub html_unescape { _simple_unescape($_[1]) }
Subroutine html_unescape: not called CC=1 SCAR=6.9
Pod undocumented
114  
115 14 1;
« Zoom/FilterStream.pm ↑ Summary Zoom.pm »