| 1 | package Data::Sah::Compiler::perl::TH::timeofday; | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.010; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | #use Log::Any '$log'; | ||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Mo qw(build default); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Role::Tiny::With; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Scalar::Util qw(blessed looks_like_number); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||
| 12 | 2 | extends 'Data::Sah::Compiler::perl::TH'; | |||||||||||||||||||||||||||||
| 13 | 2 | with 'Data::Sah::Type::timeofday'; | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||
| 15 | 2 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||||
| 16 | 2 | our $DATE = '2024-02-16'; # DATE | |||||||||||||||||||||||||||||
| 17 | 2 | our $DIST = 'Data-Sah'; # DIST | |||||||||||||||||||||||||||||
| 18 | 2 | our $VERSION = '0.917'; # VERSION | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||
| 20 | 8 | ▶ | sub handle_type { | ||||||||||||||||||||||||||||
|
Subroutine
handle_type: called CC=5 SCAR=20.4
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 21 | 8 | my ($self, $cd) = @_; | |||||||||||||||||||||||||||||
| 22 | 8 | my $c = $self->compiler; | |||||||||||||||||||||||||||||
| 23 | 8 | my $dt = $cd->{data_term}; | |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||
| 25 | 8 | ▶ | $cd->{coerce_to} = $cd->{nschema}[1]{"x.perl.coerce_to"} // 'str_hms'; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$cd->{"nschema"}[1]{"x.perl.coerce_to"} // "str_hms"
MC/DC0%0/1
$cd->{"nschema"}[1]{"x.perl.coerce_to"} // "str_hms"
$cd->{"nschema"}[1]{"x.perl.coerce_to"}
Truth table50%1/2
A
A= $cd->{"nschema"}[1]{"x.perl.coerce_to"}
| |||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||
| 27 | 8 | my $coerce_to = $cd->{coerce_to}; | |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||
| 29 | 8 | ▶ | if ($coerce_to eq 'float') { | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 30 | 0 | $cd->{_ccl_check_type} = "!ref($dt) && $dt >= 0 && $dt < 86400"; | |||||||||||||||||||||||||||||
| 31 | } elsif ($coerce_to eq 'str_hms') { | ||||||||||||||||||||||||||||||
| 32 | 8 | $cd->{_ccl_check_type} = "$dt =~ /\\A([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})(?:\\.[0-9]{1,9})?\\z/"; | |||||||||||||||||||||||||||||
| 33 | } elsif ($coerce_to eq 'Date::TimeOfDay') { | ||||||||||||||||||||||||||||||
| 34 | 0 | $c->add_runtime_module($cd, 'Scalar::Util'); | |||||||||||||||||||||||||||||
| 35 | 0 | $cd->{_ccl_check_type} = "Scalar::Util::blessed($dt) && $dt\->isa('Date::TimeOfDay')"; | |||||||||||||||||||||||||||||
| 36 | } else { | ||||||||||||||||||||||||||||||
| 37 | 0 | die "BUG: Unknown coerce_to value '$coerce_to', use either ". | |||||||||||||||||||||||||||||
| 38 | "float, str_hms, or Date::TimeOfDay"; | ||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub superclause_comparable { | ||||||||||||||||||||||||||||
|
Subroutine
superclause_comparable: not called CC=11 SCAR=48.8
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 ($cd->{cl_is_expr}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 50 | # i'm lazy, technical debt | ||||||||||||||||||||||||||||||
| 51 | 0 | $c->_die($cd, "timeofday's comparison with expression not yet supported"); | |||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||
| 54 | 0 | my $coerce_to = $cd->{coerce_to}; | |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if ($coerce_to eq 'float') { | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if ($which eq 'is') { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 57 | 0 | $c->add_ccl($cd, "$dt == $ct"); | |||||||||||||||||||||||||||||
| 58 | } elsif ($which eq 'in') { | ||||||||||||||||||||||||||||||
| 59 | 0 | $c->add_runtime_module($cd, 'List::Util'); | |||||||||||||||||||||||||||||
| 60 | 0 | $c->add_ccl($cd, "List::Util::first(sub{$dt == \$_}, $ct)"); | |||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||
| 62 | } elsif ($coerce_to eq 'str_hms') { | ||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ($which eq 'is') { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 64 | 0 | $c->add_ccl($cd, "$dt eq $ct"); | |||||||||||||||||||||||||||||
| 65 | } elsif ($which eq 'in') { | ||||||||||||||||||||||||||||||
| 66 | 0 | $c->add_runtime_module($cd, 'List::Util'); | |||||||||||||||||||||||||||||
| 67 | 0 | $c->add_ccl($cd, "List::Util::first(sub{$dt eq \$_}, $ct)"); | |||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||
| 69 | } elsif ($coerce_to eq 'Date::TimeOfDay') { | ||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if ($which eq 'is') { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 71 | 0 | $c->add_ccl($cd, "Date::TimeOfDay->compare($dt, $ct)==0"); | |||||||||||||||||||||||||||||
| 72 | } elsif ($which eq 'in') { | ||||||||||||||||||||||||||||||
| 73 | 0 | $c->add_runtime_module($cd, 'List::Util'); | |||||||||||||||||||||||||||||
| 74 | 0 | $c->add_ccl($cd, "List::Util::first(sub{Date::TimeOfDay->compare($dt, \$_)==0}, $ct)"); | |||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||
| 79 | 4 | ▶ | sub superclause_sortable { | ||||||||||||||||||||||||||||
|
Subroutine
superclause_sortable: called CC=23 SCAR=55.8
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 80 | 4 | my ($self, $which, $cd) = @_; | |||||||||||||||||||||||||||||
| 81 | 4 | my $c = $self->compiler; | |||||||||||||||||||||||||||||
| 82 | 4 | my $cv = $cd->{cl_value}; | |||||||||||||||||||||||||||||
| 83 | 4 | my $ct = $cd->{cl_term}; | |||||||||||||||||||||||||||||
| 84 | 4 | my $dt = $cd->{data_term}; | |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||
| 86 | 4 | ▶ | if ($cd->{cl_is_expr}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 87 | # i'm lazy, technical debt | ||||||||||||||||||||||||||||||
| 88 | 0 | $c->_die($cd, "timeofday's comparison with expression not yet supported"); | |||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||
| 91 | 4 | my $coerce_to = $cd->{coerce_to}; | |||||||||||||||||||||||||||||
| 92 | 4 | ▶ | if ($coerce_to eq 'float') { | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if ($which eq 'min') { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 94 | 0 | $c->add_ccl($cd, "$dt >= $cv"); | |||||||||||||||||||||||||||||
| 95 | } elsif ($which eq 'xmin') { | ||||||||||||||||||||||||||||||
| 96 | 0 | $c->add_ccl($cd, "$dt > $cv"); | |||||||||||||||||||||||||||||
| 97 | } elsif ($which eq 'max') { | ||||||||||||||||||||||||||||||
| 98 | 0 | $c->add_ccl($cd, "$dt <= $cv"); | |||||||||||||||||||||||||||||
| 99 | } elsif ($which eq 'xmax') { | ||||||||||||||||||||||||||||||
| 100 | 0 | $c->add_ccl($cd, "$dt < $cv"); | |||||||||||||||||||||||||||||
| 101 | } elsif ($which eq 'between') { | ||||||||||||||||||||||||||||||
| 102 | 0 | $c->add_ccl($cd, "$dt >= $cv->[0] && $dt <= $cv->[1]"); | |||||||||||||||||||||||||||||
| 103 | } elsif ($which eq 'xbetween') { | ||||||||||||||||||||||||||||||
| 104 | 0 | $c->add_ccl($cd, "$dt > $cv->[0] && $dt < $cv->[1]"); | |||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||
| 106 | } elsif ($coerce_to eq 'str_hms') { | ||||||||||||||||||||||||||||||
| 107 | 4 | ▶ | if ($which eq 'min') { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 108 | 3 | $c->add_ccl($cd, "$dt ge '$cv'"); | |||||||||||||||||||||||||||||
| 109 | } elsif ($which eq 'xmin') { | ||||||||||||||||||||||||||||||
| 110 | 1 | $c->add_ccl($cd, "$dt gt '$cv'"); | |||||||||||||||||||||||||||||
| 111 | } elsif ($which eq 'max') { | ||||||||||||||||||||||||||||||
| 112 | 0 | $c->add_ccl($cd, "$dt le '$cv'"); | |||||||||||||||||||||||||||||
| 113 | } elsif ($which eq 'xmax') { | ||||||||||||||||||||||||||||||
| 114 | 0 | $c->add_ccl($cd, "$dt lt '$cv'"); | |||||||||||||||||||||||||||||
| 115 | } elsif ($which eq 'between') { | ||||||||||||||||||||||||||||||
| 116 | 0 | $c->add_ccl($cd, "$dt ge '$cv->[0]' && $dt le '$cv->[1]'"); | |||||||||||||||||||||||||||||
| 117 | } elsif ($which eq 'xbetween') { | ||||||||||||||||||||||||||||||
| 118 | 0 | $c->add_ccl($cd, "$dt gt '$cv->[0]' && $dt lt '$cv->[1]'"); | |||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||
| 120 | } elsif ($coerce_to eq 'Date::TimeOfDay') { | ||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if ($which eq 'min') { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 122 | 0 | $c->add_ccl($cd, "Date::TimeOfDay->compare($dt, $cv) >= 0"); | |||||||||||||||||||||||||||||
| 123 | } elsif ($which eq 'xmin') { | ||||||||||||||||||||||||||||||
| 124 | 0 | $c->add_ccl($cd, "Date::TimeOfDay->compare($dt, $cv) > 0"); | |||||||||||||||||||||||||||||
| 125 | } elsif ($which eq 'max') { | ||||||||||||||||||||||||||||||
| 126 | 0 | $c->add_ccl($cd, "Date::TimeOfDay->compare($dt, $cv) <= 0"); | |||||||||||||||||||||||||||||
| 127 | } elsif ($which eq 'xmax') { | ||||||||||||||||||||||||||||||
| 128 | 0 | $c->add_ccl($cd, "Date::TimeOfDay->compare($dt, $cv) < 0"); | |||||||||||||||||||||||||||||
| 129 | } elsif ($which eq 'between') { | ||||||||||||||||||||||||||||||
| 130 | 0 | $c->add_ccl($cd, "Date::TimeOfDay->compare($dt, $cv\->[0]) >= 0 && Date::TimeOfDay->compare($dt, $ct\->[1]) <= 0"); | |||||||||||||||||||||||||||||
| 131 | } elsif ($which eq 'xbetween') { | ||||||||||||||||||||||||||||||
| 132 | 0 | $c->add_ccl($cd, "Date::TimeOfDay->compare($dt, $cv\->[0]) > 0 && Date::TimeOfDay->compare($dt, $ct\->[1]) < 0"); | |||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||
| 137 | 2 | 1; | |||||||||||||||||||||||||||||
| 138 | # ABSTRACT: perl's type handler for type "timeofday" | ||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||
| 140 | __END__ | ||||||||||||||||||||||||||||||