Data/Sah/Compiler/Prog.pm

filter: Statementstmt 88.7% 456 / 514 Branchbran 76.4% 185 / 242 Conditioncond 71.9% 82 / 114 MC/DCmcdc 42.1% 27 / 64 Subroutinesub 92.8% 26 / 28 Podpod 36.8% 7 / 19 totaltotal 79.8% 783 / 981 CC 183 SCAR 36.7
CC
183
Cov
83%
before_all_clauses
82.5
check_compile_args
33.1
__ANON__
28.6
CRAP 39.2
« Data/Sah/Util/Type/Date.pm ↑ Summary Test/Data/Sah.pm »
1 package Data::Sah::Compiler::Prog;
2  
3 24 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 24 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 24 ▶use Mo qw(build default);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 24 extends 'Data::Sah::Compiler';
10  
11 #use Digest::MD5 qw(md5_hex);
12  
13 # human compiler, to produce error messages
14 24 has hc => (is => 'rw');
15  
16 # subclass should provide a default, choices: 'shell', 'c', 'ini', 'cpp'
17 24 has comment_style => (is => 'rw');
18  
19 24 has var_sigil => (is => 'rw');
20  
21 24 has concat_op => (is => 'rw');
22  
23 4697 ▶has logical_and_op => (is => 'rw', default => sub {'&&'});
Subroutine __ANON__: called CC=1 SCAR=0.0
24  
25 4697 ▶has logical_not_op => (is => 'rw', default => sub {'!'});
Subroutine __ANON__: called CC=1 SCAR=0.0
26  
27 #has logical_or_op => (is => 'rw', default => sub {'||'});
28  
29 24 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
30 24 our $DATE = '2024-02-16'; # DATE
31 24 our $DIST = 'Data-Sah'; # DIST
32 24 our $VERSION = '0.917'; # VERSION
33  
34 5060 ▶sub init_cd {
Subroutine init_cd: called CC=4 SCAR=13.9
Pod undocumented
35 5060 my ($self, %args) = @_;
36  
37 5060 my $cd = $self->SUPER::init_cd(%args);
38 5060 $cd->{vars} = {};
39  
40 5060 my $hc = $self->hc;
41 5060 ▶ if (!$hc) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($hc) 4725 335 5060
42 4725 $hc = $self->main->get_compiler("human");
43 4725 $self->hc($hc);
44 }
45  
46 5060 ▶ if (my $ocd = $cd->{outer_cd}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ocd = $cd->{'outer_cd'}) { } 330 4730 5060
47 330 $cd->{vars} = $ocd->{vars};
48 330 $cd->{modules} = $ocd->{modules};
49 330 $cd->{functions} = $ocd->{functions};
50 330 $cd->{_hc} = $ocd->{_hc};
51 330 $cd->{_hcd} = $ocd->{_hcd};
52 330 $cd->{_subdata_level} = $ocd->{_subdata_level};
53 330 ▶ $cd->{use_dpath} = 1 if $ocd->{use_dpath};
Branch: 1 branch
BranchTrueFalseTotal
if $ocd->{"use_dpath"} 209 121 330
54 } else {
55 4730 $cd->{vars} = {};
56 4730 $cd->{modules} = [];
57 4730 $cd->{functions} = {};
58 4730 $cd->{_hc} = $hc;
59 4730 $cd->{_subdata_level} = 0;
60 }
61  
62 5060 $cd;
63 }
64  
65 9784 ▶sub check_compile_args {
Subroutine check_compile_args: called CC=21 SCAR=35.0
Pod undocumented
66 9784 my ($self, $args) = @_;
67  
68 9784 ▶ return if $args->{_args_checked_Prog}++;
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"_args_checked_Prog"}++ 5054 4730 9784
69  
70 4730 $self->SUPER::check_compile_args($args);
71  
72 4730 ▶ my $ct = ($args->{code_type} //= 'validator');
Condition50%1/2
$args->{"code_type"} //= "validator"
l!l
04730
MC/DC0%0/1
$args->{"code_type"} //= "validator"
$args->{"code_type"}
Truth table50%1/2
A
A= $args->{"code_type"}
Aresult
11
00
73 4730 ▶ if ($ct ne 'validator') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ct ne "validator") 0 4730 4730
74 0 $self->_die({}, "code_type currently can only be 'validator'");
75 }
76 4730 for ($args->{return_type}) {
77 4730 ▶ $_ //= 'bool_valid';
Condition100%2/2
$_ //= "bool_valid"
l!l
29431787
MC/DC100%1/1
$_ //= "bool_valid"
$_
Truth table100%2/2
A
A= $_
Aresult
11
00
78 # old values that are still supported but now deprecated
79 4730 ▶ $_ = "bool_valid" if $_ eq 'bool';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "bool" 0 4730 4730
80 4730 ▶ $_ = "bool_valid+val" if $_ eq 'bool+val';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "bool+val" 0 4730 4730
81 4730 ▶ $_ = "str_errmsg" if $_ eq 'str';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "str" 0 4730 4730
82 4730 ▶ $_ = "str_errmsg+val" if $_ eq 'str+val';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "str+val" 0 4730 4730
83 4730 ▶ $_ = "hash_details" if $_ eq 'full';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "full" 0 4730 4730
84 }
85 4730 my $rt = $args->{return_type};
86 4730 ▶ if ($rt !~ /\A(bool_valid\+val|bool_valid|str_errmsg\+val|str_errmsg|hash_details)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rt =~ /\A(bool_valid\+val|bool_valid|str_errmsg\+val|str_errmsg|hash_details)\z/) 0 4730 4730
87 0 $self->_die({}, "Invalid value for return_type, ".
88 "use bool_valid+val|bool_valid|str_errmsg+val|str_errmsg|hash_details");
89 }
90 4730 ▶ $args->{var_prefix} //= "_sahv_";
Condition50%1/2
$args->{"var_prefix"} //= "_sahv_"
l!l
04730
MC/DC0%0/1
$args->{"var_prefix"} //= "_sahv_"
$args->{"var_prefix"}
Truth table50%1/2
A
A= $args->{"var_prefix"}
Aresult
11
00
91 4730 ▶ $args->{sub_prefix} //= "_sahs_";
Condition50%1/2
$args->{"sub_prefix"} //= "_sahs_"
l!l
04730
MC/DC0%0/1
$args->{"sub_prefix"} //= "_sahs_"
$args->{"sub_prefix"}
Truth table50%1/2
A
A= $args->{"sub_prefix"}
Aresult
11
00
92 4730 ▶ $args->{data_term} //= $self->var_sigil . $args->{data_name};
Condition50%1/2
$args->{"data_term"} //= $self->var_sigil . $args->{"data_name"}
l!l
04730
MC/DC0%0/1
$args->{"data_term"} //= $self->var_sigil . $args->{"data_name"}
$args->{"data_term"}
Truth table50%1/2
A
A= $args->{"data_term"}
Aresult
11
00
93 4730 ▶ $args->{data_term_is_lvalue} //= 1;
Condition50%1/2
$args->{"data_term_is_lvalue"} //= 1
l!l
04730
MC/DC0%0/1
$args->{"data_term_is_lvalue"} //= 1
$args->{"data_term_is_lvalue"}
Truth table50%1/2
A
A= $args->{"data_term_is_lvalue"}
Aresult
11
00
94 4730 ▶ $args->{tmp_data_name} //= "tmp_$args->{data_name}";
Condition50%1/2
$args->{"tmp_data_name"} //= qq[tmp_$args->{"data_name"}]
l!l
04730
MC/DC0%0/1
$args->{"tmp_data_name"} //= qq[tmp_$args->{"data_name"}]
$args->{"tmp_data_name"}
Truth table50%1/2
A
A= $args->{"tmp_data_name"}
Aresult
11
00
95 4730 ▶ $args->{tmp_data_term} //= $self->var_sigil . $args->{tmp_data_name};
Condition50%1/2
$args->{"tmp_data_term"} //= $self->var_sigil . $args->{"tmp_data_name"}
l!l
04730
MC/DC0%0/1
$args->{"tmp_data_term"} //= $self->var_sigil . $args->{"tmp_data_name"}
$args->{"tmp_data_term"}
Truth table50%1/2
A
A= $args->{"tmp_data_term"}
Aresult
11
00
96 4730 ▶ $args->{comment} //= 1;
Condition50%1/2
$args->{"comment"} //= 1
l!l
04730
MC/DC0%0/1
$args->{"comment"} //= 1
$args->{"comment"}
Truth table50%1/2
A
A= $args->{"comment"}
Aresult
11
00
97 4730 ▶ $args->{err_term} //= $self->var_sigil . "err_$args->{data_name}";
Condition50%1/2
$args->{"err_term"} //= $self->var_sigil . qq[err_$args->{"data_name"}]
l!l
04730
MC/DC0%0/1
$args->{"err_term"} //= $self->var_sigil . qq[err_$args->{"data_name"}]
$args->{"err_term"}
Truth table50%1/2
A
A= $args->{"err_term"}
Aresult
11
00
98 4730 ▶ $args->{coerce} //= 1;
Condition50%1/2
$args->{"coerce"} //= 1
l!l
04730
MC/DC0%0/1
$args->{"coerce"} //= 1
$args->{"coerce"}
Truth table50%1/2
A
A= $args->{"coerce"}
Aresult
11
00
99 }
100  
101 17105 ▶sub comment {
Subroutine comment: called CC=7 SCAR=29.4
Pod documented
102 17105 my ($self, $cd, @args) = @_;
103 17105 ▶ return '' unless $cd->{args}{comment};
Branch: 1 branch
BranchTrueFalseTotal
unless $cd->{"args"}{"comment"} 0 17105 17105
104  
105 17105 my $content = join("", @args);
106 17105 $content =~ s/\n+/ /g;
107  
108 17105 my $style = $self->comment_style;
109 17105 ▶ if ($style eq 'shell') {
Branch: 5 branches
BranchTrueFalseTotal
if ($style eq 'shell') { } 17105 0 17105
elsif ($style eq 'shell2') { } 0 0 0
elsif ($style eq 'cpp') { } 0 0 0
elsif ($style eq 'c') { } 0 0 0
elsif ($style eq 'ini') { } 0 0 0
110 17105 return join("", "# ", $content, "\n");
111 } elsif ($style eq 'shell2') {
112 0 return join("", "## ", $content, "\n");
113 } elsif ($style eq 'cpp') {
114 0 return join("", "// ", $content, "\n");
115 } elsif ($style eq 'c') {
116 0 return join("", "/* ", $content, '*/');
117 } elsif ($style eq 'ini') {
118 0 return join("", "; ", $content, "\n");
119 } else {
120 0 $self->_die($cd, "BUG: Unknown comment style: $style");
121 }
122 }
123  
124 # enclose expression with parentheses, unless it already is
125 55497 ▶sub enclose_paren {
Subroutine enclose_paren: called CC=3 SCAR=11.0
Pod undocumented
126 55497 my ($self, $expr, $force) = @_;
127 55497 ▶ if ($expr =~ /\A(\s*)(\(.+\)\s*)\z/os) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expr =~ /\A(\s*)(\(.+\)\s*)\z/so) { } 30047 25450 55497
128 30047 ▶ return $expr if !$force;
Branch: 1 branch
BranchTrueFalseTotal
unless $force 23442 6605 30047
129 6605 return "$1($2)";
130 } else {
131 25450 $expr =~ /\A(\s*)(.*)/os;
132 25450 return "$1($2)";
133 }
134 }
135  
136 13479 ▶sub add_var {
Subroutine add_var: called CC=2 SCAR=6.9
Pod undocumented
137 13479 my ($self, $cd, $name, $value) = @_;
138  
139 13479 ▶ return if exists $cd->{vars}{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $cd->{"vars"}{$name} 8437 5042 13479
140 #$log->tracef("TMP: add_var %s", $name);
141 5042 $cd->{vars}{$name} = $value;
142 }
143  
144 # naming convention: expr_NOUN(), stmt_VERB(_NOUN)?()
145  
146 # XXX requires: expr_list
147  
148 # XXX requires: expr_defined
149  
150 # XXX requires: expr_array
151  
152 # XXX requires: expr_array_subscript
153  
154 # XXX requires: expr_last_elem
155  
156 # XXX requires: expr_push
157  
158 # XXX requires: expr_pop
159  
160 # XXX requires: expr_push_and_pop_dpath_between_expr
161  
162 # XXX requires: expr_prefix_dpath
163  
164 # XXX requires: expr_set
165  
166 # XXX requires: expr_setif
167  
168 # XXX requires: expr_set_err_str
169  
170 # XXX requires: expr_set_err_full
171  
172 # XXX requires: expr_reset_err_str
173  
174 # XXX requires: expr_reset_err_full
175  
176 # XXX requires: expr_ternary
177  
178 # XXX requires: expr_log
179  
180 # XXX requires: expr_block
181  
182 # XXX requires: expr_anon_sub
183  
184 # XXX requires: expr_eval
185  
186 # XXX requires: expr_refer_or_call_sub
187  
188 # TODO XXX requires: expr_declare_lexical_var
189  
190 # XXX requires: stmt_declare_local_var
191  
192 # XXX requires: stmt_require_module
193  
194 # XXX requires: stmt_require_log_module
195  
196 # XXX requires: stmt_assign_hash_value
197  
198 # XXX requires: stmt_sub
199  
200 # XXX requires: stmt_return
201  
202 # XXX requires: sub_defined
203  
204 # XXX requires: gen_cached_validator
205  
206 19465 ▶sub _xlt {
Subroutine _xlt: called CC=1 SCAR=0.0
207 19465 my ($self, $cd, $text) = @_;
208  
209 19465 my $hc = $cd->{_hc};
210 19465 my $hcd = $cd->{_hcd};
211 #$log->tracef("(Prog) Translating text %s ...", $text);
212 19465 $hc->_xlt($hcd, $text);
213 }
214  
215 # concatenate strings
216 0 ▶sub expr_concat {
Subroutine expr_concat: not called CC=1 SCAR=6.9
Pod undocumented
217 0 my ($self, @t) = @_;
218 0 join(" " . $self->concat_op . " ", @t);
219 }
220  
221 # variable
222 607 ▶sub expr_var {
Subroutine expr_var: called CC=1 SCAR=0.0
Pod undocumented
223 607 my ($self, $v) = @_;
224 607 $self->var_sigil. $v;
225 }
226  
227 0 ▶sub expr_preinc {
Subroutine expr_preinc: not called CC=1 SCAR=6.9
Pod undocumented
228 0 my ($self, $t) = @_;
229 0 "++$t";
230 }
231  
232 2428 ▶sub expr_preinc_var {
Subroutine expr_preinc_var: called CC=1 SCAR=0.0
Pod undocumented
233 2428 my ($self, $v) = @_;
234 2428 "++" . $self->var_sigil. $v;
235 }
236  
237 # expr_postinc
238 # expr_predec
239 # expr_postdec
240  
241 # args: log_result, var_term, err_term. the rest is the same/supplied to
242 # compile().
243 4724 ▶sub expr_validator_sub {
Subroutine expr_validator_sub: called CC=14 SCAR=28.9
Pod undocumented
244 4724 my ($self, %args) = @_;
245  
246 4724 my $cache = $args{cache};
247 4724 my $log_result = $args{log_result};
248 4724 my $dt = $args{data_term};
249 4724 ▶ my $vt = delete($args{var_term}) // $dt;
Condition33%1/3
delete $args{"var_term"} // $dt
l!l&&r!l&&!r
472400
MC/DC0%0/2
delete $args{"var_term"} // $dt
delete $args{"var_term"} $dt
Truth table33%1/3
A // B
A= delete $args{"var_term"}B= $dt
ABresult
1X1
011
000
250 4724 ▶ my $do_log = $args{debug_log} // $args{debug};
Condition33%1/3
$args{"debug_log"} // $args{"debug"}
l!l&&r!l&&!r
004724
MC/DC0%0/2
$args{"debug_log"} // $args{"debug"}
$args{"debug_log"} $args{"debug"}
Truth table33%1/3
A // B
A= $args{"debug_log"}B= $args{"debug"}
ABresult
1X1
011
000
251 4724 ▶ my $rt = $args{return_type} // 'bool_valid';
Condition50%1/2
$args{"return_type"} // "bool_valid"
l!l
47240
MC/DC0%0/1
$args{"return_type"} // "bool_valid"
$args{"return_type"}
Truth table50%1/2
A
A= $args{"return_type"}
Aresult
11
00
252  
253 4724 $args{indent_level} = 1;
254 4724 ▶ if ($cache) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache) 0 4724 4724
255 # ...
256 }
257 4724 ▶ my $cd = $args{cd} // $self->compile(%args);
Condition33%1/3
$args{"cd"} // $self->compile(%args)
l!l&&r!l&&!r
047240
MC/DC0%0/2
$args{"cd"} // $self->compile(%args)
$args{"cd"} $self->compile(%args)
Truth table33%1/3
A // B
A= $args{"cd"}B= $self->compile(%args)
ABresult
1X1
011
000
258 4691 my $et = $cd->{args}{err_term};
259  
260 4691 ▶ if ($rt !~ /\Abool/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rt =~ /\Abool/) 2943 1748 4691
261 2943 my ($ev) = $et =~ /(\w+)/; # to remove sigil
262 2943 ▶ $self->add_var($cd, $ev, $rt =~ /\Astr/ ? undef : {});
Branch: 1 branch
BranchTrueFalseTotal
$rt =~ /\Astr/ ? : 1473 1470 2943
263 }
264 4691 my $resv = '_sahv_res';
265 4691 my $rest = $self->var_sigil . $resv;
266  
267 4691 ▶ my $needs_expr_block = (grep {$_->{phase} eq 'runtime'} @{ $cd->{modules} })
Condition66%2/3
grep({$_->{'phase'} eq 'runtime';} @{$$cd{'modules'};}) || $do_log
l!l&&r!l&&!r
4651040
MC/DC50%1/2
grep({$_->{'phase'} eq 'runtime';} @{$$cd{'modules'};}) || $do_log
grep({$_->{'phase'} eq 'runtime';} @{$$cd{'modules'};}) $do_log
Truth table66%2/3
A || B
A= grep({$_->{'phase'} eq 'runtime';} @{$$cd{'modules'};})B= $do_log
ABresult
1X1
011
000
268 || $do_log;
269  
270 my $code_sub_body = join(
271 "",
272 (map {$self->stmt_declare_local_var(
273 5038 $_, $self->literal($cd->{vars}{$_}))."\n"}
274 4691 sort keys %{ $cd->{vars} }),
275 #$log->tracef('-> (validator)(%s) ...', $dt);\n";
276 4691 $self->stmt_declare_local_var($resv, "\n\n" . $cd->{result})."\n\n",
277  
278 # when rt=bool_valid, return true/false result
279 #(";\n\n\$log->tracef('<- validator() = %s', \$res)")
280 # x !!($do_log && $rt eq 'bool_valid'),
281 ($self->stmt_return($rest)."\n")
282 x !!($rt eq 'bool_valid'),
283  
284 # when rt=str_errmsg, return string error message
285 #($log->tracef('<- validator() = %s', ".
286 # "\$err_data);\n\n";
287 # x !!($do_log && $rt eq 'str_errmsg'),
288 ($self->expr_set_err_str($et, $self->literal('')).";",
289 "\n\n".$self->stmt_return($et)."\n")
290 x !!($rt eq 'str_errmsg'),
291  
292 # when rt=bool_valid+val, return true/false result as well as
293 # final input value
294 ($self->stmt_return($self->expr_array($rest, $dt))."\n")
295 x !!($rt eq 'bool_valid+val'),
296  
297 # when rt=str_errmsg+val, return string error message as well as
298 # final input value
299 ($self->expr_set_err_str($et, $self->literal('')).";",
300 "\n\n".$self->stmt_return($self->expr_array($et, $dt))."\n")
301 x !!($rt eq 'str_errmsg+val'),
302  
303 # when rt=hash_details, return error hash
304 ($self->stmt_assign_hash_value($et, $self->literal('value'), $dt),
305 "\n".$self->stmt_return($et)."\n")
306 x !!($rt eq 'hash_details'),
307 );
308  
309 my $code = join(
310 "",
311 ($self->stmt_require_log_module."\n") x !!$do_log,
312 7185 (map { $self->stmt_require_module($_)."\n" }
313 4691 grep { $_->{phase} eq 'runtime' } @{ $cd->{modules} }),
314 $self->expr_anon_sub([$vt], $code_sub_body),
315 );
316  
317 4691 ▶ if ($needs_expr_block) {
Branch: 1 branch
BranchTrueFalseTotal
if ($needs_expr_block) 4651 40 4691
318 4651 $code = $self->expr_block($code);
319 }
320  
321 4691 ▶ if ($log_result && log_is_trace()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($log_result and log_is_trace()) 0 4691 4691
Condition33%1/3
$log_result and log_is_trace()
!ll&&!rl&&r
469100
MC/DC0%0/2
$log_result and log_is_trace()
$log_result log_is_trace()
Truth table33%1/3
A and B
A= $log_resultB= log_is_trace()
ABresult
0X0
100
111
322 log_trace("validator code:\n%s",
323 0 ▶ ($ENV{LINENUM} // 1) ?
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'LINENUM'} // 1 ? : 0 0 0
Condition0%0/2
$ENV{"LINENUM"} // 1
l!l
00
MC/DC0%0/1
$ENV{"LINENUM"} // 1
$ENV{"LINENUM"}
Truth table0%0/2
A
A= $ENV{"LINENUM"}
Aresult
11
00
324 Data::Sah::Compiler::__linenum($code) :
325 $code);
326 }
327  
328 4691 $code;
329 }
330  
331 # add compiled clause to ccls, along with extra information useful for joining
332 # later (like error level, code for adding error message, etc). available
333 # options:
334 #
335 # - err_level (str, the default will be taken from current clause's .err_level
336 # if not specified),
337 #
338 # - err_expr (str, a string expression in the target language that evaluates to
339 # an error message, the more general and dynamic alternative to err_msg.
340 #
341 # - err_msg (str, the default will be produced by human compiler if not
342 # supplied, or taken from current clause's .err_msg),
343 #
344 # - subdata (bool, default false, if set to true then this means we are
345 # delving into subdata, e.g. array elements or hash pair values, and appropriate
346 # things must be done to adjust for this [e.g. push_dpath/pop_dpath at the end
347 # so that error message can show the proper data path].
348 #
349 # - assert (bool, default false, if set to true means this ccl is an assert ccl,
350 # meaning it always returns true and is not translated from an actual clause. it
351 # will not affect number of errors nor produce error messages.)
352 18651 ▶sub add_ccl {
Subroutine add_ccl: called CC=26 SCAR=32.6
Pod undocumented
353 18651 my ($self, $cd, $ccl, $opts) = @_;
354 18651 ▶ $opts //= {};
Condition100%2/2
$opts //= {}
l!l
130425609
MC/DC100%1/1
$opts //= {}
$opts
Truth table100%2/2
A
A= $opts
Aresult
11
00
355 18651 ▶ my $clause = $cd->{clause} // "";
Condition100%2/2
$cd->{"clause"} // ""
l!l
613412517
MC/DC100%1/1
$cd->{"clause"} // ""
$cd->{"clause"}
Truth table100%2/2
A
A= $cd->{"clause"}
Aresult
11
00
356 18651 ▶ my $op = $cd->{cl_op} // "";
Condition100%2/2
$cd->{"cl_op"} // ""
l!l
385214799
MC/DC100%1/1
$cd->{"cl_op"} // ""
$cd->{"cl_op"}
Truth table100%2/2
A
A= $cd->{"cl_op"}
Aresult
11
00
357 #$log->errorf("TMP: adding ccl %s, current ccls=%s", $ccl, $cd->{ccls});
358  
359 18651 ▶ my $el = $opts->{err_level} // $cd->{clset}{"$clause.err_level"} // "error";
Condition100%5/5
($opts->{"err_level"} // $cd->{"clset"}{"$clause.err_level"}) // "error"
l!l
683411817
$opts->{"err_level"} // $cd->{"clset"}{"$clause.err_level"}
l!l&&r!l&&!r
67805411817
MC/DC100%2/2
($opts->{"err_level"} // $cd->{"clset"}{"$clause.err_level"}) // "error"
$opts->{"err_level"} $cd->{"clset"}{"$clause.err_level"}
Truth table100%3/3
A // B
A= $opts->{"err_level"}B= $cd->{"clset"}{"$clause.err_level"}
ABresult
1X1
011
000
360 18651 my $err_expr = $opts->{err_expr};
361 18651 my $err_msg = $opts->{err_msg};
362  
363 18651 ▶ if (defined $err_expr) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $err_expr) { } 133 18518 18651
364 133 ▶ $self->add_var($cd, '_sahv_dpath', []) if $cd->{use_dpath};
Branch: 1 branch
BranchTrueFalseTotal
if $cd->{"use_dpath"} 62 71 133
365 133 ▶ $err_expr = $self->expr_prefix_dpath($err_expr) if $cd->{use_dpath};
Branch: 1 branch
BranchTrueFalseTotal
if $cd->{"use_dpath"} 62 71 133
366 } else {
367 18518 ▶ unless (defined $err_msg) { $err_msg = $cd->{clset}{"$clause.err_msg"} }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $err_msg) 6037 12481 18518
368 18518 ▶ unless (defined $err_msg) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $err_msg) 6037 12481 18518
369 # XXX how to invert on op='none' or op='not'?
370  
371 6037 my @msgpath = @{$cd->{spath}};
372 6037 my $msgpath;
373 6037 my $hc = $cd->{_hc};
374 6037 my $hcd = $cd->{_hcd};
375 6037 while (1) {
376 # search error message, use more general one if the more
377 # specific one is not available
378 8518 ▶ last unless @msgpath;
Branch: 1 branch
BranchTrueFalseTotal
unless @msgpath 282 8236 8518
379 8236 $msgpath = join("/", @msgpath);
380 8236 my $ccls = $hcd->{result}{$msgpath};
381 8236 pop @msgpath;
382 8236 ▶ if ($ccls) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ccls) 5755 2481 8236
383 5755 local $hcd->{args}{format} = 'inline_err_text';
384 5755 $err_msg = $hc->format_ccls($hcd, $ccls);
385 # show path when debugging
386 $err_msg = "(msgpath=$msgpath) $err_msg"
387 5755 ▶ if $cd->{args}{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $cd->{"args"}{"debug"} 0 5755 5755
388 5755 last;
389 }
390 }
391 6037 ▶ if (!$err_msg) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $err_msg) { } 282 5755 6037
392 282 ▶ $err_msg = "ERR (clause=".($cd->{clause} // "").")";
Condition100%2/2
$cd->{"clause"} // ""
l!l
22854
MC/DC100%1/1
$cd->{"clause"} // ""
$cd->{"clause"}
Truth table100%2/2
A
A= $cd->{"clause"}
Aresult
11
00
393 } else {
394 5755 $err_msg = ucfirst($err_msg);
395 }
396 }
397 18518 ▶ if ($err_msg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err_msg) 11591 6927 18518
398 11591 ▶ $self->add_var($cd, '_sahv_dpath', []) if $cd->{use_dpath};
Branch: 1 branch
BranchTrueFalseTotal
if $cd->{"use_dpath"} 4033 7558 11591
399 11591 $err_expr = $self->literal($err_msg);
400 11591 ▶ $err_expr = $self->expr_prefix_dpath($err_expr) if $cd->{use_dpath};
Branch: 1 branch
BranchTrueFalseTotal
if $cd->{"use_dpath"} 4033 7558 11591
401 }
402 }
403  
404 18651 my $rt = $cd->{args}{return_type};
405 18651 my $et = $cd->{args}{err_term};
406 18651 my $err_code;
407 18651 ▶ if ($rt eq 'hash_details') {
Branch: 2 branches
BranchTrueFalseTotal
if ($rt eq 'hash_details') { } 5844 12807 18651
elsif ($rt =~ /\Astr/) { } 5869 6938 12807
408 5844 ▶ $self->add_var($cd, '_sahv_dpath', []) if $cd->{use_dpath};
Branch: 1 branch
BranchTrueFalseTotal
if $cd->{"use_dpath"} 5844 0 5844
409 5844 ▶ my $k = $el eq 'warn' ? 'warnings' : 'errors';
Branch: 1 branch
BranchTrueFalseTotal
$el eq 'warn' ? : 18 5826 5844
410 5844 ▶ $err_code = $self->expr_set_err_full($et, $k, $err_expr) if $err_expr;
Branch: 1 branch
BranchTrueFalseTotal
if $err_expr 3710 2134 5844
411 } elsif ($rt =~ /\Astr/) {
412 5869 ▶ if ($el ne 'warn') {
Branch: 1 branch
BranchTrueFalseTotal
if ($el ne "warn") 5851 18 5869
413 5851 ▶ $err_code = $self->expr_set_err_str($et, $err_expr) if $err_expr;
Branch: 1 branch
BranchTrueFalseTotal
if $err_expr 3703 2148 5851
414 }
415 }
416  
417 my $res = {
418 ccl => $ccl,
419 err_level => $el,
420 err_code => $err_code,
421 (_debug_ccl_note => $cd->{_debug_ccl_note}) x !!$cd->{_debug_ccl_note},
422 subdata => $opts->{subdata},
423 18651 };
424 18651 push @{ $cd->{ccls} }, $res;
425 18651 delete $cd->{uclset}{"$clause.err_level"};
426 18651 delete $cd->{uclset}{"$clause.err_msg"};
427 }
428  
429 # join ccls to handle .op and insert error messages. opts = op
430 13822 ▶sub join_ccls {
Subroutine join_ccls: called CC=13 SCAR=25.8
Pod undocumented
431 13822 my ($self, $cd, $ccls, $opts) = @_;
432 13822 ▶ $opts //= {};
Condition100%2/2
$opts //= {}
l!l
92684554
MC/DC100%1/1
$opts //= {}
$opts
Truth table100%2/2
A
A= $opts
Aresult
11
00
433 13822 ▶ my $op = $opts->{op} // "and";
Condition100%2/2
$opts->{"op"} // "and"
l!l
179712025
MC/DC100%1/1
$opts->{"op"} // "and"
$opts->{"op"}
Truth table100%2/2
A
A= $opts->{"op"}
Aresult
11
00
434 #$log->errorf("TMP: joining ccl %s", $ccls);
435 #warn "join_ccls"; #TMP
436  
437 13822 my ($min_ok, $max_ok, $min_nok, $max_nok);
438 13822 ▶ if ($op eq 'and') {
Branch: 4 branches
BranchTrueFalseTotal
if ($op eq 'and') { } 12623 1199 13822
elsif ($op eq 'or') { } 607 592 1199
elsif ($op eq 'none') { } 288 304 592
elsif ($op eq 'not') { } 304 0 304
439 12623 $max_nok = 0;
440 } elsif ($op eq 'or') {
441 607 $min_ok = 1;
442 } elsif ($op eq 'none') {
443 288 $max_ok = 0;
444 } elsif ($op eq 'not') {
445  
446 }
447 13822 my $dmin_ok = defined($min_ok);
448 13822 my $dmax_ok = defined($max_ok);
449 13822 my $dmin_nok = defined($min_nok);
450 13822 my $dmax_nok = defined($max_nok);
451  
452 13822 ▶ return "" unless @$ccls;
Branch: 1 branch
BranchTrueFalseTotal
unless @$ccls 54 13768 13822
453  
454 13768 my $rt = $cd->{args}{return_type};
455 13768 my $vp = $cd->{args}{var_prefix};
456  
457 13768 my $aop = $self->logical_and_op;
458 13768 my $nop = $self->logical_not_op;
459  
460 13768 my $true = $self->true;
461  
462 # insert comment, error message, and $ok/$nok counting. $which is 0 by
463 # default (normal), or 1 (reverse logic, for 'not' or 'none'), or 2 (for
464 # $ok/$nok counting), or 3 (like 2, but for the last clause).
465 22751 ▶ my $_ice = sub {
Subroutine __ANON__: called CC=26 SCAR=33.5
466 22751 my ($ccl, $which) = @_;
467  
468 22751 ▶ return $self->enclose_paren($ccl->{ccl}) if $ccl->{assert};
Branch: 1 branch
BranchTrueFalseTotal
if $ccl->{"assert"} 0 22751 22751
469  
470 22751 my $res = "";
471  
472 22751 ▶ if ($ccl->{_debug_ccl_note}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ccl->{"_debug_ccl_note"}) 17105 5646 22751
473 17105 ▶ if ($cd->{args}{debug_log} // $cd->{args}{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cd->{'args'}{'debug_log'} // $cd->{'args'}{'debug'}) { } 0 17105 17105
Condition33%1/3
$cd->{"args"}{"debug_log"} // $cd->{"args"}{"debug"}
l!l&&r!l&&!r
0017105
MC/DC0%0/2
$cd->{"args"}{"debug_log"} // $cd->{"args"}{"debug"}
$cd->{"args"}{"debug_log"} $cd->{"args"}{"debug"}
Truth table33%1/3
A // B
A= $cd->{"args"}{"debug_log"}B= $cd->{"args"}{"debug"}
ABresult
1X1
011
000
474 $res .= $self->expr_log(
475 0 $cd, $self->literal($ccl->{_debug_ccl_note})) . " $aop\n";
476 } else {
477 17105 $res .= $self->comment($cd, $ccl->{_debug_ccl_note});
478 }
479 }
480  
481 22751 ▶ $which //= 0;
Condition100%2/2
$which //= 0
l!l
209420657
MC/DC100%1/1
$which //= 0
$which
Truth table100%2/2
A
A= $which
Aresult
11
00
482 # clause code
483 22751 ▶ my $cc = ($which == 1 ? $nop:"") . $self->enclose_paren($ccl->{ccl});
Branch: 1 branch
BranchTrueFalseTotal
$which == 1 ? : 880 21871 22751
484 22751 my ($ec, $oec);
485 22751 my ($ret, $oret);
486 22751 ▶ if ($which >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($which >= 2) { } 1214 21537 22751
487 1214 my @chk;
488 1214 ▶ if ($ccl->{err_level} eq 'warn') {
Branch: 2 branches
BranchTrueFalseTotal
if ($ccl->{'err_level'} eq 'warn') { } 0 1214 1214
elsif ($ccl->{'err_level'} eq 'fatal') { } 0 1214 1214
489 0 $oret = 1;
490 0 $ret = 1;
491 } elsif ($ccl->{err_level} eq 'fatal') {
492 0 $oret = 1;
493 0 $ret = 0;
494 } else {
495 1214 $oret = $self->expr_preinc_var("${vp}ok");
496 1214 $ret = $self->expr_preinc_var("${vp}nok");
497 1214 ▶ push @chk, $self->expr_var("${vp}ok"). " <= $max_ok"
Branch: 1 branch
BranchTrueFalseTotal
if $dmax_ok 0 1214 1214
498 if $dmax_ok;
499 1214 ▶ push @chk, $self->expr_var("${vp}nok")." <= $max_nok"
Branch: 1 branch
BranchTrueFalseTotal
if $dmax_nok 0 1214 1214
500 if $dmax_nok;
501 1214 ▶ if ($which == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($which == 3) 607 607 1214
502 607 ▶ push @chk, $self->expr_var("${vp}ok"). " >= $min_ok"
Branch: 1 branch
BranchTrueFalseTotal
if $dmin_ok 607 0 607
503 if $dmin_ok;
504 607 ▶ push @chk, $self->expr_var("${vp}nok")." >= $min_nok"
Branch: 1 branch
BranchTrueFalseTotal
if $dmin_nok 0 607 607
505 if $dmin_nok;
506  
507 # we need to clear the error message previously set
508 607 ▶ if ($rt !~ /\Abool/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rt =~ /\Abool/) 404 203 607
509 404 my $et = $cd->{args}{err_term};
510 404 my $clerrc;
511 404 ▶ if ($rt eq 'hash_details') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rt eq 'hash_details') { } 202 202 404
512 202 $clerrc = $self->expr_reset_err_full($et);
513 } else {
514 202 $clerrc = $self->expr_reset_err_str($et);
515 }
516 404 push @chk, $clerrc;
517 }
518 }
519 }
520 1214 $res .= "($cc ? $oret : $ret)";
521 1214 ▶ $res .= " $aop " . join(" $aop ", @chk) if @chk;
Branch: 1 branch
BranchTrueFalseTotal
if @chk 607 607 1214
522 } else {
523 21537 $ec = $ccl->{err_code};
524 $ret =
525 $ccl->{err_level} eq 'fatal' ? 0 :
526 # this must not be done because it messes up ok/nok counting
527 #$rt eq 'hash_details' ? 1 :
528 21537 ▶ $ccl->{err_level} eq 'warn' ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
$ccl->{'err_level'} eq 'fatal' ? : 6716 14821 21537
$ccl->{'err_level'} eq 'warn' ? : 108 14713 14821
529 21537 ▶ if ($rt =~ /\Abool/ && $ret) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rt =~ /\Abool/ and $ret) { } 36 21501 21537
elsif ($rt =~ /\Abool/ or not $ec) { } 14896 6605 21501
Condition100%3/3
$rt =~ /\Abool/ and $ret
!ll&&!rl&&r
13570793136
MC/DC100%2/2
$rt =~ /\Abool/ and $ret
$rt =~ /\Abool/ $ret
Truth table100%3/3
A and B
A= $rt =~ /\Abool/B= $ret
ABresult
0X0
100
111
530 36 $res .= $true;
531 ▶ } elsif ($rt =~ /\Abool/ || !$ec) {
Condition100%3/3
$rt =~ /\Abool/ or not $ec
l!l&&r!l&&!r
793169656605
MC/DC100%2/2
$rt =~ /\Abool/ or not $ec
$rt =~ /\Abool/ not $ec
Truth table100%3/3
A or not(B)
A= $rt =~ /\Abool/B= not $ec
ABresult
1X1
011
000
532 14896 $res .= $self->enclose_paren($cc);
533 } else {
534 6605 $res .= $self->enclose_paren(
535 $self->enclose_paren($cc). " ? $true : ($ec,$ret)",
536 "force");
537 }
538 }
539  
540 # insert dpath handling
541 $res = $self->expr_push_and_pop_dpath_between_expr($res)
542 22751 ▶ if $cd->{use_dpath} && $ccl->{subdata};
Branch: 1 branch
BranchTrueFalseTotal
if $cd->{"use_dpath"} and $ccl->{"subdata"} 86 22665 22751
Condition100%3/3
$cd->{"use_dpath"} and $ccl->{"subdata"}
!ll&&!rl&&r
14877778886
MC/DC100%2/2
$cd->{"use_dpath"} and $ccl->{"subdata"}
$cd->{"use_dpath"} $ccl->{"subdata"}
Truth table100%3/3
A and B
A= $cd->{"use_dpath"}B= $ccl->{"subdata"}
ABresult
0X0
100
111
543 22751 $res;
544  
545 13768 };
546  
547 13768 my $j = "\n\n$aop\n\n";
548 13768 ▶ if ($op eq 'not') {
Branch: 3 branches
BranchTrueFalseTotal
if ($op eq 'not') { } 304 13464 13768
elsif ($op eq 'and') { } 12569 895 13464
elsif ($op eq 'none') { } 288 607 895
549 304 return $_ice->($ccls->[0], 1);
550 } elsif ($op eq 'and') {
551 12569 return join $j, map { $_ice->($_) } @$ccls;
552 } elsif ($op eq 'none') {
553 288 return join $j, map { $_ice->($_, 1) } @$ccls;
554 } else {
555 607 ▶ my $jccl = join $j, map {$_ice->($ccls->[$_], $_ == @$ccls-1 ? 3:2)}
Branch: 1 branch
BranchTrueFalseTotal
$_ == @$ccls - 1 ? : 607 607 1214
556 0..@$ccls-1;
557 {
558 607 local $cd->{ccls} = [];
559 607 local $cd->{_debug_ccl_note} = "op=$op";
560 607 ▶ $self->add_ccl(
Branch: 1 branch
BranchTrueFalseTotal
$self->block_uses_sub ? : 0 607 607
561 $cd,
562 $self->expr_block(
563 join(
564 "",
565 $self->stmt_declare_local_var("${vp}ok" , "0"), "\n",
566 $self->stmt_declare_local_var("${vp}nok", "0"), "\n",
567 "\n",
568 $self->block_uses_sub ?
569 $self->stmt_return($jccl) : $jccl,
570 )
571 ),
572 );
573 607 $_ice->($cd->{ccls}[0]);
574 }
575 }
576 }
577  
578 5060 ▶sub before_compile {
Subroutine before_compile: called CC=3 SCAR=18.4
Pod documented
579 5060 my ($self, $cd) = @_;
580  
581 5060 ▶ if ($cd->{args}{data_term_is_lvalue}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cd->{'args'}{'data_term_is_lvalue'}) { } 5060 0 5060
582 5060 $cd->{data_term} = $cd->{args}{data_term};
583 } else {
584 0 my $v = $cd->{args}{var_prefix} . $cd->{args}{data_name};
585 0 push @{ $cd->{vars} }, $v; # XXX unless already there
586 0 $cd->{data_term} = $self->var_sigil . $v;
587 die "BUG: support for non-perl compiler not yet added here"
588 0 ▶ unless $cd->{compiler_name} eq 'perl';
Branch: 1 branch
BranchTrueFalseTotal
unless $cd->{"compiler_name"} eq "perl" 0 0 0
589 0 push @{ $cd->{ccls} }, ["(local($cd->{data_term} = $cd->{args}{data_term}), 1)"];
590 }
591 }
592  
593 5059 ▶sub before_handle_type {
Subroutine before_handle_type: called CC=2 SCAR=6.9
Pod documented
594 5059 my ($self, $cd) = @_;
595  
596 # do a human compilation first to collect all the error messages
597  
598 5059 ▶ unless ($cd->{is_inner}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cd->{"is_inner"}) 4729 330 5059
599 4729 my $hc = $cd->{_hc};
600 4729 my %hargs = %{$cd->{args}};
601 4729 $hargs{format} = 'msg_catalog';
602 4729 $hargs{schema_is_normalized} = 1;
603 4729 $hargs{schema} = $cd->{nschema};
604 4729 $hargs{on_unhandled_clause} = 'ignore';
605 4729 $hargs{on_unhandled_attr} = 'ignore';
606 4729 $hargs{hash_values} = $cd->{args}{human_hash_values};
607 4729 $cd->{_hcd} = $hc->compile(%hargs);
608 }
609 }
610  
611 5056 ▶sub before_all_clauses {
Subroutine before_all_clauses: called CC=66 SCAR=44.1
Pod documented
612 5056 my ($self, $cd) = @_;
613  
614 5056 my $rt = $cd->{args}{return_type};
615 5056 my $rt_is_hash = $rt =~ /\Ahash/;
616 5056 my $rt_is_str = $rt =~ /\Astr/;
617  
618 $cd->{use_dpath} //= (
619 $rt_is_hash ||
620 ($rt_is_str && $cd->{has_subschema})
621 5056 ▶ );
Condition88%8/9
$cd->{"use_dpath"} //= $rt_is_hash || $rt_is_str && $cd->{"has_subschema"}
l!l&&r!l&&!r
20948470
$rt_is_hash || $rt_is_str && $cd->{'has_subschema'}
l!l&&r!l&&!r
1470673310
$rt_is_str and $cd->{"has_subschema"}
!ll&&!rl&&r
1904140667
MC/DC0%0/4
$cd->{"use_dpath"} //= $rt_is_hash || $rt_is_str && $cd->{"has_subschema"}
$cd->{"use_dpath"} $rt_is_hash $rt_is_str $cd->{"has_subschema"}
Truth table0%0/5
A //= B || C and D
A= $cd->{"use_dpath"}B= $rt_is_hashC= $rt_is_strD= $cd->{"has_subschema"}
ABCDresult
1XXX1
01XX1
00111
000X0
00100
622  
623 # handle ok/default/coercion/prefilters/req/forbidden clauses and type check
624  
625 5056 my $c = $cd->{compiler};
626 5056 my $cname = $c->name;
627 5056 my $dt = $cd->{data_term};
628 5056 my $et = $cd->{args}{err_term};
629 5056 my $clsets = $cd->{clsets};
630  
631 # handle ok, this is very high priority because !ok=>1 should fail undef
632 # too. we need to handle its .op=not here.
633 5056 for my $i (0..@$clsets-1) {
634 4610 my $clset = $clsets->[$i];
635 4610 ▶ next unless exists $clset->{ok};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $clset->{"ok"} 4556 54 4610
636 54 ▶ my $op = $clset->{"ok.op"} // "";
Condition100%2/2
$clset->{"ok.op"} // ""
l!l
2727
MC/DC100%1/1
$clset->{"ok.op"} // ""
$clset->{"ok.op"}
Truth table100%2/2
A
A= $clset->{"ok.op"}
Aresult
11
00
637 54 ▶ if ($op && $op ne 'not') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op and $op ne "not") 0 54 54
Condition66%2/3
$op and $op ne "not"
!ll&&!rl&&r
27270
MC/DC0%0/2
$op and $op ne "not"
$op $op ne "not"
Truth table66%2/3
A and B
A= $opB= $op ne "not"
ABresult
0X0
100
111
638 0 $self->_die($cd, "ok can only be combined with .op=not");
639 }
640 54 ▶ if ($op eq 'not') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq 'not') { } 27 27 54
641 27 local $cd->{_debug_ccl_note} = "!ok #$i";
642 27 $self->add_ccl($cd, $self->false);
643 } else {
644 27 local $cd->{_debug_ccl_note} = "ok #$i";
645 27 $self->add_ccl($cd, $self->true);
646 }
647 54 delete $cd->{uclsets}[$i]{"ok"};
648 54 delete $cd->{uclsets}[$i]{"ok.is_expr"};
649 }
650  
651 # handle default
652 HANDLE_DEFAULT: {
653  
654 5056 my $default_value_expr;
655 my $default_value_ccl_note;
656 GEN_DEFAULT_VALUE_RULES:
657 {
658 5056 require Data::Sah::DefaultValueCommon;
659  
660 5056 my @default_value_rules;
661 5056 for my $i (0..@$clsets-1) {
662 4610 my $clset = $clsets->[$i];
663 push @default_value_rules,
664 4610 ▶ @{ $clset->{"x.$cname.default_value_rules"} // [] },
Condition100%2/2
$$clset{"x.$cname.default_value_rules"} // []
l!l
14609
MC/DC100%1/1
$$clset{"x.$cname.default_value_rules"} // []
$$clset{"x.$cname.default_value_rules"}
Truth table100%2/2
A
A= $$clset{"x.$cname.default_value_rules"}
Aresult
11
00
665 4610 ▶ @{ $clset->{'x.default_value_rules'} // [] };
Condition50%1/2
$clset->{"x.default_value_rules"} // []
l!l
04610
MC/DC0%0/1
$clset->{"x.default_value_rules"} // []
$clset->{"x.default_value_rules"}
Truth table50%1/2
A
A= $clset->{"x.default_value_rules"}
Aresult
11
00
666 }
667  
668 5056 my $extra_args = {};
669 5056 $extra_args->{coerce_to} = $cd->{coerce_to};
670 5056 my $rules = Data::Sah::DefaultValueCommon::get_default_value_rules(
671 compiler => $self->name,
672 default_value_rules => \@default_value_rules,
673 extra_args => $extra_args,
674 );
675 5056 ▶ last unless @$rules;
Branch: 1 branch
BranchTrueFalseTotal
unless @$rules 5055 1 5056
676  
677 1 for my $i (reverse 0..$#{$rules}) {
678 1 my $rule = $rules->[$i];
679  
680 1 $self->add_compile_module(
681 $cd, "Data::Sah::Value::$cname\::$rule->{name}",
682 {category => 'default_value'},
683 );
684  
685 1 ▶ if ($rule->{modules}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rule->{"modules"}) 0 1 1
686 0 for my $mod (keys %{ $rule->{modules} }) {
687 0 my $modspec = $rule->{modules}{$mod};
688 0 ▶ $modspec = {version=>$modspec} unless ref $modspec eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $modspec eq "HASH" 0 0 0
689 0 $self->add_runtime_module($cd, $mod, {category=>'default_value', %$modspec});
690 }
691 }
692 }
693  
694 1 $default_value_expr = join " // " , map { "($_->{expr_value})" } @$rules;
695 $default_value_ccl_note = "default value rule(s): ".
696 1 join(", ", map {$_->{name}} @$rules);
697 } # GEN_DEFAULT_VALUE_RULES
698  
699 5056 for my $i (0..@$clsets-1) {
700 4610 my $clset = $clsets->[$i];
701 4610 my $def = $clset->{default};
702 4610 my $defie = $clset->{"default.is_expr"};
703 4610 ▶ if (defined $def) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $def) 90 4520 4610
704 90 local $cd->{_debug_ccl_note} = "default #$i";
705 90 ▶ my $ct = $defie ?
Branch: 1 branch
BranchTrueFalseTotal
$defie ? : 0 90 90
706 $self->expr($cd, $def) : $self->literal($def);
707 90 $self->add_ccl(
708 $cd,
709 $self->expr_list(
710 $self->expr_setif($dt, $ct),
711 $self->true,
712 ),
713 {err_msg => ""},
714 );
715 }
716 4610 delete $cd->{uclsets}[$i]{"default"};
717 4610 delete $cd->{uclsets}[$i]{"default.is_expr"};
718 }
719  
720 5056 ▶ if (defined $default_value_expr) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $default_value_expr) 1 5055 5056
721 1 local $cd->{_debug_ccl_note} = $default_value_ccl_note;
722 1 $self->add_ccl(
723 $cd,
724 $self->expr_list(
725 $self->expr_setif($dt, $default_value_expr),
726 $self->true,
727 ),
728 {err_msg => ""},
729 );
730 }
731 } # HANDLE_DEFAULT
732  
733 # handle req
734 5056 my $has_req;
735 5056 for my $i (0..@$clsets-1) {
736 4610 my $clset = $clsets->[$i];
737 4610 my $req = $clset->{req};
738 4610 my $reqie = $clset->{"req.is_expr"};
739 4610 my $req_err_msg = $self->_xlt($cd, "Required but not specified");
740 4610 local $cd->{_debug_ccl_note} = "req #$i";
741 4610 ▶ if ($req && !$reqie) {
Branch: 2 branches
BranchTrueFalseTotal
if ($req and not $reqie) { } 471 4139 4610
elsif ($reqie) { } 0 4139 4139
Condition66%2/3
$req and not $reqie
!ll&&!rl&&r
41390471
MC/DC50%1/2
$req and not $reqie
$req not $reqie
Truth table66%2/3
A and not(B)
A= $reqB= not $reqie
ABresult
0X0
100
111
742 471 $has_req++;
743 471 $self->add_ccl(
744 $cd, $self->expr_defined($dt),
745 {
746 err_msg => $req_err_msg,
747 err_level => 'fatal',
748 },
749 );
750 } elsif ($reqie) {
751 0 $has_req++;
752 0 my $ct = $self->expr($cd, $req);
753 0 $self->add_ccl(
754 $cd, "!($ct) || ".$self->expr_defined($dt),
755 {
756 err_msg => $req_err_msg,
757 err_level => 'fatal',
758 },
759 );
760 }
761 4610 delete $cd->{uclsets}[$i]{"req"};
762 4610 delete $cd->{uclsets}[$i]{"req.is_expr"};
763 }
764  
765 # handle forbidden
766 5056 my $has_fbd;
767 5056 for my $i (0..@$clsets-1) {
768 4610 my $clset = $clsets->[$i];
769 4610 my $fbd = $clset->{forbidden};
770 4610 my $fbdie = $clset->{"forbidden.is_expr"};
771 4610 my $fbd_err_msg = $self->_xlt($cd, "Forbidden but specified");
772 4610 local $cd->{_debug_ccl_note} = "forbidden #$i";
773 4610 ▶ if ($fbd && !$fbdie) {
Branch: 2 branches
BranchTrueFalseTotal
if ($fbd and not $fbdie) { } 27 4583 4610
elsif ($fbdie) { } 0 4583 4583
Condition66%2/3
$fbd and not $fbdie
!ll&&!rl&&r
4583027
MC/DC50%1/2
$fbd and not $fbdie
$fbd not $fbdie
Truth table66%2/3
A and not(B)
A= $fbdB= not $fbdie
ABresult
0X0
100
111
774 27 $has_fbd++;
775 27 $self->add_ccl(
776 $cd, "!".$self->expr_defined($dt),
777 {
778 err_msg => $fbd_err_msg,
779 err_level => 'fatal',
780 },
781 );
782 } elsif ($fbdie) {
783 0 $has_fbd++;
784 0 my $ct = $self->expr($cd, $fbd);
785 0 $self->add_ccl(
786 $cd, "!($ct) || !".$self->expr_defined($dt),
787 {
788 err_msg => $fbd_err_msg,
789 err_level => 'fatal',
790 },
791 );
792 }
793 4610 delete $cd->{uclsets}[$i]{"forbidden"};
794 4610 delete $cd->{uclsets}[$i]{"forbidden.is_expr"};
795 }
796  
797 5056 ▶ if (!$has_req && !$has_fbd) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($has_req or $has_fbd) 4558 498 5056
Condition100%3/3
$has_req or $has_fbd
l!l&&r!l&&!r
471274558
MC/DC100%2/2
$has_req or $has_fbd
$has_req $has_fbd
Truth table100%3/3
A or B
A= $has_reqB= $has_fbd
ABresult
1X1
011
000
798 4558 $cd->{_skip_undef} = 1;
799 4558 $cd->{_ccls_idx1} = @{$cd->{ccls}};
800 }
801  
802 5056 my $coerce_expr;
803 my $coerce_might_fail;
804 5056 my $coerce_ccl_note;
805 GEN_COERCE_EXPR:
806 {
807 5056 ▶ last unless $cd->{args}{coerce};
Branch: 1 branch
BranchTrueFalseTotal
unless $cd->{"args"}{"coerce"} 0 5056 5056
808  
809 5056 require Data::Sah::CoerceCommon;
810  
811 5056 my @coerce_rules;
812 5056 for my $i (0..@$clsets-1) {
813 4610 my $clset = $clsets->[$i];
814 push @coerce_rules,
815 4610 ▶ @{ $clset->{"x.$cname.coerce_rules"} // [] },
Condition100%2/2
$$clset{"x.$cname.coerce_rules"} // []
l!l
14609
MC/DC100%1/1
$$clset{"x.$cname.coerce_rules"} // []
$$clset{"x.$cname.coerce_rules"}
Truth table100%2/2
A
A= $$clset{"x.$cname.coerce_rules"}
Aresult
11
00
816 4610 ▶ @{ $clset->{'x.coerce_rules'} // [] };
Condition50%1/2
$clset->{"x.coerce_rules"} // []
l!l
04610
MC/DC0%0/1
$clset->{"x.coerce_rules"} // []
$clset->{"x.coerce_rules"}
Truth table50%1/2
A
A= $clset->{"x.coerce_rules"}
Aresult
11
00
817 }
818  
819 my $rules = Data::Sah::CoerceCommon::get_coerce_rules(
820 compiler => $self->name,
821 type => $cd->{type},
822 data_term => $dt,
823 coerce_to => $cd->{coerce_to},
824 5056 coerce_rules => \@coerce_rules,
825 );
826 5056 ▶ last unless @$rules;
Branch: 1 branch
BranchTrueFalseTotal
unless @$rules 3836 1220 5056
827  
828 1220 ▶ $coerce_might_fail = 1 if grep { $_->{meta}{might_fail} } @$rules;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_->{"meta"}{"might_fail"};} @$rules 60 1160 1220
829  
830 1220 my $prev_term;
831 1220 for my $i (reverse 0..$#{$rules}) {
832 1392 my $rule = $rules->[$i];
833  
834 1392 $self->add_compile_module(
835 $cd, "Data::Sah::Coerce::$cname\::To_$cd->{type}::$rule->{name}",
836 {category => 'coerce'},
837 );
838  
839 1392 ▶ if ($rule->{modules}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rule->{"modules"}) 156 1236 1392
840 156 for my $mod (keys %{ $rule->{modules} }) {
841 156 my $modspec = $rule->{modules}{$mod};
842 156 ▶ $modspec = {version=>$modspec} unless ref $modspec eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $modspec eq "HASH" 156 0 156
843 156 $self->add_runtime_module($cd, $mod, {category=>'coerce', %$modspec});
844 }
845 }
846  
847 1392 ▶ if ($i == $#{$rules}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $#{$rules;}) { } 1220 172 1392
848 1220 ▶ if ($coerce_might_fail) {
Branch: 1 branch
BranchTrueFalseTotal
if ($coerce_might_fail) { } 60 1160 1220
849 60 $prev_term = $self->expr_array($self->literal(undef), $dt);
850 } else {
851 1160 $prev_term = $dt;
852 }
853 } else {
854 172 $prev_term = "($coerce_expr)";
855 }
856  
857 1392 my $ec;
858 1392 ▶ if ($coerce_might_fail && !$rule->{meta}{might_fail}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($coerce_might_fail and not $rule->{'meta'}{'might_fail'}) { } 164 1228 1392
Condition100%3/3
$coerce_might_fail and not $rule->{"meta"}{"might_fail"}
!ll&&!rl&&r
116068164
MC/DC100%2/2
$coerce_might_fail and not $rule->{"meta"}{"might_fail"}
$coerce_might_fail not $rule->{"meta"}{"might_fail"}
Truth table100%3/3
A and not(B)
A= $coerce_might_failB= not $rule->{"meta"}{"might_fail"}
ABresult
0X0
100
111
859 164 $ec = $self->expr_array($self->literal(undef), $rule->{expr_coerce});
860 } else {
861 1228 $ec = "($rule->{expr_coerce})";
862 }
863  
864 1392 $coerce_expr = $self->expr_ternary(
865 "($rule->{expr_match})",
866 $ec,
867 $prev_term,
868 );
869 }
870 $coerce_ccl_note = "coerce rule(s): ".
871 1392 ▶ join(", ", map {$_->{name}} @$rules) .
Branch: 1 branch
BranchTrueFalseTotal
$cd->{'coerce_to'} ? : 60 1160 1220
872 1220 ($cd->{coerce_to} ? " # coerce to: $cd->{coerce_to}" : "");
873 } # GEN_COERCE_EXPR
874  
875 5056 my $prefilters_expr;
876 my $prefilters_ccl_note;
877 GEN_PREFILTERS_EXPRS:
878 {
879 5056 my @filter_names;
880 5056 for my $i (0..@$clsets-1) {
881 4610 my $clset = $clsets->[$i];
882 6 push @filter_names, @{ $clset->{prefilters} }
883 4610 ▶ if defined $clset->{prefilters};
Branch: 1 branch
BranchTrueFalseTotal
if defined $clset->{"prefilters"} 6 4604 4610
884 }
885 5056 ▶ last unless @filter_names;
Branch: 1 branch
BranchTrueFalseTotal
unless @filter_names 5050 6 5056
886  
887 6 require Data::Sah::FilterCommon;
888 6 my $rules = Data::Sah::FilterCommon::get_filter_rules(
889 compiler => $cname,
890 data_term => $dt,
891 filter_names => \@filter_names,
892 );
893  
894 6 my @exprs;
895 6 for my $i (0..$#{$rules}) {
896 7 my $rule = $rules->[$i];
897  
898 7 $self->add_compile_module(
899 $cd, "Data::Sah::Filter::$cname\::$rule->{name}",
900 {category => 'filter'},
901 );
902 7 ▶ if ($rule->{modules}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rule->{"modules"}) 0 7 7
903 0 for my $mod (keys %{ $rule->{modules} }) {
904 0 my $modspec = $rule->{modules}{$mod};
905 0 ▶ $modspec = {version=>$modspec} unless ref $modspec eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $modspec eq "HASH" 0 0 0
906 0 $self->add_runtime_module($cd, $mod, {category=>'filter', %$modspec});
907 }
908 }
909  
910 7 my $rule_might_fail = $rule->{meta}{might_fail};
911 7 my $expr;
912 7 ▶ if ($rule->{meta}{might_fail}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rule->{'meta'}{'might_fail'}) { } 3 4 7
913 3 my $expr_fail;
914 # XXX rather hackish: like when coercion handling, to avoid
915 # adding another temporary variable, we reuse data term to hold
916 # filtering result (which contains error message string as well
917 # filtered data) then set the data term to the filtered data
918 # again. this might fail in languages or setting that is
919 # stricter (e.g. data term must be of certain type).
920 3 ▶ if ($rt_is_hash) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rt_is_hash) { } 0 3 3
elsif ($rt_is_str) { } 0 3 3
921 0 $expr_fail = $self->expr_list(
922 $self->expr_set_err_full($et, 'errors', $self->expr_array_subscript($dt, 0)),
923 $self->false,
924 );
925 } elsif ($rt_is_str) {
926 0 $expr_fail = $self->expr_list(
927 $self->expr_set_err_str($et, $self->expr_array_subscript($dt, 0)),
928 $self->expr_set($dt, $self->expr_array_subscript($dt, 1)),
929 $self->false,
930 );
931 } else {
932 3 $expr_fail = $self->false;
933 }
934  
935 $expr = $self->expr_list(
936 3 $self->expr_set($dt, $rule->{expr_filter}),
937 $self->expr_ternary(
938 $self->expr_defined($self->expr_array_subscript($dt, 0)),
939 $expr_fail,
940 $self->expr_list(
941 $self->expr_set($dt, $self->expr_array_subscript($dt, 1)),
942 $self->true,
943 )
944 ),
945 );
946 } else {
947 $expr = $self->expr_list(
948 4 $self->expr_set($dt, $rule->{expr_filter}),
949 $self->true,
950 );
951 }
952 7 push @exprs, $expr;
953 } # for rules
954 6 $prefilters_expr = join(" ".$self->logical_and_op." ", @exprs);
955 $prefilters_ccl_note = "prefilters: ".
956 6 join(", ", map {$_->{name}} @$rules);
957 } # GEN_PREFILTERS_EXPR
958  
959 HANDLE_TYPE_CHECK_OR_BASE_SCHEMA_CHECK:
960 {
961 5056 ▶ if (defined $cd->{base_schema}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cd->{'base_schema'}) { } 0 5056 5056
962 0 $self->gen_cached_validator($cd, $cd->{base_schema});
963 } else {
964 $self->_die($cd, "BUG: type handler did not produce _ccl_check_type")
965 5056 ▶ unless defined($cd->{_ccl_check_type});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cd->{"_ccl_check_type"} 0 5056 5056
966 }
967 5056 local $cd->{_debug_ccl_note};
968  
969 # handle coercion
970 5056 ▶ if ($coerce_expr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($coerce_expr) 1220 3836 5056
971 1220 $cd->{_debug_ccl_note} = $coerce_ccl_note;
972 1220 ▶ if ($coerce_might_fail) {
Branch: 1 branch
BranchTrueFalseTotal
if ($coerce_might_fail) { } 60 1160 1220
973  
974 60 my $expr_fail;
975 60 ▶ if ($rt_is_hash) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rt_is_hash) { } 0 60 60
elsif ($rt_is_str) { } 1 59 60
976 0 $expr_fail = $self->expr_list(
977 $self->expr_set_err_full($et, 'errors', $self->expr_array_subscript($dt, 0)),
978 $self->false,
979 );
980 } elsif ($rt_is_str) {
981 1 $expr_fail = $self->expr_list(
982 $self->expr_set_err_str($et, $self->expr_array_subscript($dt, 0)),
983 $self->expr_set($dt, $self->expr_array_subscript($dt, 1)),
984 $self->false,
985 );
986 } else {
987 59 $expr_fail = $self->false;
988 }
989  
990 60 $self->add_ccl(
991 $cd,
992 $self->expr_list(
993 $self->expr_set($dt, $coerce_expr),
994 $self->expr_ternary(
995 $self->expr_defined($self->expr_array_subscript($dt, 0)),
996 $expr_fail,
997 $self->expr_list(
998 $self->expr_set($dt, $self->expr_array_subscript($dt, 1)),
999 $self->true,
1000 )
1001 ),
1002 ),
1003 {
1004 err_msg => "",
1005 err_level => "fatal",
1006 },
1007 );
1008 } else {
1009 1160 $self->add_ccl(
1010 $cd,
1011 $self->expr_list(
1012 $self->expr_set($dt, $coerce_expr),
1013 $self->true,
1014 ),
1015 {
1016 err_msg => "",
1017 err_level => "fatal",
1018 },
1019 );
1020 }
1021 } # handle coercion
1022  
1023 # handle prefilters
1024 5056 ▶ if (defined $prefilters_expr) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prefilters_expr) 6 5050 5056
1025 6 $cd->{_debug_ccl_note} = $prefilters_ccl_note;
1026 6 $self->add_ccl(
1027 $cd,
1028 $prefilters_expr,
1029 {
1030 err_msg => "",
1031 err_level => "fatal",
1032 },
1033 );
1034 } # handle prefilters
1035  
1036 # handle type check (if cache=0) or base schema check (if cache=1)
1037 5056 ▶ if (defined $cd->{base_schema}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cd->{'base_schema'}) { } 0 5056 5056
1038 0 $cd->{_debug_ccl_note} = "check base schema '$cd->{base_schema}'";
1039 $self->add_ccl(
1040 $cd, $self->expr_call_cached_validator($cd, $cd->{base_schema}),
1041 {
1042 err_msg => sprintf(
1043 $self->_xlt($cd, "Not of schema %s"),
1044 $self->_xlt(
1045 $cd,
1046 $cd->{base_schema},
1047 0 ),
1048 ),
1049 err_level => 'fatal',
1050 },
1051 );
1052 } else {
1053 5056 $cd->{_debug_ccl_note} = "check type '$cd->{type}'";
1054 $self->add_ccl(
1055 $cd, $cd->{_ccl_check_type},
1056 {
1057 err_msg => sprintf(
1058 $self->_xlt($cd, "Not of type %s"),
1059 $self->_xlt(
1060 $cd,
1061 $cd->{_hc}->get_th(name=>$cd->{type})->name //
1062 $cd->{type}
1063 5056 ▶ ),
Condition66%2/3
$cd->{"_hc"}->get_th("name", $cd->{"type"})->name // $cd->{"type"}
l!l&&r!l&&!r
388111750
MC/DC0%0/2
$cd->{"_hc"}->get_th("name", $cd->{"type"})->name // $cd->{"type"}
$cd->{"_hc"}->get_th("name", $cd->{"type"})->name $cd->{"type"}
Truth table66%2/3
A // B
A= $cd->{"_hc"}->get_th("name", $cd->{"type"})->nameB= $cd->{"type"}
ABresult
1X1
011
000
1064 ),
1065 err_level => 'fatal',
1066 },
1067 );
1068 }
1069 } # HANDLE_TYPE_CHECK_OR_BASE_SCHEMA_CHECK
1070 }
1071  
1072 5306 ▶sub before_clause {
Subroutine before_clause: called CC=4 SCAR=18.8
Pod documented
1073 5306 my ($self, $cd) = @_;
1074  
1075 $self->_die($cd, "Sorry, .op + .is_expr not yet supported ".
1076 "(found in clause $cd->{clause})")
1077 5306 ▶ if $cd->{cl_is_expr} && $cd->{cl_op};
Branch: 1 branch
BranchTrueFalseTotal
if $cd->{"cl_is_expr"} and $cd->{"cl_op"} 0 5306 5306
Condition66%2/3
$cd->{"cl_is_expr"} and $cd->{"cl_op"}
!ll&&!rl&&r
530240
MC/DC0%0/2
$cd->{"cl_is_expr"} and $cd->{"cl_op"}
$cd->{"cl_is_expr"} $cd->{"cl_op"}
Truth table66%2/3
A and B
A= $cd->{"cl_is_expr"}B= $cd->{"cl_op"}
ABresult
0X0
100
111
1078  
1079 5306 ▶ if ($cd->{args}{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cd->{'args'}{'debug'}) { } 0 5306 5306
1080 0 state $json = do {
1081 0 require JSON;
1082 0 JSON->new->allow_nonref;
1083 };
1084 0 my $clset = $cd->{clset};
1085 0 my $cl = $cd->{clause};
1086 my $res = $json->encode({
1087 0 map { $_ => $clset->{$_}}
1088 0 grep {/\A\Q$cl\E(?:\.|\z)/}
1089 keys %$clset });
1090 0 $res =~ s/\n+/ /g;
1091 # a one-line dump of the clause, suitable for putting in generated
1092 # code's comment
1093 0 $cd->{_debug_ccl_note} = "clause: $res";
1094 } else {
1095 5306 $cd->{_debug_ccl_note} = "clause: $cd->{clause}";
1096 }
1097  
1098 # we save ccls to save_ccls and empty ccls for each clause, to let clause
1099 # join and do stuffs to ccls. at after_clause(), we push the clause's result
1100 # as a single ccl to the original ccls.
1101  
1102 5306 push @{ $cd->{_save_ccls} }, $cd->{ccls};
1103 5306 $cd->{ccls} = [];
1104 }
1105  
1106 5276 ▶sub after_clause {
Subroutine after_clause: called CC=4 SCAR=14.0
Pod documented
1107 5276 my ($self, $cd) = @_;
1108  
1109 5276 ▶ if ($cd->{args}{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cd->{"args"}{"debug"}) 0 5276 5276
1110 0 delete $cd->{_debug_ccl_note};
1111 }
1112  
1113 5276 my $save = pop @{ $cd->{_save_ccls} };
1114 5276 ▶ if (@{ $cd->{ccls} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$cd->{"ccls"};}) 3957 1319 5276
1115 push @$save, {
1116 ccl => $self->join_ccls($cd, $cd->{ccls}, {op=>$cd->{cl_op}}),
1117 3957 ▶ err_level => $cd->{clset}{"$cd->{clause}.err_level"} // "error",
Condition100%2/2
$cd->{"clset"}{qq[$cd->{"clause"}.err_level]} // "error"
l!l
543903
MC/DC100%1/1
$cd->{"clset"}{qq[$cd->{"clause"}.err_level]} // "error"
$cd->{"clset"}{qq[$cd->{"clause"}.err_level]}
Truth table100%2/2
A
A= $cd->{"clset"}{qq[$cd->{"clause"}.err_level]}
Aresult
11
00
1118 }
1119 }
1120 5276 $cd->{ccls} = $save;
1121 }
1122  
1123 174 ▶sub after_clause_sets {
Subroutine after_clause_sets: called CC=1 SCAR=0.0
Pod undocumented
1124 174 my ($self, $cd) = @_;
1125  
1126 # simply join them together with &&
1127 $cd->{result} = $self->indent(
1128 $cd,
1129 174 $self->join_ccls($cd, $cd->{ccls}, {err_msg => ''}),
1130 );
1131 }
1132  
1133 5025 ▶sub after_all_clauses {
Subroutine after_all_clauses: called CC=2 SCAR=6.9
Pod documented
1134 5025 my ($self, $cd) = @_;
1135  
1136 # XXX also handle postfilters here
1137  
1138 5025 ▶ if (delete $cd->{_skip_undef}) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $cd->{"_skip_undef"}) 4554 471 5025
1139 my $jccl = $self->join_ccls(
1140 $cd,
1141 4554 [splice(@{ $cd->{ccls} }, $cd->{_ccls_idx1})],
1142 );
1143 4554 local $cd->{_debug_ccl_note} = "skip if undef";
1144 $self->add_ccl(
1145 $cd,
1146 4554 "!".$self->expr_defined($cd->{data_term})." ? ".$self->true." : \n\n".
1147 $self->enclose_paren($jccl),
1148 {err_msg => ''},
1149 );
1150 }
1151  
1152 # simply join them together with &&
1153 $cd->{result} = $self->indent(
1154 $cd,
1155 5025 $self->join_ccls($cd, $cd->{ccls}, {err_msg => ''}),
1156 );
1157 }
1158  
1159 24 1;
1160 # ABSTRACT: Base class for programming language compilers
1161  
1162 __END__
« Data/Sah/Util/Type/Date.pm ↑ Summary Test/Data/Sah.pm »