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