| 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
| |||||||||||||||||||||||||||||
| 23 | 1 | $handler->({ type => 'TEXT', raw => $1 }); | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | 90 | ▶ | while ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 46 | 317 | $handler->({ type => 'CLOSE', name => $tag_name, raw => $whole }); | |||||||||||||||||||||||||||
| 47 | } else { | ||||||||||||||||||||||||||||
| 48 | 355 | ▶ | $attributes = '' if !defined($attributes) or $attributes =~ /^ +$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $attributes or $attributes =~ /^ +$/
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 =~ /^ +$/
| |||||||||||||||||||||||||||||
| 49 | 355 | ▶ | $handler->({ | ||||||||||||||||||||||||||
|
Condition100%2/2
$attributes || ''
MC/DC100%1/1
$attributes || ''
$attributes
Truth table100%2/2
A
A= $attributes
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 82 | 251 | my $lckey = lc($key); | |||||||||||||||||||||||||||
| 83 | 251 | ▶ | if ($test) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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/"/"/g; | |||||||||||||||||||||||||||
| 96 | 251 | $str =~ s/</</g; | |||||||||||||||||||||||||||
| 97 | 251 | $str =~ s/>/>/g; | |||||||||||||||||||||||||||
| 98 | 251 | $str =~ s/&/&/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/&/&/g; | |||||||||||||||||||||||||||
| 105 | 130 | $str =~ s/"/"/g; | |||||||||||||||||||||||||||
| 106 | 130 | $str =~ s/</</g; | |||||||||||||||||||||||||||
| 107 | 130 | $str =~ s/>/>/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; | |||||||||||||||||||||||||||