Commit | Line | Data |
4664d531 |
1 | #!/usr/bin/perl |
2 | |
3 | package MooseX::Types::DateTime; |
4 | |
5 | use strict; |
6 | use warnings; |
7 | |
8 | our $VERSION = "0.01"; |
9 | |
10 | use DateTime (); |
11 | use DateTime::Locale (); |
12 | use DateTime::TimeZone (); |
13 | |
14 | use Moose::Util::TypeConstraints; |
15 | |
16 | class_type "DateTime"; |
17 | class_type "DateTime::TimeZone"; |
18 | class_type "DateTime::Locale::root" => { name => "DateTime::Locale" }; |
19 | |
20 | coerce "DateTime" => ( |
21 | from "Int", |
22 | via { DateTime->from_epoch( epoch => $_ ) }, |
23 | ); |
24 | |
25 | coerce "DateTime::TimeZone" => ( |
26 | from "Str", |
27 | via { DateTime::TimeZone->new( name => $_ ) }, |
28 | ); |
29 | |
30 | coerce "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 | |
45 | MooseX::Types::DateTime - L<DateTime> related constraints and coercions for |
46 | Moose |
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 | |
62 | This module packages several L<Moose::Util::TypeConstraints> with coercions, |
63 | designed to work with the L<DateTime> suite of objects. |
64 | |
65 | =head1 CONSTRAINTS |
66 | |
67 | =over 4 |
68 | |
69 | =item L<DateTime> |
70 | |
71 | A coercion from C<Int> using L<DateTime/from_epoch> is defined. |
72 | |
73 | =item L<DateTime::Locale> |
74 | |
75 | Coerces from C<Str>, where the string is the language tag, e.g. C<en> etc. See |
76 | L<DateTime::Locale/load>. |
77 | |
78 | =item L<DateTime::TimeZone> |
79 | |
80 | Coerces from C<Str> where the string is any time zone name. |
81 | |
82 | The string may also be a number of special values (C<local>, C<floating>, |
83 | offsets, etc). See L<DateTime::TimeZone/USAGE> for details. |
84 | |
85 | =head1 VERSION CONTROL |
86 | |
87 | L<http://code2.0beta.co.uk/moose/svn/MooseX-Types-DateTime/trunk>. Ask on |
88 | #moose for commit bits. |
89 | |
90 | =head1 AUTHOR |
91 | |
92 | Yuval 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 |