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

filter: Statementstmt 100% 56 / 56 Branchbran 87.5% 7 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 93.5% 73 / 78 CC 9 SCAR 17.6
CC
9
Cov
97%
clause_of
9.0
BEGIN
1.0
BEGIN
1.0
CRAP 5.8
« Data/Sah/Compiler/human/TH/all.pm ↑ Summary Data/Sah/Compiler/human/TH/array.pm »
1 package Data::Sah::Compiler::human::TH::any;
2  
3 3 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 #use Log::Any '$log';
7  
8 3 ▶use Mo qw(build default);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Role::Tiny::With;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 extends 'Data::Sah::Compiler::human::TH';
12 3 with 'Data::Sah::Type::any';
13  
14 3 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
15 3 our $DATE = '2024-02-16'; # DATE
16 3 our $DIST = 'Data-Sah'; # DIST
17 3 our $VERSION = '0.917'; # VERSION
18  
19 16 ▶sub handle_type {
Subroutine handle_type: called CC=1 SCAR=0.0
Pod undocumented
20 # does not have a noun
21 }
22  
23 15 ▶sub clause_of {
Subroutine clause_of: called CC=9 SCAR=22.0
Pod undocumented
24 15 my ($self, $cd) = @_;
25 15 my $c = $self->compiler;
26 15 my $cv = $cd->{cl_value};
27  
28 15 my @result;
29 15 my $i = 0;
30 15 for my $cv2 (@$cv) {
31 30 local $cd->{spath} = [@{$cd->{spath}}, $i];
32 30 my %iargs = %{$cd->{args}};
33 30 $iargs{outer_cd} = $cd;
34 30 $iargs{schema} = $cv2;
35 30 $iargs{schema_is_normalized} = 0;
36 30 $iargs{cache} = $cd->{args}{cache};
37 30 my $icd = $c->compile(%iargs);
38 30 push @result, $icd->{ccls};
39 30 $i++;
40 }
41  
42 # can we say 'either NOUN1 or NOUN2 or NOUN3 ...'?
43 15 my $can = 1;
44 15 for my $r (@result) {
45 18 ▶ unless (@$r == 1 && $r->[0]{type} eq 'noun') {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$r == 1 and $r->[0]{"type"} eq "noun") 12 6 18
Condition66%2/3
@$r == 1 and $r->[0]{"type"} eq "noun"
!ll&&!rl&&r
1206
MC/DC50%1/2
@$r == 1 and $r->[0]{"type"} eq "noun"
@$r == 1 $r->[0]{"type"} eq "noun"
Truth table66%2/3
A and B
A= @$r == 1B= $r->[0]{"type"} eq "noun"
ABresult
0X0
100
111
46 12 $can = 0;
47 12 last;
48 }
49 }
50  
51 15 my $vals;
52 15 ▶ if ($can) {
Branch: 1 branch
BranchTrueFalseTotal
if ($can) { } 3 12 15
53 3 my $c0 = $c->_xlt($cd, '%(modal_verb)s be either %s');
54 3 my $awa = $c->_xlt($cd, 'or %s');
55 3 my $wb = $c->_xlt($cd, ' ');
56 3 my $fmt;
57 3 my $i = 0;
58 3 for my $r (@result) {
59 6 ▶ $fmt .= $i ? $wb . $awa : $c0;
Branch: 1 branch
BranchTrueFalseTotal
$i ? : 3 3 6
60 push @$vals, ref($r->[0]{text}) eq 'ARRAY' ?
61 6 ▶ $r->[0]{text}[0] : $r->[0]{text};
Branch: 1 branch
BranchTrueFalseTotal
ref $r->[0]{'text'} eq 'ARRAY' ? : 6 0 6
62 6 $i++;
63 }
64 3 $c->add_ccl($cd, {
65 fmt => $fmt,
66 vals => $vals,
67 xlt => 0,
68 type => 'noun',
69 });
70 } else {
71 12 $c->add_ccl($cd, {
72 type => 'list',
73 fmt => '%(modal_verb)s be one of the following',
74 items => [
75 @result,
76 ],
77 vals => [],
78 });
79 }
80 }
81  
82 3 1;
83 # ABSTRACT: perl's type handler for type "any"
84  
85 __END__
« Data/Sah/Compiler/human/TH/all.pm ↑ Summary Data/Sah/Compiler/human/TH/array.pm »