version bump
[gitmo/MooseX-Types-DateTime.git] / lib / MooseX / Types / DateTime.pm
index 4d44aad..f2fc626 100644 (file)
@@ -5,13 +5,16 @@ package MooseX::Types::DateTime;
 use strict;
 use warnings;
 
-our $VERSION = "0.01";
+our $VERSION = "0.05";
 
 use DateTime ();
 use DateTime::Locale ();
 use DateTime::TimeZone ();
 
 use MooseX::Types::Moose qw/Num HashRef Str/;
+
+use namespace::clean;
+
 use MooseX::Types -declare => [qw( DateTime Duration TimeZone Locale Now )];
 
 class_type "DateTime";
@@ -33,45 +36,41 @@ subtype( Now,
     },
 );
 
+our %coercions = (
+    DateTime => [
+               from Num, via { 'DateTime'->from_epoch( epoch => $_ ) },
+               from HashRef, via { 'DateTime'->new( %$_ ) },
+               from Now, via { 'DateTime'->now },
+    ],
+    "DateTime::Duration" => [
+               from Num, via { DateTime::Duration->new( seconds => $_ ) },
+               from HashRef, via { DateTime::Duration->new( %$_ ) },
+    ],
+    "DateTime::TimeZone" => [
+               from Str, via { DateTime::TimeZone->new( name => $_ ) },
+    ],
+    "DateTime::Locale" => [
+        from Moose::Util::TypeConstraints::find_or_create_isa_type_constraint("Locale::Maketext"),
+        via { DateTime::Locale->load($_->language_tag) },
+        from Str, via { DateTime::Locale->load($_) },
+    ],
+);
+
 for my $type ( "DateTime", DateTime ) {
-    coerce $type => (
-               from Num,
-               via { 'DateTime'->from_epoch( epoch => $_ ) },
-               from HashRef,
-               via { 'DateTime'->new( %$_ ) },
-               Moose::Meta::TypeConstraint->new(
-                       name => "__ANON__",
-                       parent => find_type_constraint("Str"),
-                       constraint => sub { $_ eq 'now' },
-                       optimise_as => sub { no warnings 'uninitialized'; !ref($_[0]) and $_[0] eq 'now' },
-               ),
-               via { 'DateTime'->now },
-       );
+    coerce $type => @{ $coercions{DateTime} };
 }
 
 for my $type ( "DateTime::Duration", Duration ) {
-       coerce $type => (
-               from Num,
-               via { DateTime::Duration->new( seconds => $_ ) },
-               from HashRef,
-               via { DateTime::Duration->new( %$_ ) },
-       );
+    coerce $type => @{ $coercions{"DateTime::Duration"} };
 }
 
 for my $type ( "DateTime::TimeZone", TimeZone ) {
-       coerce $type => (
-               from Str,
-               via { DateTime::TimeZone->new( name => $_ ) },
-       );
-
+       coerce $type => @{ $coercions{"DateTime::TimeZone"} };
 }
 
-coerce "DateTime::Locale" => (
-    from Moose::Util::TypeConstraints::find_or_create_isa_type_constraint("Locale::Maketext"),
-    via { DateTime::Locale->load($_->language_tag) },
-    from Str,
-    via { DateTime::Locale->load($_) },
-);
+for my $type ( "DateTime::Locale", Locale ) {
+       coerce $type => @{ $coercions{"DateTime::Locale"} };
+}
 
 __PACKAGE__
 
@@ -187,15 +186,27 @@ Delegates to L<DateTime::TimeZone/new> with the string as the C<name> argument.
 
 =back
 
+=back
+
+=back
+
+=head1 SEE ALSO
+
+L<MooseX::Types::DateTimeX>
+
+L<DateTime>, L<DateTimeX::Easy>
+
 =head1 VERSION CONTROL
 
-L<http://code2.0beta.co.uk/moose/svn/MooseX-Types-DateTime/trunk>. Ask on
-#moose for commit bits.
+This module is maintained using git. You can get the latest version from
+L<git://github.com/nothingmuch/moosex-types-datetime.git>.
 
 =head1 AUTHOR
 
 Yuval Kogman E<lt>nothingmuch@woobling.orgE<gt>
 
+John Napiorkowski E<lt>jjn1056 at yahoo.comE<gt>
+
 =head1 COPYRIGHT
 
        Copyright (c) 2008 Yuval Kogman. All rights reserved