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 47 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 47 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 47 ▶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 125 ▶sub _parse_text_entities {
Subroutine _parse_text_entities: called CC=1 SCAR=0.0
24 125 my MY $self = shift;
25 125 $self->_parse_text_entities_at($self->{_curpos}, @_);
26 }
27 288 ▶sub _parse_text_entities_at {
Subroutine _parse_text_entities_at: called CC=5 SCAR=16.1
28 288 my MY $self = $_[0];
29 288 local ($self->{_curpos}, $_) = @_[1,2];
30 288 my ($curpos) = ($self->{_curpos});
31 288 my $totalEnd = $curpos + length $_;
32 288 my @result;
33 {
34  
35 288 my $total = length $_;
36 288 ▶ while (s{^(.*?)$$self{_re_entopn}}{}xs) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^(.*?)$self->{"_re_entopn"}//sx) 59 288 347
37 59 my $before = $curpos;
38 59 ▶ if (length $1) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $1) 19 40 59
39 19 push @result, $1;
40 19 $self->{_endln} += numLines($1);
41 19 $curpos += length $1;
42 }
43 59 push @result, my $node = $self->mkentity($curpos, undef, $self->{_endln});
44 59 $curpos = $totalEnd - length $_;
45 59 $node->[NODE_END] = $curpos;
46 }
47 }
48 288 ▶ if (@result) {
Branch: 1 branch
BranchTrueFalseTotal
if (@result) { } 53 235 288
49 53 ▶ push @result, $_ if length $_;
Branch: 1 branch
BranchTrueFalseTotal
if length $_ 26 27 53
50 53 \@result;
51 } else {
52 235 $_;
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 47 our (%open_head, %open_rest, %close_ch, %for_expr);
65 47 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
66 47 %open_head = qw| ( call [ array { hash|;
67 47 %open_rest = qw| ( invoke [ aref { href|;
68 47 %close_ch = qw( ( ) [ ] { } );
69 47 %for_expr = (aref => 1);
70 }
71 722 ▶sub _parse_entpath {
Subroutine _parse_entpath: called CC=4 SCAR=13.9
72 722 my MY $self = shift;
73 722 local $self->{_original_entpath} = $_;
74 722 ▶ my $how = shift || '_parse_pipeline';
Condition100%2/2
shift() || '_parse_pipeline'
l!l
2720
MC/DC100%1/1
shift() || '_parse_pipeline'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
75 722 my $prevlen = length $_;
76 722 my @pipe = $self->$how(@_);
77 718 ▶ unless (s{^;}{}xs) {
Branch: 1 branch
BranchTrueFalseTotal
unless (s/^;//sx) 7 711 718
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 711 $self->{_curpos} += $prevlen - length $_;
90 711 @pipe;
91 }
92 953 ▶sub _parse_pipeline {
Subroutine _parse_pipeline: called CC=10 SCAR=23.1
93 953 (my MY $self) = @_;
94 953 ▶ unless (defined $_) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_) 0 953 953
95 0 Carp::confess "parse_pipeline for undefined \$_!";
96 }
97 953 my @pipe;
98 953 ▶ while (s{^ : (?<var>\w+) (?<open>\()?
Branch: 1 branch
BranchTrueFalseTotal
if (s/^ : (?<var>\w+) (?<open>\()? | ^ (?<open>\[) | ^ (?<open>(?<hash>\{))//sx) 1046 949 1995
99 | ^ (?<open>\[)
100 | ^ (?<open>(?<hash>\{))}{}xs) {
101 1046 ▶ my $table = @pipe ? \%open_rest : \%open_head;
Branch: 1 branch
BranchTrueFalseTotal
@pipe ? : 98 948 1046
102 my $type = $+{open} ? $table->{$+{open}}
103 1046 ▶ : @pipe ? 'prop' : 'var';
Branch: 2 branches
BranchTrueFalseTotal
$+{'open'} ? : 587 459 1046
@pipe ? : 11 448 459
104 1046 push @pipe, do {
105 # if (not @pipe and $+{hash}) {
106 # [$type, $self->_parse_hash]
107 # } else {
108 [$type, defined $+{var} ? $+{var} : ()
109 , $+{open}
110 1046 ▶ ? $self->_parse_entgroup($close_ch{$+{open}}, $for_expr{$type})
Branch: 2 branches
BranchTrueFalseTotal
defined $+{'var'} ? : 936 110 1046
$+{'open'} ? : 587 459 1046
111 : ()];
112 # }
113 };
114 }
115 949 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 728 221 949
116 @pipe
117 728 } else {
118 221 ▶ @pipe > 1 ? \@pipe : $pipe[0]
Branch: 1 branch
BranchTrueFalseTotal
@pipe > 1 ? : 17 204 221
119 }
120 }
121 589 ▶sub _parse_entgroup {
Subroutine _parse_entgroup: called CC=5 SCAR=16.1
122 589 (my MY $self, my ($close, $for_expr)) = @_;
123 589 my $prevlen = length $_;
124 589 my $emptycnt;
125 my @pipe;
126 589 ▶ 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 $_ } } 588 374 962
127 963 push @pipe, $self->_parse_entterm($for_expr);
128 963 ▶ if (length $_ == $prevlen and $emptycnt++) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $_ == $prevlen and $emptycnt++) 1 962 963
Condition100%3/3
length $_ == $prevlen and $emptycnt++
!ll&&!rl&&r
8021601
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 962 $prevlen = length $_;
134 } until (s{^ ($$self{_re_eclose})}{}xs);
135 588 ▶ die $self->synerror_at($self->{_startln}, q{Paren mismatch: expect %s got %s: str=%s}
Branch: 1 branch
BranchTrueFalseTotal
unless $1 eq $close 3 585 588
136 , $close, $1, $_)
137 unless $1 eq $close;
138 585 @pipe;
139 }
140 963 ▶sub _parse_entterm {
Subroutine _parse_entterm: called CC=11 SCAR=24.0
141 963 (my MY $self, my ($for_expr)) = @_;
142 963 ▶ my $text_type = $for_expr ? 'expr' : 'text';
Branch: 1 branch
BranchTrueFalseTotal
$for_expr ? : 38 925 963
143 963 ▶ if (s{^ ,}{}xs) {
Branch: 2 branches
BranchTrueFalseTotal
if (s/^ ,//sx) { } 14 949 963
elsif (s/^ (?=[\)\]\};])//sx) { } 159 790 949
144 14 return [text => ''];
145 } elsif (s{^ (?=[\)\]\};])}{}xs) {
146 159 return;
147 }
148 790 my $term = do {
149 790 ▶ 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) { } 569 221 790
150 | $$self{_re_eparen}
151 )}{}xs) {
152 569 my $text = '';
153 TEXT: {
154 569 ▶ 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"} } } 589 0 589
155 1158 ▶ last TEXT if $+{close};
Branch: 1 branch
BranchTrueFalseTotal
if $+{"close"} 569 589 1158
156 589 ▶ if (defined $+{text}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $+{'text'}) { } 566 23 589
elsif (defined $+{'paren'}) { } 11 12 23
157 566 $text .= $+{text};
158 } elsif (defined $+{paren}) {
159 11 $text .= $+{paren};
160 }
161 $text .= $+{open} . $self->_parse_group_string($close_ch{$+{open}})
162 589 ▶ if $+{open};
Branch: 1 branch
BranchTrueFalseTotal
if $+{"open"} 12 577 589
163 } while (s{^ (?: (?<text> (?:$$self{_ch_etext} | :)+)
164 | $$self{_re_eparen}
165 | $$self{_re_eopen}
166 | (?= (?<close>[\)\]\};,])))}{}xs);
167 }
168 569 ▶ [($text =~ s/^=// ? 'expr' : $text_type) => $text];
Branch: 1 branch
BranchTrueFalseTotal
$text =~ s/^=// ? : 15 554 569
169 } else {
170 221 $self->_parse_pipeline;
171 }
172 };
173 # Suffix.
174 790 s{^ [,:]?}{}xs;
175 790 $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 47 ▶use YATT::Lite::Breakpoint qw(break_load_parseentpath);
Subroutine BEGIN: called CC=1 SCAR=0.0
214 47 break_load_parseentpath();
215  
216 47 1;
« blib/lib/YATT/Lite/Site.pm ↑ Summary blib/lib/YATT/Lite/Factory.pm »