DateTime-Format-Natural
view release on metacpan or search on metacpan
lib/DateTime/Format/Natural.pm view on Meta::CPAN
sub _init_check
{
my $self = shift;
validate(@_, {
demand_future => {
# SCALARREF due to boolean.pm's implementation
type => BOOLEAN | SCALARREF,
optional => true,
callbacks => {
'mutually exclusive' => sub
{
return true unless exists $_[1]->{prefer_future};
die "prefer_future provided\n";
},
},
},
lang => {
type => SCALAR,
optional => true,
lib/DateTime/Format/Natural.pm view on Meta::CPAN
regex => qr!^(?:
(?: (?: [dmy]{1,4}[-./] ){2}[dmy]{1,4} )
|
(?: [dm]{1,2}/[dm]{1,2} )
)$!ix,
},
prefer_future => {
# SCALARREF due to boolean.pm's implementation
type => BOOLEAN | SCALARREF,
optional => true,
callbacks => {
'mutually exclusive' => sub
{
return true unless exists $_[1]->{demand_future};
die "demand_future provided\n";
},
},
},
time_zone => {
type => SCALAR | OBJECT,
optional => true,
callbacks => {
'valid timezone' => sub
{
my $val = shift;
if (blessed($val)) {
return $val->isa('DateTime::TimeZone');
}
else {
eval { DateTime::TimeZone->new(name => $val) };
return !$@;
}
}
},
},
daytime => {
type => HASHREF,
optional => true,
callbacks => {
'valid daytime' => sub
{
my $href = shift;
my %daytimes = map { $_ => true } qw(morning afternoon evening);
if (any { !$daytimes{$_} } keys %$href) {
die "spelling of daytime\n";
}
elsif (any { !defined $href->{$_} } keys %$href) {
die "undefined hour\n";
}
lib/DateTime/Format/Natural.pm view on Meta::CPAN
}
else {
return true;
}
}
},
},
datetime => {
type => OBJECT,
optional => true,
callbacks => {
'valid object' => sub
{
my $obj = shift;
blessed($obj) && $obj->isa('DateTime');
}
},
},
});
}
( run in 2.741 seconds using v1.01-cache-2.11-cpan-9b1e4054eb1 )