Data/Sah/Compiler/human/TH/array.pm

filter: Statementstmt 100% 74 / 74 Branchbran 66.6% 4 / 6 Conditioncond 33.3% 4 / 12 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 4 totaltotal 82.7% 91 / 110 CC 10 SCAR 17.5
CC
10
Cov
89%
clause_each_elem
10.3
clause_elems
2.0
BEGIN
1.0
CRAP 5.7
« Data/Sah/Compiler/human/TH/any.pm ↑ Summary Data/Sah/Compiler/perl/TH/num.pm »
1 package Data::Sah::Compiler::human::TH::array;
2  
3 9 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 #use Log::Any '$log';
7  
8 9 ▶use Mo qw(build default);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use Role::Tiny::With;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 9 extends 'Data::Sah::Compiler::human::TH';
12 9 with 'Data::Sah::Compiler::human::TH::Comparable';
13 9 with 'Data::Sah::Compiler::human::TH::HasElems';
14 9 with 'Data::Sah::Type::array';
15  
16 9 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
17 9 our $DATE = '2024-02-16'; # DATE
18 9 our $DIST = 'Data-Sah'; # DIST
19 9 our $VERSION = '0.917'; # VERSION
20  
21 407 ▶sub handle_type {
Subroutine handle_type: called CC=1 SCAR=0.0
Pod undocumented
22 407 my ($self, $cd) = @_;
23 407 my $c = $self->compiler;
24  
25 407 $c->add_ccl($cd, {
26 fmt => ["array", "arrays"],
27 type => 'noun',
28 });
29 }
30  
31 6 ▶sub clause_each_index {
Subroutine clause_each_index: called CC=1 SCAR=0.0
Pod undocumented
32 6 my ($self, $cd) = @_;
33 6 my $c = $self->compiler;
34 6 my $cv = $cd->{cl_value};
35  
36 6 my %iargs = %{$cd->{args}};
37 6 $iargs{outer_cd} = $cd;
38 6 $iargs{schema} = $cv;
39 6 $iargs{schema_is_normalized} = 0;
40 6 $iargs{cache} = $cd->{args}{cache};
41 6 my $icd = $c->compile(%iargs);
42  
43 $c->add_ccl($cd, {
44 type => 'list',
45 fmt => 'each array subscript %(modal_verb)s be',
46 items => [
47 $icd->{ccls},
48 6 ],
49 vals => [],
50 });
51 }
52  
53 33 ▶sub clause_each_elem {
Subroutine clause_each_elem: called CC=9 SCAR=23.3
Pod undocumented
54 33 my ($self, $cd) = @_;
55 33 my $c = $self->compiler;
56 33 my $cv = $cd->{cl_value};
57  
58 33 my %iargs = %{$cd->{args}};
59 33 $iargs{outer_cd} = $cd;
60 33 $iargs{schema} = $cv;
61 33 $iargs{schema_is_normalized} = 0;
62 33 $iargs{cache} = $cd->{args}{cache};
63 33 my $icd = $c->compile(%iargs);
64  
65 # can we say 'array of INOUNS', e.g. 'array of integers'?
66 33 ▶ if (@{$icd->{ccls}} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$icd->{"ccls"};} == 1) 26 7 33
67 26 my $c0 = $icd->{ccls}[0];
68 26 ▶ if ($c0->{type} eq 'noun' && ref($c0->{text}) eq 'ARRAY' &&
Branch: 1 branch
BranchTrueFalseTotal
if ($c0->{"type"} eq "noun" and ref $c0->{"text"} eq "ARRAY" and @{$c0->{"text"};} > 1 and @{$cd->{"ccls"};} and $cd->{"ccls"}[0]{"type"} eq "noun") 26 0 26
Condition33%4/12
$c0->{"type"} eq "noun" and ref $c0->{"text"} eq "ARRAY" and @{$c0->{"text"};} > 1 and @{$cd->{"ccls"};} and $cd->{"ccls"}[0]{"type"} eq "noun"
!ll&&!rl&&r
0026
$c0->{"type"} eq "noun" and ref $c0->{"text"} eq "ARRAY" and @{$c0->{"text"};} > 1 and @{$cd->{"ccls"};}
!ll&&!rl&&r
0026
$c0->{"type"} eq "noun" and ref $c0->{"text"} eq "ARRAY" and @{$c0->{"text"};} > 1
!ll&&!rl&&r
0026
$c0->{"type"} eq "noun" and ref $c0->{"text"} eq "ARRAY"
!ll&&!rl&&r
0026
MC/DC0%0/5
$c0->{"type"} eq "noun" and ref $c0->{"text"} eq "ARRAY" and @{$c0->{"text"};} > 1 and @{$cd->{"ccls"};} and $cd->{"ccls"}[0]{"type"} eq "noun"
$c0->{"type"} eq "noun" ref $c0->{"text"} eq "ARRAY" @{$c0->{"text"};} > 1 @{$cd->{"ccls"};} $cd->{"ccls"}[0]{"type"} eq "noun"
Truth table16%1/6
A and B and C and D and E
A= $c0->{"type"} eq "noun"B= ref $c0->{"text"} eq "ARRAY"C= @{$c0->{"text"};} > 1D= @{$cd->{"ccls"};}E= $cd->{"ccls"}[0]{"type"} eq "noun"
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
69 26 @{$c0->{text}} > 1 && @{$cd->{ccls}} &&
70 $cd->{ccls}[0]{type} eq 'noun') {
71 26 ▶ for (ref($cd->{ccls}[0]{text}) eq 'ARRAY' ?
Branch: 1 branch
BranchTrueFalseTotal
ref $cd->{'ccls'}[0]{'text'} eq 'ARRAY' ? : 26 0 26
72 26 @{$cd->{ccls}[0]{text}} : ($cd->{ccls}[0]{text})) {
73 52 my $fmt = $c->_xlt($cd, '%s of %s');
74 52 $_ = sprintf $fmt, $_, $c0->{text}[1];
75 }
76 26 return;
77 }
78 }
79  
80 # nope, we can't
81 $c->add_ccl($cd, {
82 type => 'list',
83 fmt => 'each array element %(modal_verb)s be',
84 items => [
85 $icd->{ccls},
86 7 ],
87 vals => [],
88 });
89 }
90  
91 32 ▶sub clause_elems {
Subroutine clause_elems: called CC=2 SCAR=6.9
Pod undocumented
92 32 my ($self, $cd) = @_;
93 32 my $c = $self->compiler;
94 32 my $cv = $cd->{cl_value};
95  
96 32 for my $i (0..@$cv-1) {
97 62 local $cd->{spath} = [@{$cd->{spath}}, $i];
98 62 my $v = $cv->[$i];
99 62 my %iargs = %{$cd->{args}};
100 62 $iargs{outer_cd} = $cd;
101 62 $iargs{schema} = $v;
102 62 $iargs{schema_is_normalized} = 0;
103 62 $iargs{cache} = $cd->{args}{cache};
104 62 my $icd = $c->compile(%iargs);
105 $c->add_ccl($cd, {
106 type => 'list',
107 fmt => '%s %(modal_verb)s be',
108 vals => [
109 $c->_ordinate($cd, $i+1, $c->_xlt($cd, "element")),
110 ],
111 62 items => [ $icd->{ccls} ],
112 });
113 }
114 }
115  
116 9 1;
117 # ABSTRACT: human's type handler for type "array"
118  
119 __END__
« Data/Sah/Compiler/human/TH/any.pm ↑ Summary Data/Sah/Compiler/perl/TH/num.pm »