MooseX::Types::DateTime
[gitmo/MooseX-Types-DateTime.git] / lib / MooseX / Types / DateTime.pm
CommitLineData
4664d531 1#!/usr/bin/perl
2
3package MooseX::Types::DateTime;
4
5use strict;
6use warnings;
7
8our $VERSION = "0.01";
9
10use DateTime ();
11use DateTime::Locale ();
12use DateTime::TimeZone ();
13
14use Moose::Util::TypeConstraints;
15
16class_type "DateTime";
17class_type "DateTime::TimeZone";
18class_type "DateTime::Locale::root" => { name => "DateTime::Locale" };
19
20coerce "DateTime" => (
21 from "Int",
22 via { DateTime->from_epoch( epoch => $_ ) },
23);
24
25coerce "DateTime::TimeZone" => (
26 from "Str",
27 via { DateTime::TimeZone->new( name => $_ ) },
28);
29
30coerce "DateTime::Locale" => (
31 from Moose::Util::TypeConstraints::find_or_create_isa_type_constraint("Locale::Maketext"),
32 via { DateTime::Locale->load($_->language_tag) },
33 from "Str",
34 via { DateTime::Locale->load($_) },
35);
36
37__PACKAGE__
38
39__END__
40
41=pod
42
43=head1 NAME
44
45MooseX::Types::DateTime - L<DateTime> related constraints and coercions for
46Moose
47
48=head1 SYNOPSIS
49
50 use MooseX::Types::DateTime;
51
52 has time_zone => (
53 isa => "DateTime::TimeZone",
54 is => "rw",
55 coerce => 1,
56 );
57
58 Class->new( time_zone => "Africa/Timbuktu" );
59
60=head1 DESCRIPTION
61
62This module packages several L<Moose::Util::TypeConstraints> with coercions,
63designed to work with the L<DateTime> suite of objects.
64
65=head1 CONSTRAINTS
66
67=over 4
68
69=item L<DateTime>
70
71A coercion from C<Int> using L<DateTime/from_epoch> is defined.
72
73=item L<DateTime::Locale>
74
75Coerces from C<Str>, where the string is the language tag, e.g. C<en> etc. See
76L<DateTime::Locale/load>.
77
78=item L<DateTime::TimeZone>
79
80Coerces from C<Str> where the string is any time zone name.
81
82The string may also be a number of special values (C<local>, C<floating>,
83offsets, etc). See L<DateTime::TimeZone/USAGE> for details.
84
85=head1 VERSION CONTROL
86
87L<http://code2.0beta.co.uk/moose/svn/MooseX-Types-DateTime/trunk>. Ask on
88#moose for commit bits.
89
90=head1 AUTHOR
91
92Yuval Kogman E<lt>nothingmuch@woobling.orgE<gt>
93
94=head1 COPYRIGHT
95
96 Copyright (c) 2008 Yuval Kogman. All rights reserved
97 This program is free software; you can redistribute
98 it and/or modify it under the same terms as Perl itself.
99
100=cut