| 1 | # -*- mode: perl; coding: utf-8 -*- | ||||||||||||||||||||||||||||
| 2 | package YATT::LRXML::Parser; | ||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings qw(FATAL all NONFATAL misc); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use base qw(YATT::Class::Configurable); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | use YATT::Fields | ||||||||||||||||||||||||||||
| 7 | 7 | ▶ | (qw(^tokens | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | cf_tree | ||||||||||||||||||||||||||||
| 9 | metainfo | ||||||||||||||||||||||||||||
| 10 | nsdict | ||||||||||||||||||||||||||||
| 11 | nslist | ||||||||||||||||||||||||||||
| 12 | re_splitter | ||||||||||||||||||||||||||||
| 13 | re_ns | ||||||||||||||||||||||||||||
| 14 | re_attlist | ||||||||||||||||||||||||||||
| 15 | re_entity | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | re_arg_decls | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | elem_kids | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | cf_special_entities | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | cf_untaint | ||||||||||||||||||||||||||||
| 24 | cf_debug | ||||||||||||||||||||||||||||
| 25 | cf_registry | ||||||||||||||||||||||||||||
| 26 | ) | ||||||||||||||||||||||||||||
| 27 | , [cf_html_tags => {input => 1, option => 0 | ||||||||||||||||||||||||||||
| 28 | , form => 0, textarea => 0, select => 0}] | ||||||||||||||||||||||||||||
| 29 | , [cf_tokens => qw(comment declarator pi tag entity)] | ||||||||||||||||||||||||||||
| 30 | 7 | ); | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 7 | ▶ | use YATT::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 7 | ▶ | use YATT::Util::Taint; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 7 | ▶ | use YATT::Util::Symbol qw(fields_hash); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 7 | ▶ | use YATT::LRXML::Node; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 7 | ▶ | use YATT::LRXML (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 7 | ▶ | use YATT::LRXML::MetaInfo (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | sub MetaInfo () { 'YATT::LRXML::MetaInfo' } | ||||||||||||||||||||||||||||
| 41 | sub Scanner () { 'YATT::LRXML::Scanner' } | ||||||||||||||||||||||||||||
| 42 | sub Builder () { 'YATT::LRXML::Builder' } | ||||||||||||||||||||||||||||
| 43 | sub Cursor () { 'YATT::LRXML::NodeCursor' } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 489 | ▶ | sub after_configure { | ||||||||||||||||||||||||||
|
Subroutine
after_configure: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | 489 | my MY $self = shift; | |||||||||||||||||||||||||||
| 47 | 489 | $self->SUPER::after_configure; | |||||||||||||||||||||||||||
| 48 | 489 | $$self{re_ns} = $self->re_ns(0); | |||||||||||||||||||||||||||
| 49 | 489 | $$self{re_splitter} = $self->re_splitter(1, $$self{re_ns}); | |||||||||||||||||||||||||||
| 50 | 489 | $$self{re_attlist} = $self->re_attlist(2); | |||||||||||||||||||||||||||
| 51 | 489 | $$self{re_arg_decls} = $self->re_arg_decls(1); | |||||||||||||||||||||||||||
| 52 | { | ||||||||||||||||||||||||||||
| 53 | 489 | my %re_cached = map {$_ => 1} grep {/^re_/} keys %{fields_hash($self)}; | |||||||||||||||||||||||||||
| 54 | 489 | my @token_pat = $self->re_tokens(2); | |||||||||||||||||||||||||||
| 55 | 489 | ▶ | while (@token_pat) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 2445 | my ($name, $pattern) = splice @token_pat, 0, 2; | |||||||||||||||||||||||||||
| 57 | 2445 | push @{$self->{elem_kids}}, [$name, qr{^$pattern}]; | |||||||||||||||||||||||||||
| 58 | 2445 | ▶ | next unless $re_cached{"re_$name"}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 489 | $self->{"re_$name"} = $pattern; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 4 | ▶ | sub configure_namespace { | ||||||||||||||||||||||||||
|
Subroutine
configure_namespace: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 65 | 4 | shift->metainfo->configure(namespace => shift); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 489 | ▶ | sub configure_metainfo { | ||||||||||||||||||||||||||
|
Subroutine
configure_metainfo: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 69 | 489 | (my MY $self) = shift; | |||||||||||||||||||||||||||
| 70 | 489 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 71 | 0 | $self->{metainfo} = shift; | |||||||||||||||||||||||||||
| 72 | } elsif (not $self->{metainfo}) { | ||||||||||||||||||||||||||||
| 73 | # @_ == 0 || > 1 | ||||||||||||||||||||||||||||
| 74 | 165 | $self->{metainfo} = MetaInfo->new(@_); | |||||||||||||||||||||||||||
| 75 | } else { | ||||||||||||||||||||||||||||
| 76 | 324 | $self->{metainfo}->configure(@_); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | $self->{metainfo} | ||||||||||||||||||||||||||||
| 79 | 489 | } | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 739 | ▶ | sub metainfo { | ||||||||||||||||||||||||||
|
Subroutine
metainfo: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 82 | 739 | (my MY $self) = shift; | |||||||||||||||||||||||||||
| 83 | 739 | ▶ | $self->{metainfo} ||= $self->configure_metainfo; | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"metainfo"} ||= $self->configure_metainfo
MC/DC0%0/2
$self->{"metainfo"} ||= $self->configure_metainfo
$self->{"metainfo"}
$self->configure_metainfo
Truth table66%2/3
A ||= B
A= $self->{"metainfo"}B= $self->configure_metainfo
| |||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 156 | ▶ | sub parse_handle { | ||||||||||||||||||||||||||
|
Subroutine
parse_handle: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 87 | 156 | (my MY $self, my ($fh)) = splice @_, 0, 2; | |||||||||||||||||||||||||||
| 88 | 156 | $self->configure_metainfo(@_); | |||||||||||||||||||||||||||
| 89 | 156 | $self->after_configure; | |||||||||||||||||||||||||||
| 90 | 156 | ▶ | if (my $layer = $self->{metainfo}->cget('iolayer')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | binmode $fh, $layer; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | 156 | my $scan = $self->tokenize(do { | |||||||||||||||||||||||||||
| 94 | 156 | local $/; | |||||||||||||||||||||||||||
| 95 | 156 | my $data = <$fh>; | |||||||||||||||||||||||||||
| 96 | 156 | ▶ | $self->{cf_untaint} ? untaint_any($data) : $data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | }); | ||||||||||||||||||||||||||||
| 98 | 156 | $self->organize($scan); | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 12 | ▶ | sub parse_string { | ||||||||||||||||||||||||||
|
Subroutine
parse_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 102 | 12 | my MY $self = shift; | |||||||||||||||||||||||||||
| 103 | 12 | $self->configure_metainfo(splice @_, 1); | |||||||||||||||||||||||||||
| 104 | 12 | $self->after_configure; | |||||||||||||||||||||||||||
| 105 | 12 | my $scan = $self->tokenize($_[0]); | |||||||||||||||||||||||||||
| 106 | 12 | $self->organize($scan); | |||||||||||||||||||||||||||
| 107 | # $self->{cf_document}->set_tokens($self->{tokens}); | ||||||||||||||||||||||||||||
| 108 | # $self->{cf_document}->set_tree($tree); | ||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | #======================================== | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 170 | ▶ | sub scanner { | ||||||||||||||||||||||||||
|
Subroutine
scanner: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 114 | 170 | (my MY $self) = @_; | |||||||||||||||||||||||||||
| 115 | $self->Scanner->new(array => $self->{tokens}, index => 0 | ||||||||||||||||||||||||||||
| 116 | , linenum => 1 | ||||||||||||||||||||||||||||
| 117 | 170 | , metainfo => $self->{metainfo}); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 166 | ▶ | sub tree { | ||||||||||||||||||||||||||
|
Subroutine
tree: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 121 | 166 | my MY $self = shift; | |||||||||||||||||||||||||||
| 122 | my $cursor = $self->call_type(Cursor => new => $self->{cf_tree} | ||||||||||||||||||||||||||||
| 123 | 166 | , metainfo => $self->{metainfo}); | |||||||||||||||||||||||||||
| 124 | #$cursor->configure(path => $self->Cursor->Path->new($self->{cf_tree})); | ||||||||||||||||||||||||||||
| 125 | 166 | $cursor; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 168 | ▶ | sub new_root_builder { | ||||||||||||||||||||||||||
|
Subroutine
new_root_builder: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 129 | 168 | (my MY $self, my Scanner $scan) = @_; | |||||||||||||||||||||||||||
| 130 | 168 | ▶ | if (my $reg = $self->{cf_registry}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 156 | $reg->new_root_builder($self, $scan); | |||||||||||||||||||||||||||
| 132 | } else { | ||||||||||||||||||||||||||||
| 133 | require_and($self->Builder | ||||||||||||||||||||||||||||
| 134 | , new => $self->{cf_tree} = $self->create_node('root') | ||||||||||||||||||||||||||||
| 135 | , undef | ||||||||||||||||||||||||||||
| 136 | , startpos => 0 | ||||||||||||||||||||||||||||
| 137 | , startline => $scan->{cf_linenum} | ||||||||||||||||||||||||||||
| 138 | 12 | , linenum => $scan->{cf_linenum}); | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 168 | ▶ | sub organize { | ||||||||||||||||||||||||||
|
Subroutine
organize: called CC=9 SCAR=22.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 143 | 168 | (my MY $self, my Scanner $scan) = @_; | |||||||||||||||||||||||||||
| 144 | 168 | my $builder = $self->new_root_builder($scan); | |||||||||||||||||||||||||||
| 145 | 168 | ▶ | while ($scan->readable) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 789 | my $text = $scan->read; | |||||||||||||||||||||||||||
| 147 | 789 | ▶ | $builder->add($scan, $text) if $text ne ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 789 | ▶ | last unless $scan->readable; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 635 | my ($toktype, @match) = $scan->expect($self->{elem_kids}); | |||||||||||||||||||||||||||
| 150 | 635 | ▶ | unless (defined $toktype) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | 0 | $self->build_scanned($builder, $scan | |||||||||||||||||||||||||||
| 152 | , unknown => undef, $scan->read); | ||||||||||||||||||||||||||||
| 153 | 0 | next; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 635 | ▶ | if (my $sub = $self->can("build_$toktype")) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | # declarator も complex 扱いにした方が良いね。 | ||||||||||||||||||||||||||||
| 158 | 633 | $builder = $sub->($self, $scan, $builder, \@match); | |||||||||||||||||||||||||||
| 159 | } else { | ||||||||||||||||||||||||||||
| 160 | # easy case. | ||||||||||||||||||||||||||||
| 161 | 2 | my ($ns, $body) = @match; | |||||||||||||||||||||||||||
| 162 | 2 | $self->build_scanned($builder, $scan | |||||||||||||||||||||||||||
| 163 | , $toktype => $ns, $body); | ||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | 163 | ▶ | if ($builder->{cf_endtag} and $builder->{parent}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$builder->{"cf_endtag"} and $builder->{"parent"}
MC/DC50%1/2
$builder->{"cf_endtag"} and $builder->{"parent"}
$builder->{"cf_endtag"}
$builder->{"parent"}
Truth table66%2/3
A and B
A= $builder->{"cf_endtag"}B= $builder->{"parent"}
| |||||||||||||||||||||||||||||
| 167 | die "Missing close tag '$builder->{cf_endtag}'" | ||||||||||||||||||||||||||||
| 168 | ." at line $builder->{cf_startline}" | ||||||||||||||||||||||||||||
| 169 | 2 | .$scan->{cf_metainfo}->in_file." \n"; | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 161 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | 0 | ($self->tree, $self->{metainfo}); | |||||||||||||||||||||||||||
| 174 | } else { | ||||||||||||||||||||||||||||
| 175 | 161 | $self->tree; | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 193 | ▶ | sub build_scanned { | ||||||||||||||||||||||||||
|
Subroutine
build_scanned: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 180 | 193 | (my MY $self, my Builder $builder, my Scanner $scan) = splice @_, 0, 3; | |||||||||||||||||||||||||||
| 181 | 193 | my $node = $self->create_node(@_); | |||||||||||||||||||||||||||
| 182 | 193 | node_set_nlines($node, $scan->{cf_last_nol}); | |||||||||||||||||||||||||||
| 183 | 193 | $builder->add($scan, $node); | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 19 | ▶ | sub build_pi { | ||||||||||||||||||||||||||
|
Subroutine
build_pi: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 187 | 19 | (my MY $self, my Scanner $scan, my Builder $builder, my ($match)) = @_; | |||||||||||||||||||||||||||
| 188 | 19 | $self->build_scanned($builder, $scan | |||||||||||||||||||||||||||
| 189 | , pi => $match->[0] | ||||||||||||||||||||||||||||
| 190 | , $self->parse_entities($match->[1])); | ||||||||||||||||||||||||||||
| 191 | 19 | $builder; | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 172 | ▶ | sub build_entity { | ||||||||||||||||||||||||||
|
Subroutine
build_entity: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 195 | 172 | (my MY $self, my Scanner $scan, my Builder $builder, my ($match)) = @_; | |||||||||||||||||||||||||||
| 196 | 172 | $self->build_scanned($builder, $scan | |||||||||||||||||||||||||||
| 197 | , entity => $self->parse_entpath($match->[0])); | ||||||||||||||||||||||||||||
| 198 | 172 | $builder; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 255 | ▶ | sub build_tag { | ||||||||||||||||||||||||||
|
Subroutine
build_tag: called CC=10 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 202 | 255 | (my MY $self, my Scanner $scan, my Builder $builder, my ($match)) = @_; | |||||||||||||||||||||||||||
| 203 | 255 | my ($close, $html, $ns, $tagname, $attlist, $is_ee) = @$match; | |||||||||||||||||||||||||||
| 204 | 255 | ▶ | $tagname ||= $html; | ||||||||||||||||||||||||||
|
Condition66%2/3
$tagname ||= $html
MC/DC0%0/2
$tagname ||= $html
$tagname
$html
Truth table66%2/3
A ||= B
A= $tagnameB= $html
| |||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 255 | ▶ | if ($close) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | 64 | $builder->verify_close($tagname, $scan); | |||||||||||||||||||||||||||
| 208 | # そうか、ここで attribute element からの脱出もせにゃならん。 | ||||||||||||||||||||||||||||
| 209 | # switched product 方式なら、parent は共通、かな? | ||||||||||||||||||||||||||||
| 210 | 63 | return $builder->parent; | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 191 | my ($is_att, $nodetype, $qflag) = do { | |||||||||||||||||||||||||||
| 214 | 191 | ▶ | if (defined $ns and $ns =~ s/^:(?=\w)//) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $ns and $ns =~ s/^:(?=\w)//
MC/DC100%2/2
defined $ns and $ns =~ s/^:(?=\w)//
defined $ns
$ns =~ s/^:(?=\w)//
Truth table100%3/3
A and B
A= defined $nsB= $ns =~ s/^:(?=\w)//
| |||||||||||||||||||||||||||||
| 215 | 21 | (1, attribute => YATT::LRXML::Node->quoted_by_element($is_ee)); | |||||||||||||||||||||||||||
| 216 | } else { | ||||||||||||||||||||||||||||
| 217 | 170 | my $type = do { | |||||||||||||||||||||||||||
| 218 | 170 | ▶ | if (defined $html) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 219 | 18 | $is_ee = $self->{cf_html_tags}{lc($html)}; | |||||||||||||||||||||||||||
| 220 | 18 | 'html'; | |||||||||||||||||||||||||||
| 221 | } else { | ||||||||||||||||||||||||||||
| 222 | 152 | 'element' | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | }; | ||||||||||||||||||||||||||||
| 225 | 170 | ▶ | (0, $type => $is_ee ? EMPTY_ELEMENT : 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | }; | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 191 | ▶ | my $element = $self->create_node([$nodetype, $qflag] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | , $html | ||||||||||||||||||||||||||||
| 231 | ? $html | ||||||||||||||||||||||||||||
| 232 | : [$ns, split /[:\.]/, $tagname]); | ||||||||||||||||||||||||||||
| 233 | 191 | $self->parse_attlist($attlist, $element); | |||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 191 | ▶ | unless ($is_ee) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 236 | # <yatt:normal>...</yatt:normal>, <:yatt:attr>...</:yatt:attr> | ||||||||||||||||||||||||||||
| 237 | 67 | $builder->add($scan, $element)->open($element, endtag => $tagname); | |||||||||||||||||||||||||||
| 238 | } elsif ($is_att) { | ||||||||||||||||||||||||||||
| 239 | # <:yatt:attr />... | ||||||||||||||||||||||||||||
| 240 | 16 | $builder->switch($element); | |||||||||||||||||||||||||||
| 241 | } else { | ||||||||||||||||||||||||||||
| 242 | # <yatt:empty_elem /> | ||||||||||||||||||||||||||||
| 243 | 108 | node_set_nlines($element, $scan->{cf_last_nol}); | |||||||||||||||||||||||||||
| 244 | 108 | $builder->add($scan, $element); | |||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | #======================================== | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 187 | ▶ | sub build_declarator { | ||||||||||||||||||||||||||
|
Subroutine
build_declarator: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 251 | 187 | (my MY $self, my Scanner $scan, my Builder $builder, my ($match)) = @_; | |||||||||||||||||||||||||||
| 252 | 187 | my ($ns, $tagname, $attlist) = @$match; | |||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 187 | my $element = $self->create_node(declarator => | |||||||||||||||||||||||||||
| 255 | [$ns, $tagname]); | ||||||||||||||||||||||||||||
| 256 | 187 | push @$element, $self->parse_arg_decls(\$attlist); | |||||||||||||||||||||||||||
| 257 | 187 | node_set_nlines($element, $scan->{cf_last_nol}); | |||||||||||||||||||||||||||
| 258 | 187 | ▶ | if (my $reg = $self->{cf_registry}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | 183 | $reg->new_decl_builder($builder, $scan, $element, $self); | |||||||||||||||||||||||||||
| 260 | } else { | ||||||||||||||||||||||||||||
| 261 | 4 | $builder->add($scan, $element); | |||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | 491 | ▶ | sub re_arg_decls { | ||||||||||||||||||||||||||
|
Subroutine
re_arg_decls: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 266 | 491 | (my MY $self, my ($capture)) = @_; | |||||||||||||||||||||||||||
| 267 | 491 | ▶ | die "re_arg_decls(capture=0) is not yet implemented!" unless $capture; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 268 | 491 | my ($SQ, $DQ) = ($self->re_sqv(2), $self->re_dqv(2)); | |||||||||||||||||||||||||||
| 269 | 491 | my $BARE = qr{([^=\-\'\"\s<>/\[\]%]+ | /(?!>))}x; | |||||||||||||||||||||||||||
| 270 | 491 | my $ENT = qr{%([\w\:\.]+(?:[\w:\.\-=\[\]\{\}\(,\)]+)?);}x; | |||||||||||||||||||||||||||
| 271 | 491 | qr{^ \s* -- (.*?) -- # 1 | |||||||||||||||||||||||||||
| 272 | |^ \s* $ENT # 2 | ||||||||||||||||||||||||||||
| 273 | |^ \s* (\]) # 3 | ||||||||||||||||||||||||||||
| 274 | |^ \s+ | ||||||||||||||||||||||||||||
| 275 | (?: (\w+)\s*=\s*)? # 4 | ||||||||||||||||||||||||||||
| 276 | (?: $SQ # 5 | ||||||||||||||||||||||||||||
| 277 | | $DQ # 6 | ||||||||||||||||||||||||||||
| 278 | | $BARE # 7 | ||||||||||||||||||||||||||||
| 279 | | (\[)(?:\s* (\w+(?:\:\w+)*)) # 8, 9 | ||||||||||||||||||||||||||||
| 280 | ) | ||||||||||||||||||||||||||||
| 281 | }xs; | ||||||||||||||||||||||||||||
| 282 | # '[ word' を一括で取り出すのは、次に ^\s+ を残しておくため. | ||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 3 | ▶ | sub re_decl_entity { | ||||||||||||||||||||||||||
|
Subroutine
re_decl_entity: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 286 | 3 | (my MY $self, my ($capture)) = @_; | |||||||||||||||||||||||||||
| 287 | 3 | qr{%([\w\:\.]+(?:[\w:\.\-=\[\]\{\}\(,\)]+)?);}x; | |||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | 207 | ▶ | sub parse_arg_decls { | ||||||||||||||||||||||||||
|
Subroutine
parse_arg_decls: called CC=9 SCAR=22.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 291 | 207 | (my MY $self, my ($strref)) = @_; | |||||||||||||||||||||||||||
| 292 | 207 | my @args; | |||||||||||||||||||||||||||
| 293 | 207 | ▶ | while ($$strref =~ s{$$self{re_arg_decls}}{}x) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 294 | print STDERR "parse_arg_decls: ", join("|", map { | ||||||||||||||||||||||||||||
| 295 | 0 | ▶ | defined $_ ? $_ : "(null)" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 296 | } $& | ||||||||||||||||||||||||||||
| 297 | , $1 # comment | ||||||||||||||||||||||||||||
| 298 | , $2 # ENT | ||||||||||||||||||||||||||||
| 299 | , $3 # ] | ||||||||||||||||||||||||||||
| 300 | , $4 # name | ||||||||||||||||||||||||||||
| 301 | , $5 # '..' | ||||||||||||||||||||||||||||
| 302 | , $6 # ".." | ||||||||||||||||||||||||||||
| 303 | , $7 # bare | ||||||||||||||||||||||||||||
| 304 | , $8 # [ | ||||||||||||||||||||||||||||
| 305 | , $9 # leader | ||||||||||||||||||||||||||||
| 306 | 429 | ▶ | ), "\n" if $self->{cf_debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 307 | 429 | ▶ | if (defined $1) { # comment | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 308 | 3 | push @args, $self->create_node(decl_comment => undef, $1); | |||||||||||||||||||||||||||
| 309 | } elsif (defined $2) { # ENT | ||||||||||||||||||||||||||||
| 310 | 52 | push @args | |||||||||||||||||||||||||||
| 311 | , $self->create_node([entity => 1] => $self->parse_entpath($2)); | ||||||||||||||||||||||||||||
| 312 | } elsif (defined $3) { # ] | ||||||||||||||||||||||||||||
| 313 | 20 | last; | |||||||||||||||||||||||||||
| 314 | } else { | ||||||||||||||||||||||||||||
| 315 | # $4 # name | ||||||||||||||||||||||||||||
| 316 | # $5 # '..' | ||||||||||||||||||||||||||||
| 317 | # $6 # ".." | ||||||||||||||||||||||||||||
| 318 | # $7 # bare | ||||||||||||||||||||||||||||
| 319 | # $8 # ] | ||||||||||||||||||||||||||||
| 320 | 354 | ▶ | if (defined $8) { # [ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 321 | # XXX: hard coded. | ||||||||||||||||||||||||||||
| 322 | 20 | push @args, my $nest = $self->create_node([attribute => 3], $4, $9); | |||||||||||||||||||||||||||
| 323 | 20 | push @$nest, $self->parse_arg_decls($strref); | |||||||||||||||||||||||||||
| 324 | } else { | ||||||||||||||||||||||||||||
| 325 | # XXX: dummy. | ||||||||||||||||||||||||||||
| 326 | 334 | push @args, $self->create_attlist('', $4, '=', $5, $6, $7); | |||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | 207 | ▶ | print STDERR "REST<$$strref>\n" if $self->{cf_debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | 207 | @args; | |||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | #======================================== | ||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | 191 | ▶ | sub parse_attlist { | ||||||||||||||||||||||||||
|
Subroutine
parse_attlist: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 337 | 191 | my MY $self = shift; | |||||||||||||||||||||||||||
| 338 | 191 | my $result = $_[1]; # Yes. this *is* intentional. | |||||||||||||||||||||||||||
| 339 | # XXX: タグ内改行がここでカウントされなくなる。 | ||||||||||||||||||||||||||||
| 340 | 191 | ▶ | if (defined $_[0] and my @match = $_[0] =~ m{$$self{re_attlist}}g) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $_[0] and my(@match) = $_[0] =~ /$self->{"re_attlist"}/g
MC/DC50%1/2
defined $_[0] and my(@match) = $_[0] =~ /$self->{"re_attlist"}/g
defined $_[0]
my(@match) = $_[0] =~ /$self->{"re_attlist"}/g
Truth table66%2/3
A and B
A= defined $_[0]B= my(@match) = $_[0] =~ /$self->{"re_attlist"}/g
| |||||||||||||||||||||||||||||
| 341 | 112 | push @$result, $self->create_attlist(@match); | |||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||
| 343 | 191 | $result; | |||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | 264 | ▶ | sub parse_entities { | ||||||||||||||||||||||||||
|
Subroutine
parse_entities: called CC=10 SCAR=23.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 347 | 264 | my MY $self = shift; | |||||||||||||||||||||||||||
| 348 | # XXX: 行番号情報を受け取れた方が、嬉しいのだが… | ||||||||||||||||||||||||||||
| 349 | 264 | ▶ | return undef unless defined $_[0]; # make sure single scalar is returned. | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 350 | 264 | ▶ | return '' if $_[0] eq ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 351 | 264 | ▶ | return $_[0] unless defined $$self{re_entity}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 352 | 264 | my @tokens = split $$self{re_entity}, $_[0]; | |||||||||||||||||||||||||||
| 353 | 264 | ▶ | return $tokens[0] if @tokens == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 354 | 58 | my @result; | |||||||||||||||||||||||||||
| 355 | 58 | ▶ | for (my $i = 0; $i < @tokens; $i += 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 356 | 91 | ▶ | push @result, $tokens[$i] if $tokens[$i] ne ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 357 | 91 | ▶ | push @result | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 358 | , $self->create_node(entity => $self->parse_entpath($tokens[$i+1])) | ||||||||||||||||||||||||||||
| 359 | if $i+1 < @tokens; | ||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||
| 361 | 58 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 362 | 52 | @result; | |||||||||||||||||||||||||||
| 363 | } elsif (@result > 1) { | ||||||||||||||||||||||||||||
| 364 | 5 | [TEXT_TYPE, undef, @result]; | |||||||||||||||||||||||||||
| 365 | } else { | ||||||||||||||||||||||||||||
| 366 | 1 | $result[0]; | |||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | 291 | ▶ | sub parse_entpath { | ||||||||||||||||||||||||||
|
Subroutine
parse_entpath: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 371 | 291 | (my MY $self, my ($entpath)) = @_; | |||||||||||||||||||||||||||
| 372 | 291 | my @name; | |||||||||||||||||||||||||||
| 373 | 291 | ▶ | push @name, $1 while $entpath =~ s{^[\.\:]?(\w+)(?=[\.\:]|$)}{}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 374 | # :func(), array[], hash{} is stored in node_body. | ||||||||||||||||||||||||||||
| 375 | # In &SA(); case, node_name is undef. | ||||||||||||||||||||||||||||
| 376 | 291 | ▶ | (@name ? \@name : undef | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 377 | , $entpath eq "" ? () : $entpath); | ||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | #======================================== | ||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | 168 | ▶ | sub tokenize { | ||||||||||||||||||||||||||
|
Subroutine
tokenize: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 383 | 168 | my MY $self = shift; | |||||||||||||||||||||||||||
| 384 | 168 | $self->{tokens} = [split $$self{re_splitter}, $_[0]]; | |||||||||||||||||||||||||||
| 385 | 168 | ▶ | if (my MetaInfo $meta = $self->{metainfo}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 386 | # $meta->{tokens} = $self->{tokens}; | ||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||
| 388 | 168 | $self->scanner; | |||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | 1981 | ▶ | sub token_patterns { | ||||||||||||||||||||||||||
|
Subroutine
token_patterns: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 392 | 1981 | my ($self, $token_types, $capture, $ns) = @_; | |||||||||||||||||||||||||||
| 393 | 1981 | my $wantarray = wantarray; | |||||||||||||||||||||||||||
| 394 | 1981 | my @result; | |||||||||||||||||||||||||||
| 395 | 1981 | foreach my $type (@$token_types) { | |||||||||||||||||||||||||||
| 396 | 6920 | my $meth = "re_$type"; | |||||||||||||||||||||||||||
| 397 | 6920 | ▶ | push @result | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 398 | , $wantarray ? $type : () | ||||||||||||||||||||||||||||
| 399 | , $self->$meth($capture, $ns); | ||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||
| 401 | 1981 | ▶ | return @result if $wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 402 | 1492 | my $pattern = join "\n | ", @result; | |||||||||||||||||||||||||||
| 403 | 1492 | qr{$pattern}x; | |||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | #---------------------------------------- | ||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | 494 | ▶ | sub re_splitter { | ||||||||||||||||||||||||||
|
Subroutine
re_splitter: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 409 | 494 | (my MY $self, my ($capture, $ns)) = @_; | |||||||||||||||||||||||||||
| 410 | 494 | my $body = $self->re_tokens(0, $ns); | |||||||||||||||||||||||||||
| 411 | 494 | ▶ | $capture ? qr{($body)} : $body; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | 986 | ▶ | sub re_tokens { | ||||||||||||||||||||||||||
|
Subroutine
re_tokens: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 415 | 986 | (my MY $self, my ($capture, $ns)) = @_; | |||||||||||||||||||||||||||
| 416 | 986 | $self->token_patterns($self->{cf_tokens}, $capture, $ns); | |||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | # | ||||||||||||||||||||||||||||
| 420 | # re_tag(2) returns [ /, specialtag, ns, tag, attlist, / ] | ||||||||||||||||||||||||||||
| 421 | # | ||||||||||||||||||||||||||||
| 422 | 995 | ▶ | sub re_tag { | ||||||||||||||||||||||||||
|
Subroutine
re_tag: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 423 | 995 | (my MY $self, my ($capture, $ns)) = @_; | |||||||||||||||||||||||||||
| 424 | 995 | my $namepat = $self->token_patterns([qw(tagname_html tagname_qualified)] | |||||||||||||||||||||||||||
| 425 | , $capture, $ns); | ||||||||||||||||||||||||||||
| 426 | 995 | my $attlist = $self->re_attlist; | |||||||||||||||||||||||||||
| 427 | 995 | ▶ | if (defined $capture and $capture > 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $capture and $capture > 1
MC/DC100%2/2
defined $capture and $capture > 1
defined $capture
$capture > 1
Truth table100%3/3
A and B
A= defined $captureB= $capture > 1
| |||||||||||||||||||||||||||||
| 428 | 493 | qr{<(/)? (?: $namepat) ($attlist*) \s*(/)?>}xs; | |||||||||||||||||||||||||||
| 429 | } else { | ||||||||||||||||||||||||||||
| 430 | 502 | my $re = qr{</? $namepat $attlist* \s*/?>}xs; | |||||||||||||||||||||||||||
| 431 | 502 | ▶ | $capture ? qr{($re)} : $re; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | #---------------------------------------- | ||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | 3 | ▶ | sub re_name { | ||||||||||||||||||||||||||
|
Subroutine
re_name: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 438 | 3 | my ($self, $capture) = @_; | |||||||||||||||||||||||||||
| 439 | 3 | my $body = q{[\w\-\.]+}; | |||||||||||||||||||||||||||
| 440 | 3 | ▶ | $capture ? qr{($body)} : qr{$body}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | 579 | ▶ | sub re_ns { | ||||||||||||||||||||||||||
|
Subroutine
re_ns: called CC=7 SCAR=21.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 444 | 579 | my ($self, $capture, $nslist, $additional) = @_; | |||||||||||||||||||||||||||
| 445 | 579 | ▶ | die "re_ns capture is not yet implemented" if $capture; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 446 | 579 | ▶ | $nslist ||= $self->{nslist} = do { | ||||||||||||||||||||||||||
|
Condition33%1/3
$nslist ||= ($self->{"nslist"} = do {
my $meta = $self->metainfo;
$self->{"nsdict"} = $meta->nsdict;
$meta->cget("namespace")
})
MC/DC0%0/2
$nslist ||= ($self->{"nslist"} = do {
my $meta = $self->metainfo;
$self->{"nsdict"} = $meta->nsdict;
$meta->cget("namespace")
})
$nslist
($self->{"nslist"} = do {
my $meta = $self->metainfo;
$self->{"nsdict"} = $meta->nsdict;
$meta->cget("namespace")
})
Truth table33%1/3
A ||= B
A= $nslistB= ($self->{"nslist"} = do {
my $meta = $self->metainfo;
$self->{"nsdict"} = $meta->nsdict;
$meta->cget("namespace")
})
| |||||||||||||||||||||||||||||
| 447 | 579 | my $meta = $self->metainfo; | |||||||||||||||||||||||||||
| 448 | 579 | $self->{nsdict} = $meta->nsdict; | |||||||||||||||||||||||||||
| 449 | 579 | $meta->cget('namespace'); | |||||||||||||||||||||||||||
| 450 | }; | ||||||||||||||||||||||||||||
| 451 | 579 | ▶ | unless (@$nslist) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 452 | 0 | ''; | |||||||||||||||||||||||||||
| 453 | } else { | ||||||||||||||||||||||||||||
| 454 | 579 | ▶ | my $pattern = join "|", map {ref $_ ? @$_ : $_} @$nslist | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 455 | , !$additional ? () : ref $additional ? @$additional : $additional; | ||||||||||||||||||||||||||||
| 456 | 579 | qq{(?:$pattern)}; | |||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||
| 460 | 3505 | ▶ | sub re_nsname { | ||||||||||||||||||||||||||
|
Subroutine
re_nsname: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 461 | 3505 | my ($self, $capture) = @_; | |||||||||||||||||||||||||||
| 462 | 3505 | my $body = q{[\w\-\.:]+}; | |||||||||||||||||||||||||||
| 463 | 3505 | ▶ | $capture ? qr{($body)} : qr{$body}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | 1989 | ▶ | sub re_tagname_qualified { | ||||||||||||||||||||||||||
|
Subroutine
re_tagname_qualified: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 467 | 1989 | my ($self, $capture, $ns) = @_; | |||||||||||||||||||||||||||
| 468 | 1989 | ▶ | $ns = $$self{re_ns} unless defined $ns; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 469 | 1989 | my $name = $self->re_nsname; | |||||||||||||||||||||||||||
| 470 | 1989 | ▶ | if (defined $capture and $capture > 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $capture and $capture > 1
MC/DC100%2/2
defined $capture and $capture > 1
defined $capture
$capture > 1
Truth table100%3/3
A and B
A= defined $captureB= $capture > 1
| |||||||||||||||||||||||||||||
| 471 | 985 | qr{ ( :?$ns) : ($name) }xs; | |||||||||||||||||||||||||||
| 472 | } else { | ||||||||||||||||||||||||||||
| 473 | 1004 | my $re = qq{ :?$ns : $name }; | |||||||||||||||||||||||||||
| 474 | 1004 | ▶ | $capture ? qr{($re)}xs : qr{$re}xs; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | 998 | ▶ | sub re_tagname_html { | ||||||||||||||||||||||||||
|
Subroutine
re_tagname_html: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 479 | 998 | (my MY $self, my ($capture, $ns)) = @_; | |||||||||||||||||||||||||||
| 480 | 998 | my $body = join "|", keys %{$self->{cf_html_tags}}; | |||||||||||||||||||||||||||
| 481 | 998 | ▶ | $capture ? qr{($body)}i : qr{$body}i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||
| 484 | #---------------------------------------- | ||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||
| 486 | 1491 | ▶ | sub re_attlist { | ||||||||||||||||||||||||||
|
Subroutine
re_attlist: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 487 | 1491 | my ($self, $capture) = @_; | |||||||||||||||||||||||||||
| 488 | 1491 | my $name = $self->re_nsname; | |||||||||||||||||||||||||||
| 489 | 1491 | my $value = $self->re_attvalue($capture); | |||||||||||||||||||||||||||
| 490 | 1491 | my $sp = q{\s+}; | |||||||||||||||||||||||||||
| 491 | 1491 | my $eq = q{\s* = \s*}; | |||||||||||||||||||||||||||
| 492 | 1491 | ▶ | if (defined $capture and $capture > 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $capture and $capture > 1
MC/DC100%2/2
defined $capture and $capture > 1
defined $capture
$capture > 1
Truth table100%3/3
A and B
A= defined $captureB= $capture > 1
| |||||||||||||||||||||||||||||
| 493 | 494 | qr{($sp|\b) (?:($name) ($eq))? $value}xs; | |||||||||||||||||||||||||||
| 494 | } else { | ||||||||||||||||||||||||||||
| 495 | 997 | my $re = qr{(?:$sp|\b) (?:$name $eq)? $value}xs; | |||||||||||||||||||||||||||
| 496 | 997 | ▶ | $capture ? qr{($re)} : $re; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||
| 500 | 1494 | ▶ | sub re_attvalue { | ||||||||||||||||||||||||||
|
Subroutine
re_attvalue: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 501 | 1494 | my ($self, $capture) = @_; | |||||||||||||||||||||||||||
| 502 | 1494 | my ($SQ, $DQ, $NQ) = | |||||||||||||||||||||||||||
| 503 | ($self->re_sqv($capture), | ||||||||||||||||||||||||||||
| 504 | $self->re_dqv($capture), | ||||||||||||||||||||||||||||
| 505 | $self->re_bare($capture)); | ||||||||||||||||||||||||||||
| 506 | 1494 | qr{$SQ | $DQ | $NQ}xs; | |||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||
| 509 | 1988 | ▶ | sub re_sqv { | ||||||||||||||||||||||||||
|
Subroutine
re_sqv: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 510 | 1988 | my ($self, $capture) = @_; | |||||||||||||||||||||||||||
| 511 | 1988 | my $body = qr{(?: [^\'\\]+ | \\.)*}x; | |||||||||||||||||||||||||||
| 512 | 1988 | ▶ | $body = qr{($body)} if $capture; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 513 | 1988 | qr{\'$body\'}s; | |||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||
| 516 | 1988 | ▶ | sub re_dqv { | ||||||||||||||||||||||||||
|
Subroutine
re_dqv: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 517 | 1988 | my ($self, $capture) = @_; | |||||||||||||||||||||||||||
| 518 | 1988 | my $body = qr{(?: [^\"\\]+ | \\.)*}x; | |||||||||||||||||||||||||||
| 519 | 1988 | ▶ | $body = qr{($body)} if $capture; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 520 | 1988 | qr{\"$body\"}s; | |||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||
| 523 | sub re_bare; | ||||||||||||||||||||||||||||
| 524 | 7 | *re_bare = \&re_bare_torelant; | |||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | 3 | ▶ | sub re_bare_strict { | ||||||||||||||||||||||||||
|
Subroutine
re_bare_strict: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 527 | 3 | shift->re_nsname(@_); | |||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||
| 530 | 1500 | ▶ | sub re_bare_torelant { | ||||||||||||||||||||||||||
|
Subroutine
re_bare_torelant: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 531 | 1500 | my ($self, $capture) = @_; | |||||||||||||||||||||||||||
| 532 | 1500 | my $body = qr{[^\'\"\s<>/]+ | /(?!>)}x; | |||||||||||||||||||||||||||
| 533 | 1500 | ▶ | $capture ? qr{($body+)} : qr{$body+}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||
| 536 | 0 | ▶ | sub strip_bs { | ||||||||||||||||||||||||||
|
Subroutine
strip_bs: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 537 | 0 | shift; | |||||||||||||||||||||||||||
| 538 | 0 | $_[0] =~ s/\\(\.)/$1/g; | |||||||||||||||||||||||||||
| 539 | 0 | $_[0]; | |||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||
| 542 | #---------------------------------------- | ||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||
| 544 | 991 | ▶ | sub re_declarator { | ||||||||||||||||||||||||||
|
Subroutine
re_declarator: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 545 | 991 | my ($self, $capture, $ns) = @_; | |||||||||||||||||||||||||||
| 546 | 991 | my $namepat = $self->re_tagname_qualified($capture, $ns); | |||||||||||||||||||||||||||
| 547 | 991 | my $arg_decls = q{[^>]}; | |||||||||||||||||||||||||||
| 548 | # $self->re_arg_decls(0); | ||||||||||||||||||||||||||||
| 549 | # print "<<$arg_decls>>\n"; | ||||||||||||||||||||||||||||
| 550 | 991 | ▶ | if (defined $capture and $capture > 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $capture and $capture > 1
MC/DC100%2/2
defined $capture and $capture > 1
defined $capture
$capture > 1
Truth table100%3/3
A and B
A= defined $captureB= $capture > 1
| |||||||||||||||||||||||||||||
| 551 | 491 | qr{<! (?: $namepat) ($arg_decls*?) \s*>}xs; | |||||||||||||||||||||||||||
| 552 | } else { | ||||||||||||||||||||||||||||
| 553 | 500 | my $re = qr{<! $namepat $arg_decls*? \s*>}xs; | |||||||||||||||||||||||||||
| 554 | 500 | ▶ | $capture ? qr{($re)} : $re; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||
| 558 | 991 | ▶ | sub re_comment { | ||||||||||||||||||||||||||
|
Subroutine
re_comment: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 559 | 991 | my ($self, $capture, $ns) = @_; | |||||||||||||||||||||||||||
| 560 | 991 | $ns = $self->re_prefix($capture, $ns, '#'); | |||||||||||||||||||||||||||
| 561 | 991 | ▶ | $capture ? qr{<!--$ns\b(.*?)-->}s : qr{<!--$ns\b.*?-->}s; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | 991 | ▶ | sub re_pi { | ||||||||||||||||||||||||||
|
Subroutine
re_pi: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 565 | 991 | my ($self, $capture, $ns) = @_; | |||||||||||||||||||||||||||
| 566 | 991 | $ns = $self->re_prefix($capture, $ns); | |||||||||||||||||||||||||||
| 567 | 991 | ▶ | my $body = $capture ? qr{(.*?)}s : qr{.*?}s; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 568 | 991 | qr{<\?\b$ns\b$body\?>}s; | |||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||
| 571 | 991 | ▶ | sub re_entity { | ||||||||||||||||||||||||||
|
Subroutine
re_entity: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 572 | 991 | shift->re_entity_pathexpr(@_); | |||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||
| 575 | # normal entity | ||||||||||||||||||||||||||||
| 576 | 3 | ▶ | sub re_entity_strict { | ||||||||||||||||||||||||||
|
Subroutine
re_entity_strict: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 577 | 3 | my ($self, $capture, $ns) = @_; | |||||||||||||||||||||||||||
| 578 | 3 | ▶ | $ns = defined $ns ? qq{$ns\:} : qr{\w+:}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 579 | 3 | my $body = $self->re_nsname; | |||||||||||||||||||||||||||
| 580 | 3 | ▶ | if (defined $capture and $capture > 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $capture and $capture > 1
MC/DC100%2/2
defined $capture and $capture > 1
defined $capture
$capture > 1
Truth table100%3/3
A and B
A= defined $captureB= $capture > 1
| |||||||||||||||||||||||||||||
| 581 | 1 | qr{&$ns($body);}xs; | |||||||||||||||||||||||||||
| 582 | } else { | ||||||||||||||||||||||||||||
| 583 | 2 | my $re = qr{&$ns$body;}xs; | |||||||||||||||||||||||||||
| 584 | 2 | ▶ | $capture ? qr{($re)} : $re; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||
| 588 | # extended (subscripted) entity. | ||||||||||||||||||||||||||||
| 589 | 6 | ▶ | sub re_entity_subscripted { | ||||||||||||||||||||||||||
|
Subroutine
re_entity_subscripted: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 590 | 6 | my ($self, $capture, $ns) = @_; | |||||||||||||||||||||||||||
| 591 | 6 | ▶ | $ns = defined $ns ? qq{$ns\:} : qr{\w+:}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 592 | 6 | my $name = $self->re_nsname; | |||||||||||||||||||||||||||
| 593 | 6 | my $sub = $self->re_subscript; | |||||||||||||||||||||||||||
| 594 | 6 | my $body = qq{$name$sub*}; | |||||||||||||||||||||||||||
| 595 | 6 | ▶ | if (defined $capture and $capture > 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $capture and $capture > 1
MC/DC100%2/2
defined $capture and $capture > 1
defined $capture
$capture > 1
Truth table100%3/3
A and B
A= defined $captureB= $capture > 1
| |||||||||||||||||||||||||||||
| 596 | 1 | qr{&($ns)($body);}xs; | |||||||||||||||||||||||||||
| 597 | } else { | ||||||||||||||||||||||||||||
| 598 | 5 | my $re = qr{&$ns$body;}xs; | |||||||||||||||||||||||||||
| 599 | 5 | ▶ | $capture ? qr{($re)} : $re; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||
| 603 | # This cannot handle matching paren, of course;-). | ||||||||||||||||||||||||||||
| 604 | 10 | ▶ | sub re_subscript { | ||||||||||||||||||||||||||
|
Subroutine
re_subscript: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 605 | 10 | my $name = shift->re_nsname; | |||||||||||||||||||||||||||
| 606 | 10 | qr{[\[\(\{] | |||||||||||||||||||||||||||
| 607 | [\w\.\-\+\$\[\]\{\}]*? | ||||||||||||||||||||||||||||
| 608 | [\}\)\]] | ||||||||||||||||||||||||||||
| 609 | |\. $name | ||||||||||||||||||||||||||||
| 610 | |\: [/\$\.\-\w]+ | ||||||||||||||||||||||||||||
| 611 | }xs; | ||||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||
| 614 | # more extended | ||||||||||||||||||||||||||||
| 615 | 994 | ▶ | sub re_entity_pathexpr { | ||||||||||||||||||||||||||
|
Subroutine
re_entity_pathexpr: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 616 | 994 | my ($self, $capture, $ns) = @_; | |||||||||||||||||||||||||||
| 617 | 994 | $ns = $self->re_prefix(0, $self->entity_ns($ns), ''); | |||||||||||||||||||||||||||
| 618 | 994 | my $body = qr{[\w\$\-\+\*/%<>\.=\@\|!:\[\]\{\}\(,\)]*}; | |||||||||||||||||||||||||||
| 619 | 994 | ▶ | if (defined $capture and $capture > 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $capture and $capture > 1
MC/DC100%2/2
defined $capture and $capture > 1
defined $capture
$capture > 1
Truth table100%3/3
A and B
A= defined $captureB= $capture > 1
| |||||||||||||||||||||||||||||
| 620 | 492 | qr{&($ns\b$body);}xs; | |||||||||||||||||||||||||||
| 621 | } else { | ||||||||||||||||||||||||||||
| 622 | 502 | my $re = qr{&$ns\b$body;}xs; | |||||||||||||||||||||||||||
| 623 | 502 | ▶ | $capture ? qr{($re)} : $re; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||
| 627 | 994 | ▶ | sub entity_ns { | ||||||||||||||||||||||||||
|
Subroutine
entity_ns: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 628 | 994 | my ($self, $ns) = @_; | |||||||||||||||||||||||||||
| 629 | my $special = $self->{cf_special_entities} | ||||||||||||||||||||||||||||
| 630 | 994 | ▶ | or return $ns; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 631 | # XXX: die "entity_ns \$ns ($ns) is not yet implemented" if defined $ns; | ||||||||||||||||||||||||||||
| 632 | 90 | $self->re_ns(0, undef, $special); | |||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||
| 635 | # | ||||||||||||||||||||||||||||
| 636 | 2976 | ▶ | sub re_prefix { | ||||||||||||||||||||||||||
|
Subroutine
re_prefix: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 637 | 2976 | (my MY $self, my ($capture, $ns, $pre, $suf)) = @_; | |||||||||||||||||||||||||||
| 638 | 2976 | ▶ | $ns = $$self{re_ns} unless defined $ns; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 639 | 2976 | ▶ | $pre = '' unless defined $pre; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 640 | 2976 | ▶ | $suf = '' unless defined $suf; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 641 | 2976 | ▶ | if (defined $ns and $ns ne '') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $ns and $ns ne ""
MC/DC50%1/2
defined $ns and $ns ne ""
defined $ns
$ns ne ""
Truth table66%2/3
A and B
A= defined $nsB= $ns ne ""
| |||||||||||||||||||||||||||||
| 642 | 2974 | ▶ | $ns = "($ns)" if $capture && $capture > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$capture and $capture > 1
MC/DC100%2/2
$capture and $capture > 1
$capture
$capture > 1
Truth table100%3/3
A and B
A= $captureB= $capture > 1
| |||||||||||||||||||||||||||||
| 643 | 2974 | qq{$pre$ns$suf}; | |||||||||||||||||||||||||||
| 644 | } else { | ||||||||||||||||||||||||||||
| 645 | 2 | '' | |||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||
| 649 | 7 | 1; | |||||||||||||||||||||||||||