| 1 | package Data::Sah::Compiler::js::TH::duration; | ||||||||||||||||||||||||||||||
| 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 | 1 | ▶ | use Scalar::Util qw(blessed looks_like_number); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||
| 15 | 1 | extends 'Data::Sah::Compiler::js::TH'; | |||||||||||||||||||||||||||||
| 16 | 1 | with 'Data::Sah::Type::duration'; | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub handle_type { | ||||||||||||||||||||||||||||
|
Subroutine
handle_type: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 19 | 0 | my ($self, $cd) = @_; | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||
| 21 | 0 | my $dt = $cd->{data_term}; | |||||||||||||||||||||||||||||
| 22 | 0 | $cd->{_ccl_check_type} = join( | |||||||||||||||||||||||||||||
| 23 | ' && ', | ||||||||||||||||||||||||||||||
| 24 | "typeof($dt) == 'number'", | ||||||||||||||||||||||||||||||
| 25 | "$dt >= 0", # disallow negative duration | ||||||||||||||||||||||||||||||
| 26 | "isFinite($dt)", # disallow infinite duration | ||||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub superclause_comparable { | ||||||||||||||||||||||||||||
|
Subroutine
superclause_comparable: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 31 | 0 | my ($self, $which, $cd) = @_; | |||||||||||||||||||||||||||||
| 32 | 0 | my $c = $self->compiler; | |||||||||||||||||||||||||||||
| 33 | 0 | my $cv = $cd->{cl_value}; | |||||||||||||||||||||||||||||
| 34 | 0 | my $ct = $cd->{cl_term}; | |||||||||||||||||||||||||||||
| 35 | 0 | my $dt = $cd->{data_term}; | |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ($which eq 'is') { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 38 | 0 | $c->add_ccl($cd, "$dt === $ct"); | |||||||||||||||||||||||||||||
| 39 | } elsif ($which eq 'in') { | ||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if ($cd->{cl_is_expr}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 41 | # i'm lazy, technical debt | ||||||||||||||||||||||||||||||
| 42 | 0 | $c->_die($cd, "duration's in clause with expression not yet supported"); | |||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||
| 44 | 0 | $ct = '['.join(', ', map { "+($_)" } @$cv).']'; | |||||||||||||||||||||||||||||
| 45 | 0 | $c->add_ccl($cd, "($ct).indexOf(+($dt)) > -1"); | |||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub superclause_sortable { | ||||||||||||||||||||||||||||
|
Subroutine
superclause_sortable: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 50 | 0 | my ($self, $which, $cd) = @_; | |||||||||||||||||||||||||||||
| 51 | 0 | my $c = $self->compiler; | |||||||||||||||||||||||||||||
| 52 | 0 | my $cv = $cd->{cl_value}; | |||||||||||||||||||||||||||||
| 53 | 0 | my $ct = $cd->{cl_term}; | |||||||||||||||||||||||||||||
| 54 | 0 | my $dt = $cd->{data_term}; | |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if ($cd->{cl_is_expr}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 57 | # i'm lazy, technical debt | ||||||||||||||||||||||||||||||
| 58 | 0 | $c->_die($cd, "duration's comparison with expression not yet supported"); | |||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ($which eq 'min') { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 62 | 0 | $c->add_ccl($cd, "$dt >= $cv"); | |||||||||||||||||||||||||||||
| 63 | } elsif ($which eq 'xmin') { | ||||||||||||||||||||||||||||||
| 64 | 0 | $c->add_ccl($cd, "$dt > $cv"); | |||||||||||||||||||||||||||||
| 65 | } elsif ($which eq 'max') { | ||||||||||||||||||||||||||||||
| 66 | 0 | $c->add_ccl($cd, "$dt <= $cv"); | |||||||||||||||||||||||||||||
| 67 | } elsif ($which eq 'xmax') { | ||||||||||||||||||||||||||||||
| 68 | 0 | $c->add_ccl($cd, "$dt < $cv"); | |||||||||||||||||||||||||||||
| 69 | } elsif ($which eq 'between') { | ||||||||||||||||||||||||||||||
| 70 | 0 | $c->add_ccl($cd, "$dt >= $cv->[0] && $dt <= $cv->[1]"); | |||||||||||||||||||||||||||||
| 71 | } elsif ($which eq 'xbetween') { | ||||||||||||||||||||||||||||||
| 72 | 0 | $c->add_ccl($cd, "$dt > $cv->[0] && $dt < $cv->[1]"); | |||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||
| 76 | 1 | 1; | |||||||||||||||||||||||||||||
| 77 | # ABSTRACT: js's type handler for type "date" | ||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||||||||||||