-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch from Params::Validate to Params::CheckCompiler & Specio
- Loading branch information
Showing
9 changed files
with
485 additions
and
261 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
package DateTime::Types; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use parent 'Specio::Exporter'; | ||
|
||
use Specio 0.18; | ||
use Specio::Declare; | ||
use Specio::Library::Builtins -reexport; | ||
use Specio::Library::Numeric -reexport; | ||
use Specio::Library::String; | ||
|
||
any_can_type( | ||
'ConvertibleObject', | ||
methods => ['utc_rd_values'], | ||
); | ||
|
||
declare( | ||
'DayOfMonth', | ||
parent => t('Int'), | ||
inline => sub { | ||
$_[0]->parent->inline_check( $_[1] ) | ||
. " && $_[1] >= 1 && $_[1] <= 31"; | ||
}, | ||
); | ||
|
||
declare( | ||
'DayOfYear', | ||
parent => t('Int'), | ||
inline => sub { | ||
$_[0]->parent->inline_check( $_[1] ) | ||
. " && $_[1] >= 1 && $_[1] <= 366"; | ||
}, | ||
); | ||
|
||
object_isa_type( | ||
'Duration', | ||
class => 'DateTime::Duration', | ||
); | ||
|
||
enum( | ||
'EndOfMonthMode', | ||
values => [qw( wrap limit preserve )], | ||
); | ||
|
||
any_can_type( | ||
'Formatter', | ||
methods => ['format_datetime'], | ||
); | ||
|
||
my $locale_object = declare( | ||
'LocaleObject', | ||
parent => t('Object'), | ||
inline => sub { | ||
<<"EOF"; | ||
( | ||
$_[1]->isa('DateTime::Locale::FromData') | ||
|| $_[1]->isa('DateTime::Locale::Base') | ||
) | ||
EOF | ||
}, | ||
); | ||
|
||
union( | ||
'Locale', | ||
of => [ t('NonEmptySimpleStr'), $locale_object ], | ||
); | ||
|
||
my $time_zone_object = object_can_type( | ||
'TZObject', | ||
methods => [ | ||
qw( | ||
is_floating | ||
is_utc | ||
name | ||
offset_for_datetime | ||
short_name_for_datetime | ||
) | ||
], | ||
); | ||
|
||
declare( | ||
'TimeZone', | ||
of => [ t('NonEmptySimpleStr'), $time_zone_object ], | ||
); | ||
|
||
declare( | ||
'Hour', | ||
parent => t('PositiveOrZeroInt'), | ||
inline => sub { | ||
$_[0]->parent->inline_check( $_[1] ) | ||
. " && $_[1] >= 0 && $_[1] <= 23"; | ||
}, | ||
); | ||
|
||
declare( | ||
'Minute', | ||
parent => t('PositiveOrZeroInt'), | ||
inline => sub { | ||
$_[0]->parent->inline_check( $_[1] ) | ||
. " && $_[1] >= 0 && $_[1] <= 59"; | ||
}, | ||
); | ||
|
||
declare( | ||
'Month', | ||
parent => t('PositiveInt'), | ||
inline => sub { | ||
$_[0]->parent->inline_check( $_[1] ) | ||
. " && $_[1] >= 1 && $_[1] <= 12"; | ||
}, | ||
); | ||
|
||
declare( | ||
'Nanosecond', | ||
parent => t('PositiveOrZeroInt'), | ||
); | ||
|
||
declare( | ||
'Second', | ||
parent => t('PositiveOrZeroInt'), | ||
inline => sub { | ||
$_[0]->parent->inline_check( $_[1] ) | ||
. " && $_[1] >= 0 && $_[1] <= 61"; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
arodland
via email
|
||
}, | ||
); | ||
|
||
enum( | ||
'TruncationLevel', | ||
values => [ | ||
qw( | ||
year | ||
month | ||
day hour | ||
minute | ||
second | ||
nanosecond | ||
week | ||
local_week | ||
) | ||
], | ||
); | ||
|
||
declare( | ||
'Year', | ||
parent => t('Int'), | ||
); | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
I guess there is a good reason why a second can be
60
or61
?