NAME
MooseX::Types::Time::Piece - Time::Piece type and coercions for Moose
SYNOPSIS
package Foo;
use Moose;
use MooseX::Types::Time::Piece qw( Time Duration );
has 'time' => (
is => 'rw',
isa => Time,
coerce => 1,
);
has 'duration' => (
is => 'rw',
isa => Duration,
coerce => 1,
);
# ...
my $f = Foo->new;
$f->time( Time::Piece->new ) # no coercion
$f->time( time() ); # coerce from Num
$f->time( '2012-12-31T23:59:59' ); # coerce from Str
$f->time( ['2012-12-31', '%Y-%m-%d'] ); # coerce from ArrayRef
$f->duration( Time::Seconds::ONE_DAY * 2 );
DESCRIPTION
This module provides Moose type constraints and coercions for using Time::Piece objects as Moose attributes.
EXPORTS
The following type constants provided by MooseX::Types must be explicitly imported. The full class name may also be used (as strings with quotes) without importing the constant declarations.
Time
A class type for Time::Piece.
- coerce from
Num
-
The number is interpreted as the seconds since the system epoch as accepted by localtime().
- coerce from
Str
-
The string is expected to be in ISO 8601 date/time format, e.g.
'2012-12-31T23:59:59'
. See also "YYYY-MM-DDThh:mm:ss" in Time::Piece. - coerce from
ArrayRef
-
The arrayref is expected to contain 2 string values, the time and the time format, as accepted by strptime().
An exception is thrown during coercion if the given time does not match the expected/given format, or the given time or format is invalid.
Duration
A class type for Time::Seconds.
SEE ALSO
AUTHOR
Steven Lee, <stevenl at cpan.org>
LICENSE AND COPYRIGHT
Copyright (C) 2012 Steven Lee
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.