Remove stray "to" from caveats POD
[gitmo/MooseX-Types-DateTime-MoreCoercions.git] / lib / MooseX / Types / DateTime / MoreCoercions.pm
CommitLineData
00d7c0c9 1package MooseX::Types::DateTime::MoreCoercions;
de827165 2use strict;
3use warnings;
4
c4bf22a0 5use Moose 0.41 ();
6use DateTime 0.4302 ();
7use DateTime::Duration 0.4302 ();
8use DateTimeX::Easy 0.085 ();
9use Time::Duration::Parse 0.06 qw(parse_duration);
10use MooseX::Types::DateTime 0.07 ();
11use MooseX::Types::Moose 0.04 qw/Num HashRef Str/;
de827165 12
c4bf22a0 13use namespace::clean 0.08;
de827165 14
736d2c28 15our $VERSION = '0.10';
de827165 16
c4bf22a0 17use MooseX::Types 0.04 -declare => [qw( DateTime Duration)];
de827165 18
e18dcdf2 19subtype DateTime, as MooseX::Types::DateTime::DateTime;
de827165 20coerce( DateTime,
a7c573a0 21 @{ MooseX::Types::DateTime::DateTime->coercion->type_coercion_map },
de827165 22 from Str, via { DateTimeX::Easy->new($_) },
23);
24
e18dcdf2 25subtype Duration, as MooseX::Types::DateTime::Duration;
de827165 26coerce( Duration,
a7c573a0 27 @{ MooseX::Types::DateTime::Duration->coercion->type_coercion_map },
de827165 28 from Str, via {
29 DateTime::Duration->new(
30 seconds => parse_duration($_)
31 );
32 },
33);
34
351;
36
37__END__
38
39=head1 NAME
40
00d7c0c9 41MooseX::Types::DateTime::MoreCoercions - Extensions to L<MooseX::Types::DateTime>
de827165 42
43=head1 SYNOPSIS
44
45 package MyApp::MyClass;
46
00d7c0c9 47 use MooseX::Types::DateTime::MoreCoercions qw( DateTime );
de827165 48
49 has created => (
50 isa => DateTime,
51 is => "rw",
52 coerce => 1,
53 );
54
55 my $instance = MyApp::MyClass->new(created=>'January 1, 1980');
56 print $instance->created->year; # is 1980
57
58 ## Coercions from the base type continue to work as normal.
59 my $instance = MyApp::MyClass->new(created=>{year=>2000,month=>1,day=>10});
60
61Please see the test case for more example usage.
62
63=head1 DESCRIPTION
64
65This module builds on L<MooseX::Types::DateTime> to add additional custom types and coercions. Since it builds on an existing type, all coercions and constraints are inherited.
66
de827165 67=head1 SUBTYPES
68
69This module defines the following additional subtypes.
70
71=head2 DateTime
72
00d7c0c9 73Subtype of L<MooseX::Types::DateTime/DateTime>. Adds an additional coercion from strings.
de827165 74
75Uses L<DateTimeX::Easy> to try and convert strings, like "yesterday" into a valid L<DateTime> object. Please note that due to ambiguity with how different systems might localize their timezone, string parsing may not always return the most expected value. IN general we try to localize to UTC whenever possible. Feedback welcomed!
76
77=head2 Duration
78
00d7c0c9 79Subtype of L<MooseX::Types::DateTime/Duration> that coerces from a string. We use the module L<Time::Duration::Parse> to attempt this.
de827165 80
81=head1 CAVEATS
82
d811326f 83Firstly, this module uses L<DateTimeX::Easy> which is way more DWIM than any sane person would desire. L<DateTimeX::Easy> works by falling back until something makes sense, this is variable. Furthermore, all the modules that L<DateTimeX::Easy> *can* use aren't required for "proper" function of L<DateTimeX::Easy>. What does this mean? Simple, your mileage may vary in your coercions because L<DateTimeX::Easy> is installation specific.
de827165 84
85=head1 SEE ALSO
86
87=over 4
88
e18dcdf2 89=item * L<MooseX::Types::DateTime> Replacement for this module -- coercions with less voodoo
de827165 90
91=item * L<DateTimeX::Easy> Backend of this module
92
00d7c0c9 93=item * L<Time::Duration::Parse> Duration parsing backend for this module
94
de827165 95=back
96
97=head1 AUTHOR
98
99John Napiorkowski E<lt>jjn1056 at yahoo.comE<gt>
100
55a1a560 101Broken into a separate package from L<MooseX::Types::DateTime> by Evan Carroll.
de827165 102
00d7c0c9 103Forked from L<MooseX::Types::DateTimeX> and ported back to use
104L<MooseX::Types::DateTime> by Dagfinn Ilmari MannsE<aring>ker
105E<lt>ilmari@ilmari.orgE<gt>.
106
de827165 107=head1 LICENSE
108
109 Copyright (c) 2008 John Napiorkowski.
110
111 This program is free software; you can redistribute
112 it and/or modify it under the same terms as Perl itself.