Data/Sah/Compiler/Prog/TH.pm

filter: Statementstmt 93.2% 96 / 103 Branchbran 62.5% 5 / 8 Conditioncond 44.4% 4 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 82.6% 19 / 23 Podpod 0.0% 0 / 19 totaltotal 74.2% 124 / 167 CC 9 SCAR 6.7
CC
9
Cov
88%
clause_if
4.1
set_tmp_data_term
3.0
gen_any_or_all_of
3.0
CRAP 2.0
« Data/Sah/Compiler/human/TH/float.pm ↑ Summary Data/Sah/Compiler/human/TH/Comparable.pm »
1 package Data::Sah::Compiler::Prog::TH;
2  
3 46 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 46 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 46 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 #use Log::Any '$log';
7  
8 46 ▶use Mo qw(build default);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 46 extends 'Data::Sah::Compiler::TH';
11  
12 46 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
13 46 our $DATE = '2024-02-16'; # DATE
14 46 our $DIST = 'Data-Sah'; # DIST
15 46 our $VERSION = '0.917'; # VERSION
16  
17 # handled in compiler's before_all_clauses()
18  
19 90 ▶sub clause_default {}
Subroutine clause_default: called CC=1 SCAR=0.0
Pod undocumented
20 54 ▶sub clause_ok {}
Subroutine clause_ok: called CC=1 SCAR=0.0
Pod undocumented
21 498 ▶sub clause_req {}
Subroutine clause_req: called CC=1 SCAR=0.0
Pod undocumented
22 54 ▶sub clause_forbidden {}
Subroutine clause_forbidden: called CC=1 SCAR=0.0
Pod undocumented
23 6 ▶sub clause_prefilters {}
Subroutine clause_prefilters: called CC=1 SCAR=0.0
Pod undocumented
24  
25 # handled in compiler's after_all_clauses()
26  
27 0 ▶sub clause_postfilters {}
Subroutine clause_postfilters: not called CC=1 SCAR=0.0
Pod undocumented
28  
29 27 ▶sub clause_name {
Subroutine clause_name: called CC=1 SCAR=0.0
Pod undocumented
30 27 my ($self, $cd) = @_;
31 27 $self->compiler->_ignore_clause_and_attrs($cd);
32 }
33  
34 27 ▶sub clause_summary {
Subroutine clause_summary: called CC=1 SCAR=0.0
Pod undocumented
35 27 my ($self, $cd) = @_;
36 27 $self->compiler->_ignore_clause_and_attrs($cd);
37 }
38  
39 27 ▶sub clause_description {
Subroutine clause_description: called CC=1 SCAR=0.0
Pod undocumented
40 27 my ($self, $cd) = @_;
41 27 $self->compiler->_ignore_clause_and_attrs($cd);
42 }
43  
44 0 ▶sub clause_comment {
Subroutine clause_comment: not called CC=1 SCAR=6.9
Pod undocumented
45 0 my ($self, $cd) = @_;
46 0 $self->compiler->_ignore_clause($cd);
47 }
48  
49 27 ▶sub clause_tags {
Subroutine clause_tags: called CC=1 SCAR=0.0
Pod undocumented
50 27 my ($self, $cd) = @_;
51 27 $self->compiler->_ignore_clause($cd);
52 }
53  
54 27 ▶sub clause_defhash_v {
Subroutine clause_defhash_v: called CC=1 SCAR=0.0
Pod undocumented
55 27 my ($self, $cd) = @_;
56 27 $self->compiler->_ignore_clause($cd);
57 }
58  
59 27 ▶sub clause_v {
Subroutine clause_v: called CC=1 SCAR=0.0
Pod undocumented
60 27 my ($self, $cd) = @_;
61 27 $self->compiler->_ignore_clause($cd);
62 }
63  
64 0 ▶sub clause_examples {
Subroutine clause_examples: not called CC=1 SCAR=6.9
Pod undocumented
65 0 my ($self, $cd) = @_;
66 0 $self->compiler->_ignore_clause($cd);
67 }
68  
69 0 ▶sub clause_links {
Subroutine clause_links: not called CC=1 SCAR=6.9
Pod undocumented
70 0 my ($self, $cd) = @_;
71 0 $self->compiler->_ignore_clause($cd);
72 }
73  
74 # temporarily use temporary variable for referring to data (e.g. when converting
75 # non-number to number for checking in clauses, or prefiltering)
76 530 ▶sub set_tmp_data_term {
Subroutine set_tmp_data_term: called CC=3 SCAR=11.0
Pod undocumented
77 530 my ($self, $cd, $expr) = @_;
78 530 my $c = $self->compiler;
79 #$log->errorf("TMP: set_tmp_data_term");
80  
81 530 ▶ $expr //= $cd->{data_term};
Condition66%2/3
$expr //= $cd->{"data_term"}
l!l&&r!l&&!r
52190
MC/DC0%0/2
$expr //= $cd->{"data_term"}
$expr $cd->{"data_term"}
Truth table66%2/3
A //= B
A= $exprB= $cd->{"data_term"}
ABresult
1X1
011
000
82  
83 530 my $tdn = $cd->{args}{tmp_data_name};
84 530 my $tdt = $cd->{args}{tmp_data_term};
85 530 my $t = $c->expr_array_subscript($tdt, $cd->{_subdata_level});
86 530 ▶ unless ($cd->{_save_data_term}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cd->{"_save_data_term"}) 530 0 530
87 530 $c->add_var($cd, $tdn, []);
88 530 $cd->{_save_data_term} = $cd->{data_term};
89 530 $cd->{data_term} = $t;
90 }
91 530 local $cd->{_debug_ccl_note} = 'set temporary data term';
92 530 $c->add_ccl($cd, "(".$c->expr_set($t, $expr). ", ".$c->true.")",
93 {err_msg => ''});
94 }
95  
96 526 ▶sub restore_data_term {
Subroutine restore_data_term: called CC=2 SCAR=7.0
Pod undocumented
97 526 my ($self, $cd) = @_;
98 526 my $c = $self->compiler;
99 #$log->errorf("TMP: restore_data_term");
100  
101 526 my $tdt = $cd->{args}{tmp_data_term};
102 526 ▶ if ($cd->{_save_data_term}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cd->{"_save_data_term"}) 526 0 526
103 526 $cd->{data_term} = delete($cd->{_save_data_term});
104 526 local $cd->{_debug_ccl_note} = 'restore original data term';
105 526 $c->add_ccl($cd, "(".$c->expr_pop($tdt). ", ".$c->true.")",
106 {err_msg => ''});
107 }
108 }
109  
110 27 ▶sub gen_any_or_all_of {
Subroutine gen_any_or_all_of: called CC=3 SCAR=11.0
Pod undocumented
111 27 my ($self, $which, $cd) = @_;
112 27 my $c = $self->compiler;
113 27 my $cv = $cd->{cl_value};
114 27 my $dt = $cd->{data_term};
115  
116 27 my $jccl;
117 {
118 27 local $cd->{ccls} = [];
119 27 for my $i (0..@$cv-1) {
120 54 local $cd->{spath} = [@{ $cd->{spath} }, $i];
121 54 my $sch = $cv->[$i];
122 54 my %iargs = %{$cd->{args}};
123 54 $iargs{outer_cd} = $cd;
124 54 $iargs{schema} = $sch;
125 54 $iargs{schema_is_normalized} = 0;
126 54 $iargs{cache} = $cd->{args}{cache};
127 54 $iargs{indent_level}++;
128 54 my $icd = $c->compile(%iargs);
129 my @code = (
130 $icd->{result},
131 54 );
132 54 $c->add_ccl($cd, join("", @code));
133 }
134 27 ▶ if ($which eq 'all') {
Branch: 1 branch
BranchTrueFalseTotal
if ($which eq 'all') { } 12 15 27
135 $jccl = $c->join_ccls(
136 12 $cd, $cd->{ccls}, {err_msg=>''});
137 } else {
138 $jccl = $c->join_ccls(
139 15 $cd, $cd->{ccls}, {err_msg=>'', op=>'or'});
140 }
141 }
142 27 $c->add_ccl($cd, $jccl);
143 }
144  
145 13 ▶sub clause_if {
Subroutine clause_if: called CC=4 SCAR=14.1
Pod undocumented
146 13 my ($self, $cd) = @_;
147 13 my $c = $self->compiler;
148 13 my $cv = $cd->{cl_value};
149  
150 13 my ($cond, $then, $else) = @$cv;
151  
152 13 ▶ unless (!ref($cond) && ref($then) eq 'ARRAY' && !$else) {
Branch: 1 branch
BranchTrueFalseTotal
unless (not ref $cond and ref $then eq "ARRAY" and not $else) 0 13 13
Condition33%2/6
not ref $cond and ref $then eq "ARRAY" and not $else
!ll&&!rl&&r
0013
not ref $cond and ref $then eq "ARRAY"
!ll&&!rl&&r
0013
MC/DC0%0/3
not ref $cond and ref $then eq "ARRAY" and not $else
not ref $cond ref $then eq "ARRAY" not $else
Truth table25%1/4
not(A) and B and not(C)
A= not ref $condB= ref $then eq "ARRAY"C= not $else
ABCresult
0XX0
10X0
1100
1111
153 0 $c->_die($cd, "Sorry, for 'if' clause, I currently can only handle COND=str (expr), THEN=array (schema), and no ELSE");
154 }
155  
156 # COND
157 13 my $comp_cond = $c->expr($cd, $cond);
158  
159 # THEN
160 13 my $comp_then;
161 {
162 13 local $cd->{ccls} = [];
163 13 local $cd->{spath} = [@{ $cd->{spath} }, 'if'];
164 13 my $sch = $then;
165 13 my %iargs = %{$cd->{args}};
166 13 $iargs{outer_cd} = $cd;
167 13 $iargs{schema} = $sch;
168 13 $iargs{schema_is_normalized} = 0;
169 13 $iargs{cache} = $cd->{args}{cache};
170 13 $iargs{indent_level}++;
171 13 my $icd = $c->compile(%iargs);
172 my @code = (
173 $icd->{result},
174 13 );
175 13 $comp_then = join("", @code);
176 }
177  
178 $c->add_ccl(
179 13 $cd,
180 $c->expr_ternary($comp_cond, $comp_then, $c->true, {err_msg=>''}),
181 );
182 }
183  
184 46 1;
185 # ABSTRACT: Base class for programming-language emiting compiler's type handlers
186  
187 __END__
« Data/Sah/Compiler/human/TH/float.pm ↑ Summary Data/Sah/Compiler/human/TH/Comparable.pm »