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 );
This module provides Moose type constraints and coercions for using Time::Piece objects as Moose attributes.
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.
Num
The number is interpreted as the seconds since the system epoch as accepted by localtime().
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.
'2012-12-31T23:59:59'
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.
A class type for Time::Seconds.
The number is interpreted as seconds in duration.
Time::Piece, MooseX::Types
Steven Lee, <stevenl at cpan.org>
<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.
To install MooseX::Types::Time::Piece, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::Types::Time::Piece
CPAN shell
perl -MCPAN -e shell install MooseX::Types::Time::Piece
For more information on module installation, please visit the detailed CPAN module installation guide.