Data/Sah/Compiler/js/TH/bool.pm

filter: Statementstmt 37.2% 19 / 51 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 55.5% 5 / 9 Podpod 0.0% 0 / 4 totaltotal 28.5% 24 / 84 CC 11 SCAR 38.1
CC
11
Cov
27%
superclause_sortable
90.0
superclause_comparable
12.0
handle_type
2.0
CRAP 45.0
« Data/Sah/Compiler/js/TH/str.pm ↑ Summary Data/Sah/Compiler/js/TH/num.pm »
1 package Data::Sah::Compiler::js::TH::bool;
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::bool';
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} = "typeof($dt)=='boolean'";
23 }
24  
25 # TEMP: when we already implement clause value coercion, we can stop
26 # booleanizing it
27  
28 0 ▶sub superclause_comparable {
Subroutine superclause_comparable: not called CC=3 SCAR=24.8
Pod undocumented
29 0 my ($self, $which, $cd) = @_;
30 0 my $c = $self->compiler;
31 0 my $ct = $cd->{cl_term};
32 0 my $dt = $cd->{data_term};
33  
34 0 ▶ if ($which eq 'is') {
Branch: 2 branches
BranchTrueFalseTotal
if ($which eq 'is') { } 0 0 0
elsif ($which eq 'in') { } 0 0 0
35 0 $c->add_ccl($cd, "$dt == !!($ct)");
36 } elsif ($which eq 'in') {
37 0 $c->add_ccl($cd, "($ct).map(function(x){return !!x}).indexOf($dt) > -1");
38 #$c->add_ccl($cd, "$ct.indexOf($dt) > -1");
39 }
40 }
41  
42 0 ▶sub superclause_sortable {
Subroutine superclause_sortable: not called CC=9 SCAR=45.0
Pod undocumented
43 0 my ($self, $which, $cd) = @_;
44 0 my $c = $self->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 'min') {
Branch: 6 branches
BranchTrueFalseTotal
if ($which eq 'min') { } 0 0 0
elsif ($which eq 'xmin') { } 0 0 0
elsif ($which eq 'max') { } 0 0 0
elsif ($which eq 'xmax') { } 0 0 0
elsif ($which eq 'between') { } 0 0 0
elsif ($which eq 'xbetween') { } 0 0 0
50 0 $c->add_ccl($cd, "$dt >= !!($ct)");
51 } elsif ($which eq 'xmin') {
52 0 $c->add_ccl($cd, "$dt > !!($ct)");
53 } elsif ($which eq 'max') {
54 0 $c->add_ccl($cd, "$dt <= !!($ct)");
55 } elsif ($which eq 'xmax') {
56 0 $c->add_ccl($cd, "$dt < !!($ct)");
57 } elsif ($which eq 'between') {
58 0 ▶ if ($cd->{cl_is_expr}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cd->{'cl_is_expr'}) { } 0 0 0
59 0 $c->add_ccl($cd, "$dt >= !!(($ct)[0]) && ".
60 "$dt <= !!(($ct)[1])");
61 } else {
62 # simplify code
63 0 $c->add_ccl($cd, "$dt >= !!($cv->[0]) && ".
64 "$dt <= !!($cv->[1])");
65 }
66 } elsif ($which eq 'xbetween') {
67 0 ▶ if ($cd->{cl_is_expr}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cd->{'cl_is_expr'}) { } 0 0 0
68 0 $c->add_ccl($cd, "$dt > !!(($ct)[0]) && ".
69 "$dt < !!(($ct)[1])");
70 } else {
71 # simplify code
72 0 $c->add_ccl($cd, "$dt > !!($cv->[0]) && ".
73 "$dt < !!($cv->[1])");
74 }
75 }
76 }
77  
78 0 ▶sub clause_is_true {
Subroutine clause_is_true: not called CC=1 SCAR=6.9
Pod undocumented
79 0 my ($self, $cd) = @_;
80 0 my $c = $self->compiler;
81 0 my $ct = $cd->{cl_term};
82 0 my $dt = $cd->{data_term};
83  
84 0 $c->add_ccl($cd, "$ct ? $dt : !(".$c->expr_defined($ct).") ? true : !($dt)");
85 }
86  
87 1 1;
88 # ABSTRACT: js's type handler for type "bool"
89  
90 __END__
« Data/Sah/Compiler/js/TH/str.pm ↑ Summary Data/Sah/Compiler/js/TH/num.pm »