| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MooseX::Types::DateTime; # git description: v0.11-2-gcf49f6d |
|
2
|
|
|
|
|
|
|
# ABSTRACT: L<DateTime> related constraints and coercions for Moose |
|
3
|
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
192740
|
use strict; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
47
|
|
|
5
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
71
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
120
|
use 5.008003; |
|
|
2
|
|
|
|
|
6
|
|
|
10
|
2
|
|
|
2
|
|
1643
|
use Moose 0.41 (); |
|
|
2
|
|
|
|
|
904959
|
|
|
|
2
|
|
|
|
|
92
|
|
|
11
|
2
|
|
|
2
|
|
1714
|
use DateTime 0.4302 (); |
|
|
2
|
|
|
|
|
126378
|
|
|
|
2
|
|
|
|
|
71
|
|
|
12
|
2
|
|
|
2
|
|
14
|
use DateTime::Duration 0.4302 (); |
|
|
2
|
|
|
|
|
31
|
|
|
|
2
|
|
|
|
|
40
|
|
|
13
|
2
|
|
|
2
|
|
11
|
use DateTime::Locale 0.4001 (); |
|
|
2
|
|
|
|
|
26
|
|
|
|
2
|
|
|
|
|
40
|
|
|
14
|
2
|
|
|
2
|
|
10
|
use DateTime::TimeZone 0.95 (); |
|
|
2
|
|
|
|
|
24
|
|
|
|
2
|
|
|
|
|
51
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
1705
|
use MooseX::Types::Moose 0.30 qw/Num HashRef Str/; |
|
|
2
|
|
|
|
|
128436
|
|
|
|
2
|
|
|
|
|
22
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
2
|
|
|
2
|
|
10754
|
use namespace::clean 0.19; |
|
|
2
|
|
|
|
|
34
|
|
|
|
2
|
|
|
|
|
14
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
2
|
|
|
2
|
|
404
|
use MooseX::Types 0.30 -declare => [qw( DateTime Duration TimeZone Locale Now )]; |
|
|
2
|
|
|
|
|
29
|
|
|
|
2
|
|
|
|
|
14
|
|
|
21
|
2
|
|
|
2
|
|
11544
|
use if MooseX::Types->VERSION >= 0.42, 'namespace::autoclean'; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
39
|
|
|
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
|
|
611
|
no warnings 'uninitialized'; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
1086
|
|
|
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.12 |
|
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 SUPPORT |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Types-DateTime> |
|
218
|
|
|
|
|
|
|
(or L<bug-MooseX-Types-DateTime@rt.cpan.org|mailto:bug-MooseX-Types-DateTime@rt.cpan.org>). |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
There is also a mailing list available for users of this distribution, at |
|
221
|
|
|
|
|
|
|
L<http://lists.perl.org/list/moose.html>. |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
There is also an irc channel available for users of this distribution, at |
|
224
|
|
|
|
|
|
|
irc://irc.perl.org/#moose. |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 AUTHOR |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
×××× ×§××'×× (Yuval Kogman) <nothingmuch@woobling.org> |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=for stopwords Karen Etheridge Dagfinn Ilmari Mannsåker Florian Ragwitz John Napiorkowski Shawn M Moore |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=over 4 |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=item * |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
Karen Etheridge <ether@cpan.org> |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=item * |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=item * |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
Florian Ragwitz <rafl@debian.org> |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=item * |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
John Napiorkowski <jjnapiork@cpan.org> |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=item * |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
Shawn M Moore <sartak@gmail.com> |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=back |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
This software is copyright (c) 2008 by ×××× ×§××'×× (Yuval Kogman). |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
263
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=cut |