MooseX::Types::Date::Piece - Date::Piece type and coercions for Moose.
package Foo; use Moose; use MooseX::Types::Date::Piece qw( Date Duration ); has 'date' => ( is => 'ro', isa => Date, coerce => 1, ); has 'duration' => ( is => 'ro', isa => Duration, coerce => 1, ); # ... my $f = Foo->new( date => '2012-07-09', duration => '1day', );
This module provides Moose type constraints and coercions for using Date::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 Date::Piece.
Str
Uses "date" in Date::Piece, where the string is formatted as '2012-12-31' or '20121231'.
'2012-12-31'
'20121231'
ArrayRef
Uses "date" in Date::Piece, where the array is formatted as [2012, 12, 31].
[2012, 12, 31]
An exception is thrown if the value to be coerced is not in a valid format or if the date is invalid.
A class type for Date::Piece::Duration. Subtypes include day_unit, week_unit, month_unit and year_unit. These objects are normally created using the days, weeks, months and years constants and may be multiplied by an integer. They may also be used for date math by adding (or subtracting) them to Date::Piece objects. See "Year-Month-and-etc-units" in Date::Piece for more information.
Date::Piece::Duration
day_unit
week_unit
month_unit
year_unit
days
weeks
months
years
Date::Piece
The string must specify the number and unit, e.g. '1day', '2weeks', '3 months', '4 YEARS'.
'1day'
'2weeks'
'3 months'
'4 YEARS'
Int
The integer value will be interpreted as the number of days.
Date::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::Date::Piece, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::Types::Date::Piece
CPAN shell
perl -MCPAN -e shell install MooseX::Types::Date::Piece
For more information on module installation, please visit the detailed CPAN module installation guide.