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

NAME

MooseX::Types::Time::Piece - Time::Piece type and coercions for Moose

SYNOPSIS

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

DESCRIPTION

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

Time

A class type for Time::Piece.

coerce from Int

The Int value is interpreted as epoch seconds as provided by the time() function.

coerce from Str

Parses strings in ISO 8601 format, e.g. '2012-12-31T23:59:59'. See also "YYYY-MM-DDThh:mm:ss" in Time::Piece.

coerce from 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.

Duration

A class type for Time::Seconds

coerce from Int

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

SEE ALSO

Time::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.