| 1 | package Data::Sah::Compiler::perl::TH::array; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use Log::ger; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use Mo qw(build default); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use Role::Tiny::With; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 7 | extends 'Data::Sah::Compiler::perl::TH'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 7 | with 'Data::Sah::Type::array'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 7 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 7 | our $DATE = '2024-02-16'; # DATE | |||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 7 | our $DIST = 'Data-Sah'; # DIST | |||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 7 | our $VERSION = '0.917'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 403 | ▶ | sub handle_type { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 403 | my ($self, $cd) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 403 | my $c = $self->compiler; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 403 | my $dt = $cd->{data_term}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 403 | $cd->{_ccl_check_type} = "ref($dt) eq 'ARRAY'"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 288 | ▶ | sub superclause_comparable { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
superclause_comparable: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 288 | my ($self, $which, $cd) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 288 | my $c = $self->compiler; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 288 | my $ct = $cd->{cl_term}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 288 | my $dt = $cd->{data_term}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 288 | $c->add_runtime_module($cd, $cd->{args}{dump_module}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 288 | ▶ | if ($which eq 'is') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 150 | $c->add_ccl($cd, $c->expr_dump($cd, $dt).' eq '.$c->expr_dump($cd, $ct)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } elsif ($which eq 'in') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 138 | $c->add_ccl($cd, "do { my \$_sahv_dt_str = ".$c->expr_dump($cd, $dt)."; my \$_sahv_res = 0; " . | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | "for my \$_sahv_el (\@{ $ct }) { my \$_sahv_el_str = ".$c->expr_dump($cd, "\$_sahv_el")."; ". | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | "if (\$_sahv_dt_str eq \$_sahv_el_str) { \$_sahv_res = 1; last } } \$_sahv_res }"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 123 | ▶ | sub superclause_has_elems { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
superclause_has_elems: called CC=17 SCAR=32.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 123 | my ($self_th, $which, $cd) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 123 | my $c = $self_th->compiler; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 123 | my $cv = $cd->{cl_value}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 123 | my $ct = $cd->{cl_term}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 123 | my $dt = $cd->{data_term}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 123 | ▶ | if ($which eq 'len') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 11 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 6 | $c->add_ccl($cd, "\@{$dt} == $ct"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } elsif ($which eq 'min_len') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 34 | $c->add_ccl($cd, "\@{$dt} >= $ct"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } elsif ($which eq 'max_len') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 21 | $c->add_ccl($cd, "\@{$dt} <= $ct"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } elsif ($which eq 'len_between') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 6 | ▶ | if ($cd->{cl_is_expr}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $c->add_ccl( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | $cd, "\@{$dt} >= $ct\->[0] && \@{$dt} >= $ct\->[1]"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # simplify code | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 6 | $c->add_ccl( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | $cd, "\@{$dt} >= $cv->[0] && \@{$dt} <= $cv->[1]"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } elsif ($which eq 'has') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 19 | $c->add_runtime_module($cd, $cd->{args}{dump_module}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 19 | $c->add_ccl($cd, "do { my \$_sahv_ct_str = ".$c->expr_dump($cd, $ct)."; my \$_sahv_res = 0; " . | |||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | "for my \$_sahv_el (\@{ $dt }) { my \$_sahv_el_str = ".$c->expr_dump($cd, "\$_sahv_el")."; ". | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | "if (\$_sahv_ct_str eq \$_sahv_el_str) { \$_sahv_res = 1; last } } \$_sahv_res }"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } elsif ($which eq 'each_index') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 6 | ▶ | $self_th->set_tmp_data_term($cd) if $cd->{args}{data_term_includes_topic_var}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 6 | $self_th->gen_each($cd, "0..\@{$cd->{data_term}}-1", '_', '$_'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 6 | ▶ | $self_th->restore_data_term($cd) if $cd->{args}{data_term_includes_topic_var}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } elsif ($which eq 'each_elem') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 31 | ▶ | $self_th->set_tmp_data_term($cd) if $cd->{args}{data_term_includes_topic_var}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 31 | $self_th->gen_each($cd, "0..\@{$cd->{data_term}}-1", '_', "$cd->{data_term}\->[\$_]"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 31 | ▶ | $self_th->restore_data_term($cd) if $cd->{args}{data_term_includes_topic_var}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } elsif ($which eq 'check_each_index') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $self_th->compiler->_die_unimplemented_clause($cd); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } elsif ($which eq 'check_each_elem') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $self_th->compiler->_die_unimplemented_clause($cd); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } elsif ($which eq 'uniq') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $self_th->compiler->_die_unimplemented_clause($cd, "for now you can use eData::Sah::Filter::perl::Array::check_uniq instead"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } elsif ($which eq 'exists') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $self_th->compiler->_die_unimplemented_clause($cd); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 30 | ▶ | sub clause_elems { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clause_elems: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 30 | require Data::Sah::Normalize; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 30 | my ($self_th, $cd) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 30 | my $c = $self_th->compiler; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 30 | my $cv = $cd->{cl_value}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 30 | my $dt = $cd->{data_term}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 30 | local $cd->{_subdata_level} = $cd->{_subdata_level} + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 30 | my $jccl; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 30 | local $cd->{ccls} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 30 | ▶ | my $cdef = $cd->{clset}{"elems.create_default"} // 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$cd->{"clset"}{"elems.create_default"} // 1
MC/DC100%1/1
$cd->{"clset"}{"elems.create_default"} // 1
$cd->{"clset"}{"elems.create_default"}
Truth table100%2/2
A
A= $cd->{"clset"}{"elems.create_default"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 30 | delete $cd->{uclset}{"elems.create_default"}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 30 | for my $i (0..@$cv-1) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 60 | local $cd->{spath} = [@{$cd->{spath}}, $i]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 60 | my $nsch = Data::Sah::Normalize::normalize_schema($cv->[$i]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 60 | my $edt = "$dt\->[$i]"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 60 | my %iargs = %{$cd->{args}}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 60 | $iargs{outer_cd} = $cd; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 60 | $iargs{data_name} = "$cd->{args}{data_name}_$i"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 60 | $iargs{data_term} = $edt; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 60 | $iargs{schema} = $nsch; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 60 | $iargs{schema_is_normalized} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 60 | $iargs{cache} = $cd->{args}{cache}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 60 | $iargs{indent_level}++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 60 | my $icd = $c->compile(%iargs); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | my @code = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | ($c->indent_str($cd), "(\$_sahv_dpath->[-1] = $i),\n") x !!$cd->{use_dpath}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 60 | $icd->{result}, "\n", | |||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 60 | my $ires = join("", @code); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 60 | local $cd->{_debug_ccl_note} = "elem: $i"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 60 | ▶ | if ($cdef && defined($nsch->[1]{default})) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$cdef and defined $nsch->[1]{"default"}
MC/DC100%2/2
$cdef and defined $nsch->[1]{"default"}
$cdef
defined $nsch->[1]{"default"}
Truth table100%3/3
A and B
A= $cdefB= defined $nsch->[1]{"default"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 18 | $c->add_ccl($cd, $ires); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 42 | $c->add_ccl($cd, "\@{$dt} < ".($i+1)." || ($ires)"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | $jccl = $c->join_ccls( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 30 | $cd, $cd->{ccls}, {err_msg => ''}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 30 | $c->add_ccl($cd, $jccl, {subdata=>1}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # ABSTRACT: perl's type handler for type "array" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||