web/cgi-bin/yatt.lib/YATT/LRXML/EntityPath.pm

filter: Statementstmt 94.5% 121 / 128 Branchbran 76.4% 78 / 102 Conditioncond 71.8% 23 / 32 MC/DCmcdc 47.6% 10 / 21 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 3 totaltotal 81.8% 244 / 298 CC 63 SCAR 22.1
CC
63
Cov
85%
_parse_term
12.0
_parse_hash
11.4
is_nested_entpath
10.7
CRAP 9.1
« blib/lib/YATT/Util/RLimit.pm ↑ Summary web/cgi-bin/yatt.lib/YATT/Fields.pm »
1 # -*- mode: perl; coding: utf-8 -*-
2 package YATT::LRXML::EntityPath;
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶BEGIN {require Exporter; *import = \&Exporter::import}
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 our @EXPORT_OK = qw(parse_entpath is_nested_entpath);
7 4 our @EXPORT = @EXPORT_OK;
8  
9 =pod
10  
11 term ::= ( text | expr | pipeline ) ','? ;
12  
13 pipeline ::= container? trail+ ;
14  
15 trail ::= var | '[' term ']' ;
16  
17 container::= '[' term* ']'
18 | '{' ( dot_name (':' text | '=' term )
19 | other+ ','?
20 )* '}' ;
21  
22 var ::= (':'+ | '.'+) name ( '(' term* ')' )? ;
23 name ::= \w+ ;
24 dot_name ::= [\w\.]+ ;
25  
26 expr ::= '=' text ;
27 text ::= word ( group word? )* ; -- group で始まるのは、container.
28  
29 group ::= [\(\[\{] ( text | ',' )* [\}\]\)]
30  
31 word ::= [\w\$\-\+\*/%<>] other* ;
32 other ::= [\w\$\-\+\*/%<>:\.!=] ;
33  
34 =cut
35  
36 # is_nested_entpath($entpath, ?head?)
37  
38 50 ▶sub is_nested_entpath {
Subroutine is_nested_entpath: called CC=7 SCAR=23.7
Pod undocumented
39 50 ▶ return unless defined $_[0] and ref $_[0] eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] and ref $_[0] eq "ARRAY" 0 50 50
Condition33%1/3
defined $_[0] and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
0050
MC/DC0%0/2
defined $_[0] and ref $_[0] eq "ARRAY"
defined $_[0] ref $_[0] eq "ARRAY"
Truth table33%1/3
A and B
A= defined $_[0]B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
40 50 my $item = shift;
41 50 ▶ return unless defined $item->[0] and ref $item->[0] eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $item->[0] and ref $item->[0] eq "ARRAY" 48 2 50
Condition66%2/3
defined $item->[0] and ref $item->[0] eq "ARRAY"
!ll&&!rl&&r
0482
MC/DC50%1/2
defined $item->[0] and ref $item->[0] eq "ARRAY"
defined $item->[0] ref $item->[0] eq "ARRAY"
Truth table66%2/3
A and B
A= defined $item->[0]B= ref $item->[0] eq "ARRAY"
ABresult
0X0
100
111
42 2 ▶ return 1 unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 2 0 2
43 0 ▶ defined $item->[0][0] and $item->[0][0] eq $_[0];
Branch: 1 branch
BranchTrueFalseTotal
defined $item->[0][0] and $item->[0][0] eq $_[0] 0 0 0
44 }
45  
46 4 our ($TRANS, $NODE, $ORIG);
47  
48 2 ▶sub mydie (@) {
Subroutine mydie: called CC=3 SCAR=12.3
Pod undocumented
49 2 my $fmt = shift;
50 2 my $diag = do {
51 2 ▶ if ($TRANS and $NODE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($YATT::LRXML::EntityPath::TRANS and $YATT::LRXML::EntityPath::NODE) { } 2 0 2
Condition33%1/3
$YATT::LRXML::EntityPath::TRANS and $YATT::LRXML::EntityPath::NODE
!ll&&!rl&&r
002
MC/DC0%0/2
$YATT::LRXML::EntityPath::TRANS and $YATT::LRXML::EntityPath::NODE
$YATT::LRXML::EntityPath::TRANS $YATT::LRXML::EntityPath::NODE
Truth table33%1/3
A and B
A= $YATT::LRXML::EntityPath::TRANSB= $YATT::LRXML::EntityPath::NODE
ABresult
0X0
100
111
52 2 $TRANS->node_error($NODE, $fmt, @_);
53 } else {
54 0 sprintf $fmt, @_;
55 };
56 };
57 2 die $diag;
58 }
59  
60 272 ▶sub parse_entpath {
Subroutine parse_entpath: called CC=5 SCAR=16.2
Pod undocumented
61 272 my ($pack, $orig, $trans, $node) = @_;
62 272 ▶ return undef unless defined $orig;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $orig 1 271 272
63 271 local $_ = $orig;
64 271 local $ORIG = $orig;
65 271 local $TRANS = $trans;
66 271 local $NODE = $node;
67 271 my @result;
68 271 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 271 0 271
69 271 @result = &_parse_pipeline;
70 } else {
71 0 $result[0] = &_parse_pipeline;
72 }
73 270 ▶ if ($_ ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ ne "") 1 269 270
74 1 mydie "Unexpected token '$_' in entpath '$orig'";
75 }
76 269 ▶ wantarray ? @result : $result[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 269 0 269
77 }
78  
79 4 my %open_head = qw| ( call [ array { hash |;
80 4 my %open_rest = qw| ( call [ aref |;
81 4 my %close_ch = qw( ( ) [ ] { } );
82  
83 4 my $re_var = qr{[:]+ (\w+) (\()?}x;
84 4 my $re_other= qr{[\w\$\-\+\*/%<>\.=\@\|!:]}x;
85 4 my $re_word = qr{[\w\$\-\+\*/%<>\.=\@\|!] $re_other*}x;
86  
87 316 ▶sub _parse_pipeline {
Subroutine _parse_pipeline: called CC=9 SCAR=22.1
88 316 my @pipe;
89 316 ▶ if (s/^ \[ //x) {
Branch: 2 branches
BranchTrueFalseTotal
if (s/^ \[ //x) { } 6 310 316
elsif (s/^ \{ //x) { } 17 293 310
90 # container
91 6 push @pipe, _parse_group(['array'], ']', \&_parse_term);
92 } elsif (s/^ \{ //x) {
93 17 push @pipe, &_parse_hash;
94 }
95 316 ▶ while (s/^$re_var | ^(\[) | ^(\{)//x) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^$re_var | ^(\[) | ^(\{)//x) 361 315 676
96 361 ▶ if ($2) {
Branch: 4 branches
BranchTrueFalseTotal
if ($2) { } 96 265 361
elsif (defined $1) { } 239 26 265
elsif (defined $3) { } 24 2 26
elsif (defined $4) { } 2 0 2
97 # '('
98 96 push @pipe, _parse_group([call => $1], ')', \&_parse_term);
99 } elsif (defined $1) {
100 # \w+
101 239 push @pipe, [var => $1];
102 } elsif (defined $3) { # '['
103 24 push @pipe, _parse_group(['aref'], ']', \&_parse_term, 'expr');
104 } elsif (defined $4) {
105 2 push @pipe, _parse_group(['var'], '}', \&_parse_term);
106 } else {
107 0 mydie "?? $_";
108 }
109 }
110 315 ▶ wantarray ? @pipe : \@pipe;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 315 0 315
111 }
112  
113 4 my $re_grend = qr{ (?=[\)\]\}]) | $ }x;
114 4 my $re_text = qr{($re_word) # 1
115 (?: ([\(\[\{]) # 2
116 | $re_grend)?
117 | $re_grend
118 }x;
119  
120 169 ▶sub _parse_term {
Subroutine _parse_term: called CC=12 SCAR=24.9
121 169 my ($literal_type) = @_;
122 169 ▶ $literal_type ||= 'text';
Condition100%2/2
$literal_type ||= "text"
l!l
24145
MC/DC100%1/1
$literal_type ||= "text"
$literal_type
Truth table100%2/2
A
A= $literal_type
Aresult
11
00
123 # :foo() [call => foo]
124 # :foo(,) [call => foo => [text => '']]
125 # :foo(bar) [call => foo => [text => 'bar']]
126 # :foo(,,) [call => foo => [text => ''], [text => '']]
127 # :foo(bar,) [call => foo => [text => 'bar'], [text => '']]
128 # :foo(bar,,)[call => foo => [text => 'bar'], [text => '']]
129 169 ▶ if (s{^,}{}x) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^,//x) 8 161 169
130 8 return [$literal_type => ''];
131 }
132 161 ▶ if (my $is_expr = s{^=}{}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $is_expr = s/^=//) 12 149 161
133 12 return &_parse_expr;
134 }
135 149 my @result;
136 149 ▶ unless (s{^$re_text}{}) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^$re_text//) { } 104 45 149
137 45 @result = &_parse_pipeline;
138 } else {
139 104 my $result = '';
140 TEXT: {
141 104 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
s/^(?: $re_text | ([\(\[\{]) | ([:\.]) ) //x and do { do { $result .= $1 if defined $1; $result .= $4 if defined $4; if (my $opn = $2 || $3) { $result .= $opn; $result .= &_parse_group_string($close_ch{$opn}); } elsif (not defined $1 || defined $4) { last TEXT; } } } 61 44 105
142 165 ▶ $result .= $1 if defined $1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $1 106 59 165
143 165 ▶ $result .= $4 if defined $4;
Branch: 1 branch
BranchTrueFalseTotal
if defined $4 0 165 165
144 165 ▶ if (my $opn = $2 || $3) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $opn = $2 || $3) { } 4 161 165
elsif (not defined $1 || defined $4) { } 59 102 161
Condition66%2/3
$2 || $3
l!l&&r!l&&!r
40161
MC/DC50%1/2
$2 || $3
$2 $3
Truth table66%2/3
A || B
A= $2B= $3
ABresult
1X1
011
000
145 # open group
146 4 $result .= $opn;
147 4 $result .= &_parse_group_string($close_ch{$opn});
148 ▶ } elsif (not defined $1 and not defined $4) {
Condition66%2/3
defined $1 || defined $4
l!l&&r!l&&!r
102059
MC/DC50%1/2
defined $1 || defined $4
defined $1 defined $4
Truth table66%2/3
A || B
A= defined $1B= defined $4
ABresult
1X1
011
000
149 59 last TEXT;
150 }
151 } while s{^(?: $re_text | ([\(\[\{]) | ([:\.]) ) }{}x;
152 }
153 103 @result = [$literal_type => $result];
154 }
155 148 s/^,//;
156 148 @result;
157 }
158  
159 12 ▶sub _parse_expr {
Subroutine _parse_expr: called CC=9 SCAR=22.0
160 12 my $literal_type = 'expr';
161 12 ▶ if (s{^,}{}x) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^,//x) 0 12 12
162 0 return [$literal_type => ''];
163 }
164 12 my $result = '';
165 TEXT:
166 12 ▶ while (s{^(?: $re_text | ([\(\[\{]) | ([:\.]) ) }{}x) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^(?: $re_text | ([\(\[\{]) | ([:\.]) ) //x) 27 8 35
167 27 ▶ $result .= $1 if defined $1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $1 18 9 27
168 27 ▶ $result .= $4 if defined $4;
Branch: 1 branch
BranchTrueFalseTotal
if defined $4 1 26 27
169 27 ▶ if (my $opn = $2 || $3) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $opn = $2 || $3) { } 12 15 27
elsif (not defined $1 || defined $4) { } 4 11 15
Condition100%3/3
$2 || $3
l!l&&r!l&&!r
8415
MC/DC100%2/2
$2 || $3
$2 $3
Truth table100%3/3
A || B
A= $2B= $3
ABresult
1X1
011
000
170 # open group
171 12 $result .= $opn;
172 12 $result .= &_parse_group_string($close_ch{$opn});
173 ▶ } elsif (not defined $1 and not defined $4) {
Condition100%3/3
defined $1 || defined $4
l!l&&r!l&&!r
1014
MC/DC100%2/2
defined $1 || defined $4
defined $1 defined $4
Truth table100%3/3
A || B
A= defined $1B= defined $4
ABresult
1X1
011
000
174 4 last TEXT;
175 }
176 }
177 12 s/^,//;
178 12 [$literal_type => $result];
179 }
180  
181 128 ▶sub _parse_group {
Subroutine _parse_group: called CC=8 SCAR=22.4
182 128 my ($group, $close, $sub, @rest) = @_;
183 128 ▶ for (my ($len, $cnt) = length($_); $_ ne ''; $len = length($_), $cnt++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ ne "") 271 0 271
184 271 ▶ if (s/^ ([\)\]\}])//x) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^ ([\)\]\}])//x) 127 144 271
185 127 ▶ mydie "Paren mismatch: expect $close got $1 " if $1 ne $close;
Branch: 1 branch
BranchTrueFalseTotal
if $1 ne $close 0 127 127
186 127 last;
187 }
188 144 my @pipe = $sub->(@rest);
189 143 ▶ if ($cnt && $len == length($_)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cnt and $len == length $_) 0 143 143
Condition66%2/3
$cnt and $len == length $_
!ll&&!rl&&r
88550
MC/DC0%0/2
$cnt and $len == length $_
$cnt $len == length $_
Truth table66%2/3
A and B
A= $cntB= $len == length $_
ABresult
0X0
100
111
190 0 ▶ mydie "Can't match: $_" . (defined $close ? " for $close" : "");
Branch: 1 branch
BranchTrueFalseTotal
defined $close ? : 0 0 0
191 }
192 143 ▶ push @$group, @pipe <= 1 ? @pipe : \@pipe;
Branch: 1 branch
BranchTrueFalseTotal
@pipe <= 1 ? : 138 5 143
193 }
194 127 $group;
195 }
196  
197 20 ▶sub _parse_group_string {
Subroutine _parse_group_string: called CC=8 SCAR=20.8
198 20 my ($close) = @_;
199 20 my $result = '';
200 20 ▶ for (my ($len, $prev) = length($_); $_ ne ''
Branch: 1 branch
BranchTrueFalseTotal
if ($_ ne "") 47 0 47
201 ; $prev = $len, $len = length($_)) {
202 47 ▶ if (s/^ ([\)\]\}])//x) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^ ([\)\]\}])//x) 19 28 47
203 19 ▶ mydie "Paren mismatch: expect $close got $1 " if $1 ne $close;
Branch: 1 branch
BranchTrueFalseTotal
if $1 ne $close 0 19 19
204 19 $result .= $1;
205 19 last;
206 }
207 28 ▶ if (s/^($re_word | , )//x) {
Branch: 2 branches
BranchTrueFalseTotal
if (s/^($re_word | , )//x) { } 22 6 28
elsif (s/^([\(\[\{])//) { } 4 2 6
208 22 $result .= $1;
209 } elsif (s/^([\(\[\{])//) {
210 4 $result .= $1;
211 4 $result .= &_parse_group_string($close_ch{$1});
212 }
213 28 ▶ if (defined $prev and $prev == length($_)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prev and $prev == length $_) 1 27 28
Condition100%3/3
defined $prev and $prev == length $_
!ll&&!rl&&r
1981
MC/DC100%2/2
defined $prev and $prev == length $_
defined $prev $prev == length $_
Truth table100%3/3
A and B
A= defined $prevB= $prev == length $_
ABresult
0X0
100
111
214 1 mydie "Can't parse entity_path group $ORIG (near $_)\n"
215 }
216 }
217 19 $result;
218 }
219  
220 17 ▶sub _parse_hash {
Subroutine _parse_hash: called CC=10 SCAR=24.4
221 17 my @hash = ('hash');
222 17 ▶ for (my ($len, $cnt) = length($_); $_ ne ''; $len = length($_), $cnt++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ ne "") 42 0 42
223 42 ▶ if (s/^ ([\)\]\}])//x) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^ ([\)\]\}])//x) 17 25 42
224 17 ▶ mydie "Paren mismatch: expect \} got $1 " if $1 ne '}';
Branch: 1 branch
BranchTrueFalseTotal
if $1 ne "}" 0 17 17
225 17 last;
226 }
227 # {!=,:var} を許すには…
228 25 ▶ if (s/^([\w\.\-]+) [:=] //x || s/^($re_other+) ,?//x) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^([\w\.\-]+) [:=] //x or s/^($re_other+) ,?//x) 25 0 25
Condition66%2/3
s/^([\w\.\-]+) [:=] //x or s/^($re_other+) ,?//x
l!l&&r!l&&!r
1960
MC/DC0%0/2
s/^([\w\.\-]+) [:=] //x or s/^($re_other+) ,?//x
s/^([\w\.\-]+) [:=] //x s/^($re_other+) ,?//x
Truth table66%2/3
A or B
A= s/^([\w\.\-]+) [:=] //xB= s/^($re_other+) ,?//x
ABresult
1X1
011
000
229 # ↑ array でも許すべきか?
230 25 my $str = $1;
231 25 ▶ push @hash, [$str =~ s/^:// ? 'var' : 'text', $str];
Branch: 1 branch
BranchTrueFalseTotal
$str =~ s/^:// ? : 0 25 25
232 }
233 25 my @value = &_parse_term;
234 25 ▶ push @hash, @value > 1 ? \@value : $value[0];
Branch: 1 branch
BranchTrueFalseTotal
@value > 1 ? : 1 24 25
235 25 ▶ unless (length($_) < $len) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $_ < $len) 0 25 25
236 0 mydie "Infinite loop on parse_hash: $_";
237 }
238 }
239 # XXX: Give more detailed diag!
240 17 ▶ mydie "Odd number of hash elements" if (@hash - 1) % 2;
Branch: 1 branch
BranchTrueFalseTotal
if (@hash - 1) % 2 0 17 17
241 17 \@hash;
242 }
243  
244 4 1;
« blib/lib/YATT/Util/RLimit.pm ↑ Summary web/cgi-bin/yatt.lib/YATT/Fields.pm »