line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Types::DateTime; # git description: v0.12-2-g35c46dd |
2
|
|
|
|
|
|
|
# ABSTRACT: L<DateTime> related constraints and coercions for Moose |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
206501
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
47
|
|
5
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
71
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.13'; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
59
|
use 5.008003; |
|
2
|
|
|
|
|
7
|
|
10
|
2
|
|
|
2
|
|
1687
|
use Moose 0.41 (); |
|
2
|
|
|
|
|
923837
|
|
|
2
|
|
|
|
|
84
|
|
11
|
2
|
|
|
2
|
|
1697
|
use DateTime 0.4302 (); |
|
2
|
|
|
|
|
133438
|
|
|
2
|
|
|
|
|
76
|
|
12
|
2
|
|
|
2
|
|
16
|
use DateTime::Duration 0.4302 (); |
|
2
|
|
|
|
|
33
|
|
|
2
|
|
|
|
|
44
|
|
13
|
2
|
|
|
2
|
|
12
|
use DateTime::Locale 0.4001 (); |
|
2
|
|
|
|
|
29
|
|
|
2
|
|
|
|
|
39
|
|
14
|
2
|
|
|
2
|
|
12
|
use DateTime::TimeZone 0.95 (); |
|
2
|
|
|
|
|
27
|
|
|
2
|
|
|
|
|
57
|
|
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
1889
|
use MooseX::Types::Moose 0.30 qw/Num HashRef Object Str/; |
|
2
|
|
|
|
|
132232
|
|
|
2
|
|
|
|
|
24
|
|
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
2
|
|
11134
|
use namespace::clean 0.19; |
|
2
|
|
|
|
|
37
|
|
|
2
|
|
|
|
|
17
|
|
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
2
|
|
483
|
use MooseX::Types 0.30 -declare => [qw( DateTime Duration TimeZone Locale Now )]; |
|
2
|
|
|
|
|
31
|
|
|
2
|
|
|
|
|
15
|
|
21
|
2
|
|
|
2
|
|
11678
|
use if MooseX::Types->VERSION >= 0.42, 'namespace::autoclean'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
38
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
class_type "DateTime"; |
24
|
|
|
|
|
|
|
class_type "DateTime::Duration"; |
25
|
|
|
|
|
|
|
class_type "DateTime::TimeZone"; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
subtype DateTime, as 'DateTime'; |
28
|
|
|
|
|
|
|
subtype Duration, as 'DateTime::Duration'; |
29
|
|
|
|
|
|
|
subtype TimeZone, as 'DateTime::TimeZone'; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
subtype 'DateTime::Locale', as Object, |
32
|
|
|
|
|
|
|
where { $_->isa('DateTime::Locale::root') || $_->isa('DateTime::Locale::FromData') }; |
33
|
|
|
|
|
|
|
subtype Locale, as 'DateTime::Locale'; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
subtype( Now, |
36
|
|
|
|
|
|
|
as Str, |
37
|
|
|
|
|
|
|
where { $_ eq 'now' }, |
38
|
|
|
|
|
|
|
($Moose::VERSION >= 2.0100 |
39
|
|
|
|
|
|
|
? Moose::Util::TypeConstraints::inline_as { |
40
|
|
|
|
|
|
|
'no warnings "uninitialized";'. |
41
|
|
|
|
|
|
|
'!ref(' . $_[1] . ') and '. $_[1] .' eq "now"'; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
: Moose::Util::TypeConstraints::optimize_as { |
44
|
2
|
|
|
2
|
|
590
|
no warnings 'uninitialized'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1055
|
|
45
|
|
|
|
|
|
|
!ref($_[0]) and $_[0] eq 'now'; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
), |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
our %coercions = ( |
51
|
|
|
|
|
|
|
DateTime => [ |
52
|
|
|
|
|
|
|
from Num, via { 'DateTime'->from_epoch( epoch => $_ ) }, |
53
|
|
|
|
|
|
|
from HashRef, via { 'DateTime'->new( %$_ ) }, |
54
|
|
|
|
|
|
|
from Now, via { 'DateTime'->now }, |
55
|
|
|
|
|
|
|
], |
56
|
|
|
|
|
|
|
"DateTime::Duration" => [ |
57
|
|
|
|
|
|
|
from Num, via { DateTime::Duration->new( seconds => $_ ) }, |
58
|
|
|
|
|
|
|
from HashRef, via { DateTime::Duration->new( %$_ ) }, |
59
|
|
|
|
|
|
|
], |
60
|
|
|
|
|
|
|
"DateTime::TimeZone" => [ |
61
|
|
|
|
|
|
|
from Str, via { DateTime::TimeZone->new( name => $_ ) }, |
62
|
|
|
|
|
|
|
], |
63
|
|
|
|
|
|
|
"DateTime::Locale" => [ |
64
|
|
|
|
|
|
|
from Moose::Util::TypeConstraints::find_or_create_isa_type_constraint("Locale::Maketext"), |
65
|
|
|
|
|
|
|
via { DateTime::Locale->load($_->language_tag) }, |
66
|
|
|
|
|
|
|
from Str, via { DateTime::Locale->load($_) }, |
67
|
|
|
|
|
|
|
], |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
for my $type ( "DateTime", DateTime ) { |
71
|
|
|
|
|
|
|
coerce $type => @{ $coercions{DateTime} }; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
for my $type ( "DateTime::Duration", Duration ) { |
75
|
|
|
|
|
|
|
coerce $type => @{ $coercions{"DateTime::Duration"} }; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
for my $type ( "DateTime::TimeZone", TimeZone ) { |
79
|
|
|
|
|
|
|
coerce $type => @{ $coercions{"DateTime::TimeZone"} }; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
for my $type ( "DateTime::Locale", Locale ) { |
83
|
|
|
|
|
|
|
coerce $type => @{ $coercions{"DateTime::Locale"} }; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__PACKAGE__ |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=pod |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=encoding UTF-8 |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 NAME |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
MooseX::Types::DateTime - L<DateTime> related constraints and coercions for Moose |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 VERSION |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
version 0.13 |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 SYNOPSIS |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Export Example: |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
use MooseX::Types::DateTime qw(TimeZone); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
has time_zone => ( |
109
|
|
|
|
|
|
|
isa => TimeZone, |
110
|
|
|
|
|
|
|
is => "rw", |
111
|
|
|
|
|
|
|
coerce => 1, |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Class->new( time_zone => "Africa/Timbuktu" ); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 DESCRIPTION |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
This module packages several L<Moose::Util::TypeConstraints> with coercions, |
119
|
|
|
|
|
|
|
designed to work with the L<DateTime> suite of objects. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=for stopwords Namespaced |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Namespaced Example: |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
use MooseX::Types::DateTime; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
has time_zone => ( |
128
|
|
|
|
|
|
|
isa => 'DateTime::TimeZone', |
129
|
|
|
|
|
|
|
is => "rw", |
130
|
|
|
|
|
|
|
coerce => 1, |
131
|
|
|
|
|
|
|
); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Class->new( time_zone => "Africa/Timbuktu" ); |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 CONSTRAINTS |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=over 4 |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item L<DateTime> |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
A class type for L<DateTime>. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=over 4 |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item from C<Num> |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Uses L<DateTime/from_epoch>. Floating values will be used for sub-second |
148
|
|
|
|
|
|
|
precision, see L<DateTime> for details. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item from C<HashRef> |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Calls L<DateTime/new> with the hash entries as arguments. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=back |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item L<Duration> |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
A class type for L<DateTime::Duration> |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=over 4 |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item from C<Num> |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Uses L<DateTime::Duration/new> and passes the number as the C<seconds> argument. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Note that due to leap seconds, DST changes etc this may not do what you expect. |
167
|
|
|
|
|
|
|
For instance passing in C<86400> is not always equivalent to one day, although |
168
|
|
|
|
|
|
|
there are that many seconds in a day. See L<DateTime/"How Date Math is Done"> |
169
|
|
|
|
|
|
|
for more details. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item from C<HashRef> |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Calls L<DateTime::Duration/new> with the hash entries as arguments. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=back |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=item L<DateTime::Locale> |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
A class type for L<DateTime::Locale::root> with the name L<DateTime::Locale>. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=over 4 |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item from C<Str> |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
The string is treated as a language tag (e.g. C<en> or C<he_IL>) and given to |
186
|
|
|
|
|
|
|
L<DateTime::Locale/load>. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item from L<Locale::Maktext> |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
The C<Locale::Maketext/language_tag> attribute will be used with L<DateTime::Locale/load>. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=item L<DateTime::TimeZone> |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
A class type for L<DateTime::TimeZone>. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=over 4 |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item from C<Str> |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Treated as a time zone name or offset. See L<DateTime::TimeZone/USAGE> for more |
201
|
|
|
|
|
|
|
details on the allowed values. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Delegates to L<DateTime::TimeZone/new> with the string as the C<name> argument. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=back |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=back |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=back |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 SEE ALSO |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
L<MooseX::Types::DateTime::MoreCoercions> |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
L<DateTime>, L<DateTimeX::Easy> |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head1 SUPPORT |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Types-DateTime> |
220
|
|
|
|
|
|
|
(or L<bug-MooseX-Types-DateTime@rt.cpan.org|mailto:bug-MooseX-Types-DateTime@rt.cpan.org>). |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
There is also a mailing list available for users of this distribution, at |
223
|
|
|
|
|
|
|
L<http://lists.perl.org/list/moose.html>. |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
There is also an irc channel available for users of this distribution, at |
226
|
|
|
|
|
|
|
irc://irc.perl.org/#moose. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head1 AUTHOR |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
×××× ×§××'×× (Yuval Kogman) <nothingmuch@woobling.org> |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=for stopwords Karen Etheridge Dagfinn Ilmari Mannsåker Florian Ragwitz John Napiorkowski Shawn M Moore Dave Rolsky |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=over 4 |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=item * |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
Karen Etheridge <ether@cpan.org> |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=item * |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=item * |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
Florian Ragwitz <rafl@debian.org> |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=item * |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
John Napiorkowski <jjnapiork@cpan.org> |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=item * |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Shawn M Moore <sartak@gmail.com> |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=item * |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=back |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
This software is copyright (c) 2008 by ×××× ×§××'×× (Yuval Kogman). |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
269
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=cut |