MooseX::Types::Time::Piece - Time::Piece type and coercions for Moose
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 );
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.
A class type for Time::Piece.
The number is interpreted as the seconds since the system epoch as accepted by localtime().
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.
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.
A class type for Time::Seconds.
The number is interpreted as seconds in duration.
<stevenl at cpan.org>
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.