The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MooseX::Types::Date::Piece - Date::Piece type and coercions for Moose.

SYNOPSIS

    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',
    );

DESCRIPTION

This module provides Moose type constraints and coercions for using Date::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.

Date

A class type for Date::Piece.

coerce from Str

Uses "date" in Date::Piece, where the string is formatted as '2012-12-31' or '20121231'.

coerce from ArrayRef

Uses "date" in Date::Piece, where the array is formatted as [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.

Duration

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.

coerce from Str

The string must specify the number and unit, e.g. '1day', '2weeks', '3 months', '4 YEARS'.

coerce from Int

The integer value will be interpreted as the number of days.

SEE ALSO

Date::Piece, Moose::Util::TypeConstraints, MooseX::Types

AUTHOR

Steven Lee, <stevenl at cpan.org>

LICENSE AND COPYRIGHT

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.