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 => 'ro', isa => Time, coerce => 1, ); has 'duration' => ( is => 'ro', isa => Duration, coerce => 1, ); # ... my $f = Foo->new( datetime => '2012-12-31T23:59:59', 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.
Int
The Int value is interpreted as epoch seconds as provided by the time() function.
Str
Parses strings in ISO 8601 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 should contain a time string and a format string as accepted by strptime().
An exception is thrown if the time does not match the format, or the time or format is invalid.
A class type for Time::Seconds
The integer value will be interpreted as the number of seconds.
seconds
Time::Piece, Moose::Util::TypeConstraints, MooseX::Types
Steven Lee, <stevenl at cpan.org>
<stevenl at cpan.org>
Copyright © 2012 Steven Lee. All rights reserved.
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.