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