| 1 | package Data::Sah::Compiler::js::TH::num; | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | 3 | our $DATE = '2016-09-14'; # DATE | |||||||||||||||||||||||||||||
| 4 | 3 | our $VERSION = '0.87'; # VERSION | |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use 5.010; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 9 | #use Log::Any '$log'; | ||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Mo qw(build default); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Role::Tiny::With; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||
| 14 | 3 | extends 'Data::Sah::Compiler::js::TH'; | |||||||||||||||||||||||||||||
| 15 | 3 | with 'Data::Sah::Type::num'; | |||||||||||||||||||||||||||||
| 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 | 0 | my $dt = $cd->{data_term}; | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||
| 22 | 0 | $cd->{_ccl_check_type} = "(typeof($dt)=='number' || parseFloat($dt)==$dt)"; | |||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub before_all_clauses { | ||||||||||||||||||||||||||||
|
Subroutine
before_all_clauses: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 26 | 0 | my ($self, $cd) = @_; | |||||||||||||||||||||||||||||
| 27 | 0 | my $c = $self->compiler; | |||||||||||||||||||||||||||||
| 28 | 0 | my $dt = $cd->{data_term}; | |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||
| 30 | # XXX only do this when there are clauses | ||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||
| 32 | # convert non-number to number, if we need further testing like <, >=, etc. | ||||||||||||||||||||||||||||||
| 33 | 0 | $self->set_tmp_data_term( | |||||||||||||||||||||||||||||
| 34 | $cd, "typeof($dt)=='number' ? $dt : parseFloat($dt)"); | ||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub after_all_clauses { | ||||||||||||||||||||||||||||
|
Subroutine
after_all_clauses: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 38 | 0 | my ($self, $cd) = @_; | |||||||||||||||||||||||||||||
| 39 | 0 | my $c = $self->compiler; | |||||||||||||||||||||||||||||
| 40 | 0 | my $dt = $cd->{data_term}; | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||
| 42 | 0 | $self->restore_data_term($cd); | |||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub superclause_comparable { | ||||||||||||||||||||||||||||
|
Subroutine
superclause_comparable: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 46 | 0 | my ($self, $which, $cd) = @_; | |||||||||||||||||||||||||||||
| 47 | 0 | my $c = $self->compiler; | |||||||||||||||||||||||||||||
| 48 | 0 | my $ct = $cd->{cl_term}; | |||||||||||||||||||||||||||||
| 49 | 0 | my $dt = $cd->{data_term}; | |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ($which eq 'is') { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 52 | 0 | $c->add_ccl($cd, "$dt == $ct"); | |||||||||||||||||||||||||||||
| 53 | } elsif ($which eq 'in') { | ||||||||||||||||||||||||||||||
| 54 | 0 | $c->add_ccl($cd, "($ct).indexOf($dt) > -1"); | |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub superclause_sortable { | ||||||||||||||||||||||||||||
|
Subroutine
superclause_sortable: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 59 | 0 | my ($self, $which, $cd) = @_; | |||||||||||||||||||||||||||||
| 60 | 0 | my $c = $self->compiler; | |||||||||||||||||||||||||||||
| 61 | 0 | my $cv = $cd->{cl_value}; | |||||||||||||||||||||||||||||
| 62 | 0 | my $ct = $cd->{cl_term}; | |||||||||||||||||||||||||||||
| 63 | 0 | my $dt = $cd->{data_term}; | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ($which eq 'min') { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 66 | 0 | $c->add_ccl($cd, "$dt >= $ct"); | |||||||||||||||||||||||||||||
| 67 | } elsif ($which eq 'xmin') { | ||||||||||||||||||||||||||||||
| 68 | 0 | $c->add_ccl($cd, "$dt > $ct"); | |||||||||||||||||||||||||||||
| 69 | } elsif ($which eq 'max') { | ||||||||||||||||||||||||||||||
| 70 | 0 | $c->add_ccl($cd, "$dt <= $ct"); | |||||||||||||||||||||||||||||
| 71 | } elsif ($which eq 'xmax') { | ||||||||||||||||||||||||||||||
| 72 | 0 | $c->add_ccl($cd, "$dt < $ct"); | |||||||||||||||||||||||||||||
| 73 | } elsif ($which eq 'between') { | ||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ($cd->{cl_is_expr}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 75 | 0 | $c->add_ccl($cd, "$dt >= $ct\[0] && $dt <= $ct\[1]"); | |||||||||||||||||||||||||||||
| 76 | } else { | ||||||||||||||||||||||||||||||
| 77 | # simplify code | ||||||||||||||||||||||||||||||
| 78 | 0 | $c->add_ccl($cd, "$dt >= $cv->[0] && $dt <= $cv->[1]"); | |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||
| 80 | } elsif ($which eq 'xbetween') { | ||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | if ($cd->{cl_is_expr}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 82 | 0 | $c->add_ccl($cd, "$dt > $ct\[0] && $dt < $ct\[1]"); | |||||||||||||||||||||||||||||
| 83 | } else { | ||||||||||||||||||||||||||||||
| 84 | # simplify code | ||||||||||||||||||||||||||||||
| 85 | 0 | $c->add_ccl($cd, "$dt > $cv->[0] && $dt < $cv->[1]"); | |||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||
| 90 | 3 | 1; | |||||||||||||||||||||||||||||
| 91 | # ABSTRACT: js's type handler for type "num" | ||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||||||||||||