line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MouseX::Types::DateTime; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
172507
|
use strict; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
195
|
|
4
|
5
|
|
|
5
|
|
29
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
183
|
|
5
|
5
|
|
|
5
|
|
75
|
use 5.8.1; |
|
5
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
217
|
|
6
|
5
|
|
|
5
|
|
9825
|
use DateTime (); |
|
5
|
|
|
|
|
278212
|
|
|
5
|
|
|
|
|
189
|
|
7
|
5
|
|
|
5
|
|
57
|
use DateTime::Duration (); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
74
|
|
8
|
5
|
|
|
5
|
|
26
|
use DateTime::TimeZone (); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
67
|
|
9
|
5
|
|
|
5
|
|
27
|
use DateTime::Locale (); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
97
|
|
10
|
5
|
|
|
5
|
|
24
|
use DateTime::Locale::root (); |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
66
|
|
11
|
5
|
|
|
5
|
|
5186
|
use DateTimeX::Easy (); |
|
5
|
|
|
|
|
425035
|
|
|
5
|
|
|
|
|
680
|
|
12
|
5
|
|
|
5
|
|
5599
|
use Time::Duration::Parse qw(parse_duration); |
|
5
|
|
|
|
|
13072
|
|
|
5
|
|
|
|
|
38
|
|
13
|
5
|
|
|
5
|
|
295
|
use Scalar::Util qw(looks_like_number); |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
279
|
|
14
|
5
|
|
|
5
|
|
888
|
use Mouse::Util::TypeConstraints; |
|
5
|
|
|
|
|
19358
|
|
|
5
|
|
|
|
|
63
|
|
15
|
5
|
|
|
5
|
|
5450
|
use MouseX::Types::Mouse qw(Str HashRef); |
|
5
|
|
|
|
|
12484
|
|
|
5
|
|
|
|
|
35
|
|
16
|
5
|
|
|
5
|
|
5714
|
use namespace::clean; |
|
5
|
|
|
|
|
28
|
|
|
5
|
|
|
|
|
55
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use MouseX::Types |
19
|
5
|
|
|
5
|
|
1910
|
-declare => [qw(DateTime Duration TimeZone Locale)]; # export Types |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
37
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
class_type 'DateTime' => { class => 'DateTime' }; |
24
|
|
|
|
|
|
|
class_type 'DateTime::Duration' => { class => 'DateTime::Duration' }; |
25
|
|
|
|
|
|
|
class_type 'DateTime::TimeZone' => { class => 'DateTime::TimeZone' }; |
26
|
|
|
|
|
|
|
class_type 'DateTime::Locale' => { class => 'DateTime::Locale::root' }; |
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
|
|
|
|
|
|
|
for my $type ( 'DateTime', DateTime ) { |
34
|
|
|
|
|
|
|
coerce $type, |
35
|
|
|
|
|
|
|
from Str, via { |
36
|
|
|
|
|
|
|
looks_like_number($_) |
37
|
|
|
|
|
|
|
? 'DateTime'->from_epoch(epoch => $_) |
38
|
|
|
|
|
|
|
: DateTimeX::Easy->new($_); |
39
|
|
|
|
|
|
|
}, |
40
|
|
|
|
|
|
|
from HashRef, via { 'DateTime'->new(%$_) }; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
for my $type ( 'DateTime::Duration', Duration ) { |
44
|
|
|
|
|
|
|
coerce $type, |
45
|
|
|
|
|
|
|
from Str, via { |
46
|
|
|
|
|
|
|
DateTime::Duration->new( |
47
|
|
|
|
|
|
|
seconds => looks_like_number($_) ? $_ : parse_duration($_) |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
}, |
50
|
|
|
|
|
|
|
from HashRef, via { DateTime::Duration->new(%$_) }; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
for my $type ( 'DateTime::TimeZone', TimeZone ) { |
54
|
|
|
|
|
|
|
coerce $type, |
55
|
|
|
|
|
|
|
from Str, via { DateTime::TimeZone->new(name => $_) }; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
for my $type ( 'DateTime::Locale', Locale ) { |
59
|
|
|
|
|
|
|
coerce $type, |
60
|
|
|
|
|
|
|
from Str, via { DateTime::Locale->load($_) }; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 NAME |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
MouseX::Types::DateTime - A DateTime type library for Mouse |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 SYNOPSIS |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 CLASS TYPES |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
package MyApp; |
74
|
|
|
|
|
|
|
use Mouse; |
75
|
|
|
|
|
|
|
use MouseX::Types::DateTime; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
has 'datetime' => ( |
78
|
|
|
|
|
|
|
is => 'rw', |
79
|
|
|
|
|
|
|
isa => 'DateTime', |
80
|
|
|
|
|
|
|
coerce => 1, |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
has 'duration' => ( |
84
|
|
|
|
|
|
|
is => 'rw', |
85
|
|
|
|
|
|
|
isa => 'DateTime::Duration', |
86
|
|
|
|
|
|
|
coerce => 1, |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
has 'timezone' => ( |
90
|
|
|
|
|
|
|
is => 'rw', |
91
|
|
|
|
|
|
|
isa => 'DateTime::TimeZone', |
92
|
|
|
|
|
|
|
coerce => 1, |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
has 'locale' => ( |
96
|
|
|
|
|
|
|
is => 'rw', |
97
|
|
|
|
|
|
|
isa => 'DateTime::Locale', |
98
|
|
|
|
|
|
|
coerce => 1, |
99
|
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 CUSTOM TYPES |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
package MyApp; |
104
|
|
|
|
|
|
|
use Mouse; |
105
|
|
|
|
|
|
|
use MouseX::Types::DateTime qw(DateTime Duration TimeZone Locale); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
has 'datetime' => ( |
108
|
|
|
|
|
|
|
is => 'rw', |
109
|
|
|
|
|
|
|
isa => DateTime, |
110
|
|
|
|
|
|
|
coerce => 1, |
111
|
|
|
|
|
|
|
); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
has 'duration' => ( |
114
|
|
|
|
|
|
|
is => 'rw', |
115
|
|
|
|
|
|
|
isa => Duration, |
116
|
|
|
|
|
|
|
coerce => 1, |
117
|
|
|
|
|
|
|
); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
has 'timezone' => ( |
120
|
|
|
|
|
|
|
is => 'rw', |
121
|
|
|
|
|
|
|
isa => TimeZone, |
122
|
|
|
|
|
|
|
coerce => 1, |
123
|
|
|
|
|
|
|
); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
has 'locale' => ( |
126
|
|
|
|
|
|
|
is => 'rw', |
127
|
|
|
|
|
|
|
isa => Locale, |
128
|
|
|
|
|
|
|
coerce => 1, |
129
|
|
|
|
|
|
|
); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 DESCRIPTION |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
MouseX::Types::DateTime creates common L types and coercions |
134
|
|
|
|
|
|
|
for dealing with L objects as L attributes. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Coercions (see L) are made from |
137
|
|
|
|
|
|
|
C and C to L, L, |
138
|
|
|
|
|
|
|
L and L objects. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 TYPES |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 DateTime |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=over 4 |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
A L class type. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Coerces from C via L or L. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Coerces from C via L. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=back |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 Duration |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=over 4 |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
A L class type. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Coerces from C via L |
161
|
|
|
|
|
|
|
and L. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Coerces from C via L. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=back |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head2 TimeZone |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=over 4 |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
A L class type. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Coerces from C via L. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=back |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head2 Locale |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=over 4 |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
A L (see L) class type. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Coerces from C via L. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=back |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 AUTHOR |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
NAKAGAWA Masaki Emasaki@cpan.orgE |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 THANKS TO |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Yuval Kogman, John Napiorkowski, L |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 LICENSE |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
198
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head1 SEE ALSO |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
L, L, |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
L, L, |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
L, L |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=cut |