blib/lib/YATT/Lite/LRXML/ParseEntpath.pm

filter: Statementstmt 89.3% 101 / 113 Branchbran 81.4% 57 / 70 Conditioncond 62.5% 5 / 8 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 92.3% 12 / 13 Podpod n/a totaltotal 85.1% 178 / 209 CC 39 SCAR 22.3
CC
39
Cov
85%
_parse_hash
30.0
_parse_entterm
11.0
_parse_pipeline
10.0
CRAP 9.3
« blib/lib/YATT/Lite/Site.pm ↑ Summary blib/lib/YATT/Lite/Factory.pm »
1 package YATT::Lite::LRXML::ParseEntpath;
2 74 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 74 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 74 ▶package YATT::Lite::LRXML; use YATT::Lite::LRXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # item ::=
8 # pathItem
9 # [ pathItem+ ]
10  
11 # pathItem ::=
12 # [call => name, item, item, ...]
13 # [var => name]
14 # [array => item, item, ...]
15 # [hash => item, item, ...]
16 # [aref => item]
17 # [href => item]
18  
19 # Ex:
20 # [aref => [var => x]]
21 # [aref => [[var => i], [var => j]]
22  
23 150 ▶sub _parse_text_entities {
Subroutine _parse_text_entities: called CC=1 SCAR=0.0
24 150 my MY $self = shift;
25 150 $self->_parse_text_entities_at($self->{_curpos}, @_);
26 }
27 420 ▶sub _parse_text_entities_at {
Subroutine _parse_text_entities_at: called CC=5 SCAR=16.1
28 420 my MY $self = $_[0];
29 420 local ($self->{_curpos}, $_) = @_[1,2];
30 420 my ($curpos) = ($self->{_curpos});
31 420 my $totalEnd = $curpos + length $_;
32 420 my @result;
33 {
34  
35 420 my $total = length $_;
36 420 ▶ while (s{^(.*?)$$self{_re_entopn}}{}xs) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^(.*?)$self->{"_re_entopn"}//sx) 80 420 500
37 80 my $before = $curpos;
38 80 ▶ if (length $1) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $1) 23 57 80
39 23 push @result, $1;
40 23 $self->{_endln} += numLines($1);
41 23 $curpos += length $1;
42 }
43 80 push @result, my $node = $self->mkentity($curpos, undef, $self->{_endln});
44 80 $curpos = $totalEnd - length $_;
45 80 $node->[NODE_END] = $curpos;
46 }
47 }
48 420 ▶ if (@result) {
Branch: 1 branch
BranchTrueFalseTotal
if (@result) { } 73 347 420
49 73 ▶ push @result, $_ if length $_;
Branch: 1 branch
BranchTrueFalseTotal
if length $_ 30 43 73
50 73 \@result;
51 } else {
52 347 $_;
53 }
54 }
55  
56 # &yatt:foo:bar
57 #
58 # entpath ::= pipeline ';'
59 # pipeline ::= (pathElem | '[' <group ']'> | '{' <group '}'>)+
60 # pathElem ::= ':' name ('(' <group ')'>)?
61 # group C ::= term* C
62 # term ::= (pipeline | expr | text) [,:]?
63  
64 74 our (%open_head, %open_rest, %close_ch, %for_expr);
65 74 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
66 74 %open_head = qw| ( call [ array { hash|;
67 74 %open_rest = qw| ( invoke [ aref { href|;
68 74 %close_ch = qw( ( ) [ ] { } );
69 74 %for_expr = (aref => 1);
70 }
71 1020 ▶sub _parse_entpath {
Subroutine _parse_entpath: called CC=4 SCAR=13.9
72 1020 my MY $self = shift;
73 1020 local $self->{_original_entpath} = $_;
74 1020 ▶ my $how = shift || '_parse_pipeline';
Condition100%2/2
shift() || '_parse_pipeline'
l!l
21018
MC/DC100%1/1
shift() || '_parse_pipeline'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
75 1020 my $prevlen = length $_;
76 1020 my @pipe = $self->$how(@_);
77 1016 ▶ unless (s{^;}{}xs) {
Branch: 1 branch
BranchTrueFalseTotal
unless (s/^;//sx) 7 1009 1016
78 7 ▶ if (/^\s|^$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s|^$/) { } 3 4 7
79 die $self->synerror_at($self->{_startln}
80 3 , q{Entity has no terminator: '%s'}
81 , $self->shortened_original_entpath);
82  
83 } else {
84 die $self->synerror_at($self->{_startln}
85 4 , q{Syntax error in entity: '%s'}
86 , $self->shortened_original_entpath);
87 }
88 }
89 1009 $self->{_curpos} += $prevlen - length $_;
90 1009 @pipe;
91 }
92 1317 ▶sub _parse_pipeline {
Subroutine _parse_pipeline: called CC=10 SCAR=23.1
93 1317 (my MY $self) = @_;
94 1317 ▶ unless (defined $_) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_) 0 1317 1317
95 0 Carp::confess "parse_pipeline for undefined \$_!";
96 }
97 1317 my @pipe;
98 1317 ▶ while (s{^ : (?<var>\w+) (?<open>\()?
Branch: 1 branch
BranchTrueFalseTotal
if (s/^ : (?<var>\w+) (?<open>\()? | ^ (?<open>\[) | ^ (?<open>(?<hash>\{))//sx) 1466 1313 2779
99 | ^ (?<open>\[)
100 | ^ (?<open>(?<hash>\{))}{}xs) {
101 1466 ▶ my $table = @pipe ? \%open_rest : \%open_head;
Branch: 1 branch
BranchTrueFalseTotal
@pipe ? : 154 1312 1466
102 my $type = $+{open} ? $table->{$+{open}}
103 1466 ▶ : @pipe ? 'prop' : 'var';
Branch: 2 branches
BranchTrueFalseTotal
$+{'open'} ? : 752 714 1466
@pipe ? : 25 689 714
104 1466 push @pipe, do {
105 # if (not @pipe and $+{hash}) {
106 # [$type, $self->_parse_hash]
107 # } else {
108 [$type, defined $+{var} ? $+{var} : ()
109 , $+{open}
110 1466 ▶ ? $self->_parse_entgroup($close_ch{$+{open}}, $for_expr{$type})
Branch: 2 branches
BranchTrueFalseTotal
defined $+{'var'} ? : 1344 122 1466
$+{'open'} ? : 752 714 1466
111 : ()];
112 # }
113 };
114 }
115 1313 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 1077 236 1313
116 @pipe
117 1077 } else {
118 236 ▶ @pipe > 1 ? \@pipe : $pipe[0]
Branch: 1 branch
BranchTrueFalseTotal
@pipe > 1 ? : 17 219 236
119 }
120 }
121 754 ▶sub _parse_entgroup {
Subroutine _parse_entgroup: called CC=5 SCAR=16.1
122 754 (my MY $self, my ($close, $for_expr)) = @_;
123 754 my $prevlen = length $_;
124 754 my $emptycnt;
125 my @pipe;
126 754 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
s/^ ($self->{"_re_eclose"})//sx or do { do { push @pipe, $self->_parse_entterm($for_expr); if (length $_ == $prevlen and $emptycnt++) { die $self->synerror_at($self->{"_startln"}, "Syntax error in entity: '%s'", $self->shortened_original_entpath); } ; $prevlen = length $_ } } 753 403 1156
127 1157 push @pipe, $self->_parse_entterm($for_expr);
128 1157 ▶ if (length $_ == $prevlen and $emptycnt++) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $_ == $prevlen and $emptycnt++) 1 1156 1157
Condition100%3/3
length $_ == $prevlen and $emptycnt++
!ll&&!rl&&r
8892671
MC/DC100%2/2
length $_ == $prevlen and $emptycnt++
length $_ == $prevlen $emptycnt++
Truth table100%3/3
A and B
A= length $_ == $prevlenB= $emptycnt++
ABresult
0X0
100
111
129 die $self->synerror_at($self->{_startln}
130 1 , q{Syntax error in entity: '%s'}
131 , $self->shortened_original_entpath);
132 }
133 1156 $prevlen = length $_;
134 } until (s{^ ($$self{_re_eclose})}{}xs);
135 753 ▶ die $self->synerror_at($self->{_startln}, q{Paren mismatch: expect %s got %s: str=%s}
Branch: 1 branch
BranchTrueFalseTotal
unless $1 eq $close 3 750 753
136 , $close, $1, $_)
137 unless $1 eq $close;
138 750 @pipe;
139 }
140 1157 ▶sub _parse_entterm {
Subroutine _parse_entterm: called CC=11 SCAR=24.0
141 1157 (my MY $self, my ($for_expr)) = @_;
142 1157 ▶ my $text_type = $for_expr ? 'expr' : 'text';
Branch: 1 branch
BranchTrueFalseTotal
$for_expr ? : 46 1111 1157
143 1157 ▶ if (s{^ ,}{}xs) {
Branch: 2 branches
BranchTrueFalseTotal
if (s/^ ,//sx) { } 14 1143 1157
elsif (s/^ (?=[\)\]\};])//sx) { } 266 877 1143
144 14 return [text => ''];
145 } elsif (s{^ (?=[\)\]\};])}{}xs) {
146 266 return;
147 }
148 877 my $term = do {
149 877 ▶ if (s{^(?: (?<text> $$self{_ch_etext} (?:$$self{_ch_etext} | :)* )
Branch: 1 branch
BranchTrueFalseTotal
if (s/^(?: (?<text> $self->{'_ch_etext'} (?:$self->{'_ch_etext'} | :)* ) | $self->{'_re_eparen'} )//sx) { } 641 236 877
150 | $$self{_re_eparen}
151 )}{}xs) {
152 641 my $text = '';
153 TEXT: {
154 641 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
s/^ (?: (?<text> (?:$self->{"_ch_etext"} | :)+) | $self->{"_re_eparen"} | $self->{"_re_eopen"} | (?= (?<close>[\)\]\};,])))//sx and do { do { last TEXT if $+{"close"}; if (defined $+{"text"}) { $text .= $+{"text"}; } elsif (defined $+{"paren"}) { $text .= $+{"paren"}; } ; $text .= $+{"open"} . $self->_parse_group_string($YATT::Lite::LRXML::close_ch{$+{"open"}}) if $+{"open"} } } 661 0 661
155 1302 ▶ last TEXT if $+{close};
Branch: 1 branch
BranchTrueFalseTotal
if $+{"close"} 641 661 1302
156 661 ▶ if (defined $+{text}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $+{'text'}) { } 638 23 661
elsif (defined $+{'paren'}) { } 11 12 23
157 638 $text .= $+{text};
158 } elsif (defined $+{paren}) {
159 11 $text .= $+{paren};
160 }
161 $text .= $+{open} . $self->_parse_group_string($close_ch{$+{open}})
162 661 ▶ if $+{open};
Branch: 1 branch
BranchTrueFalseTotal
if $+{"open"} 12 649 661
163 } while (s{^ (?: (?<text> (?:$$self{_ch_etext} | :)+)
164 | $$self{_re_eparen}
165 | $$self{_re_eopen}
166 | (?= (?<close>[\)\]\};,])))}{}xs);
167 }
168 641 ▶ [($text =~ s/^=// ? 'expr' : $text_type) => $text];
Branch: 1 branch
BranchTrueFalseTotal
$text =~ s/^=// ? : 15 626 641
169 } else {
170 236 $self->_parse_pipeline;
171 }
172 };
173 # Suffix.
174 877 s{^ [,:]?}{}xs;
175 877 $term;
176 }
177  
178 12 ▶sub _parse_group_string {
Subroutine _parse_group_string: called CC=5 SCAR=17.8
179 12 (my MY $self, my $close) = @_;
180 12 my $oldpos = pos;
181 12 my $text = '';
182 12 ▶ while (s{^ ((?:$$self{_ch_etext}+ | [,:])*)
Branch: 1 branch
BranchTrueFalseTotal
if (s/^ ((?:$self->{"_ch_etext"}+ | [,:])*) (?: $self->{"_re_eopen"} | $self->{"_re_eclose"})//sx) 12 0 12
183 (?: $$self{_re_eopen} | $$self{_re_eclose})}{}xs) {
184 # print pos($_), "\n";
185 12 $text .= $&;
186 12 ▶ if ($+{close}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($+{"close"}) 12 0 12
187 die $self->synerror_at($self->{_startln}, q{Paren mismatch: expect %s got %s: str=%s}
188 , $close, $+{close}, substr($_, $oldpos, pos))
189 12 ▶ unless $+{close} eq $close;
Branch: 1 branch
BranchTrueFalseTotal
unless $+{"close"} eq $close 0 12 12
190 12 last;
191 }
192 0 ▶ $text .= $self->_parse_group_string($close_ch{$+{open}}) if $+{open};
Branch: 1 branch
BranchTrueFalseTotal
if $+{"open"} 0 0 0
193 }
194 12 $text;
195 }
196  
197 0 ▶sub _parse_hash {
Subroutine _parse_hash: not called CC=5 SCAR=34.0
198 0 (my MY $self) = @_;
199  
200 0 my ($lastlen, @hash);
201 0 ▶ while (not defined $lastlen or length $_ < $lastlen) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $lastlen or length $_ < $lastlen) 0 0 0
Condition0%0/3
not defined $lastlen or length $_ < $lastlen
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $lastlen or length $_ < $lastlen
not defined $lastlen length $_ < $lastlen
Truth table0%0/3
not(A) or B
A= not defined $lastlenB= length $_ < $lastlen
ABresult
1X1
011
000
202 0 $lastlen = length $_;
203 0 ▶ return @hash if s/^\}//;
Branch: 1 branch
BranchTrueFalseTotal
if s/^\}// 0 0 0
204 0 ▶ s{^ ($$self{_ch_etext}*) (?: [:,])}{}xs or last;
Branch: 1 branch
BranchTrueFalseTotal
s/^ ($self->{"_ch_etext"}*) (?: [:,])//sx or last 0 0 0
205 0 push @hash, [text => $1];
206 0 push @hash, $self->_parse_entterm;
207 0 s{^,}{};
208 }
209 0 die $self->synerror_at($self->{_startln}, q{Paren mismatch: expect \} got %s}
210 , $self->shortened_original_entpath);
211 }
212  
213 74 ▶use YATT::Lite::Breakpoint qw(break_load_parseentpath);
Subroutine BEGIN: called CC=1 SCAR=0.0
214 74 break_load_parseentpath();
215  
216 74 1;
« blib/lib/YATT/Lite/Site.pm ↑ Summary blib/lib/YATT/Lite/Factory.pm »