line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormFu::Inflator::DateTime; |
2
|
|
|
|
|
|
|
|
3
|
25
|
|
|
25
|
|
1603
|
use strict; |
|
25
|
|
|
|
|
42
|
|
|
25
|
|
|
|
|
1199
|
|
4
|
|
|
|
|
|
|
our $VERSION = '2.05'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
25
|
|
|
25
|
|
93
|
use Moose; |
|
25
|
|
|
|
|
28
|
|
|
25
|
|
|
|
|
203
|
|
7
|
25
|
|
|
25
|
|
110272
|
use MooseX::Attribute::FormFuChained; |
|
25
|
|
|
|
|
41
|
|
|
25
|
|
|
|
|
825
|
|
8
|
|
|
|
|
|
|
extends 'HTML::FormFu::Inflator'; |
9
|
|
|
|
|
|
|
|
10
|
25
|
|
|
25
|
|
90
|
use HTML::FormFu::Constants qw( $EMPTY_STR ); |
|
25
|
|
|
|
|
36
|
|
|
25
|
|
|
|
|
2689
|
|
11
|
25
|
|
|
25
|
|
7010
|
use DateTime::Format::Builder; |
|
25
|
|
|
|
|
4537134
|
|
|
25
|
|
|
|
|
226
|
|
12
|
25
|
|
|
25
|
|
635
|
use DateTime::Format::Strptime; |
|
25
|
|
|
|
|
33
|
|
|
25
|
|
|
|
|
158
|
|
13
|
25
|
|
|
25
|
|
1133
|
use Scalar::Util qw( reftype ); |
|
25
|
|
|
|
|
37
|
|
|
25
|
|
|
|
|
8790
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has strptime => ( is => 'rw', traits => ['FormFuChained'] ); |
16
|
|
|
|
|
|
|
has time_zone => ( is => 'rw', traits => ['FormFuChained'] ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has _builder => ( |
19
|
|
|
|
|
|
|
is => 'rw', |
20
|
|
|
|
|
|
|
default => sub { DateTime::Format::Builder->new }, |
21
|
|
|
|
|
|
|
lazy => 1, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub parser { |
25
|
26
|
|
|
26
|
1
|
49
|
my ( $self, $arg ) = @_; |
26
|
|
|
|
|
|
|
|
27
|
26
|
100
|
100
|
|
|
118
|
if ( exists $arg->{regex} && !ref $arg->{regex} ) { |
28
|
1
|
|
|
|
|
27
|
$arg->{regex} = qr/$arg->{regex}/; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
26
|
|
|
|
|
719
|
$self->_builder->parser($arg); |
32
|
|
|
|
|
|
|
|
33
|
26
|
|
|
|
|
35977
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub inflator { |
37
|
27
|
|
|
27
|
0
|
45
|
my ( $self, $value ) = @_; |
38
|
|
|
|
|
|
|
|
39
|
27
|
100
|
100
|
|
|
236
|
return if !defined $value || $value eq $EMPTY_STR; |
40
|
|
|
|
|
|
|
|
41
|
25
|
|
|
|
|
907
|
my $dt = $self->_builder->parse_datetime($value); |
42
|
|
|
|
|
|
|
|
43
|
22
|
100
|
|
|
|
14746
|
if ( defined $self->time_zone ) { |
44
|
1
|
|
|
|
|
25
|
$dt->set_time_zone( $self->time_zone ); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
22
|
100
|
|
|
|
10904
|
if ( defined $self->strptime ) { |
48
|
11
|
|
|
|
|
272
|
my $strptime = $self->strptime; |
49
|
11
|
|
|
|
|
17
|
my %args; |
50
|
|
|
|
|
|
|
|
51
|
11
|
100
|
100
|
|
|
126
|
if ( ( reftype($strptime) || '' ) eq 'HASH' ) { |
52
|
2
|
|
|
|
|
8
|
%args = %$strptime; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
else { |
55
|
9
|
|
|
|
|
31
|
%args = ( pattern => $strptime ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Make strptime format the date with the specified time_zone, |
59
|
|
|
|
|
|
|
# this is most likely what the user wants |
60
|
11
|
100
|
|
|
|
297
|
if ( defined $self->time_zone ) { |
61
|
1
|
|
|
|
|
24
|
$args{time_zone} = $self->time_zone; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
11
|
50
|
33
|
|
|
129
|
if ( !exists $args{locale} |
65
|
|
|
|
|
|
|
&& defined( my $locale = $self->locale ) ) |
66
|
|
|
|
|
|
|
{ |
67
|
0
|
|
|
|
|
0
|
$args{locale} = $locale; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
11
|
|
|
|
|
65
|
my $formatter = DateTime::Format::Strptime->new(%args); |
71
|
|
|
|
|
|
|
|
72
|
11
|
|
|
|
|
9873
|
$dt->set_formatter($formatter); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
22
|
|
|
|
|
529
|
return $dt; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub clone { |
79
|
2
|
|
|
2
|
0
|
3
|
my $self = shift; |
80
|
|
|
|
|
|
|
|
81
|
2
|
|
|
|
|
15
|
my $clone = $self->SUPER::clone(@_); |
82
|
|
|
|
|
|
|
|
83
|
2
|
|
|
|
|
51
|
$clone->_builder( $self->_builder->clone ); |
84
|
|
|
|
|
|
|
|
85
|
2
|
|
|
|
|
49
|
return $clone; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 NAME |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
HTML::FormFu::Inflator::DateTime - DateTime inflator |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 VERSION |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
version 2.05 |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 SYNOPSIS |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
--- |
105
|
|
|
|
|
|
|
elements: |
106
|
|
|
|
|
|
|
- type: Text |
107
|
|
|
|
|
|
|
name: start_date |
108
|
|
|
|
|
|
|
inflators: |
109
|
|
|
|
|
|
|
- type: DateTime |
110
|
|
|
|
|
|
|
parser: |
111
|
|
|
|
|
|
|
strptime: '%d-%m-%Y' |
112
|
|
|
|
|
|
|
strptime: |
113
|
|
|
|
|
|
|
pattern: '%d-%b-%Y' |
114
|
|
|
|
|
|
|
locale: de |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
- type: Text |
117
|
|
|
|
|
|
|
name: end_time |
118
|
|
|
|
|
|
|
inflators: |
119
|
|
|
|
|
|
|
- type: DateTime |
120
|
|
|
|
|
|
|
time_zone: Europe/Rome |
121
|
|
|
|
|
|
|
parser: |
122
|
|
|
|
|
|
|
regex: '^ (\d{2}) - (\d{2}) - (\d{4}) $' |
123
|
|
|
|
|
|
|
params: [day, month, year] |
124
|
|
|
|
|
|
|
strptime: '%d-%m-%Y' |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
An example of using the same parser declaration for both a DateTime |
127
|
|
|
|
|
|
|
constraint and a DateTime inflator, using YAML references: |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
--- |
130
|
|
|
|
|
|
|
elements: |
131
|
|
|
|
|
|
|
- type: Text |
132
|
|
|
|
|
|
|
name: date |
133
|
|
|
|
|
|
|
constraints: |
134
|
|
|
|
|
|
|
- type: DateTime |
135
|
|
|
|
|
|
|
parser: &PARSER |
136
|
|
|
|
|
|
|
strptime: '%d-%m-%Y' |
137
|
|
|
|
|
|
|
inflators: |
138
|
|
|
|
|
|
|
- type: DateTime |
139
|
|
|
|
|
|
|
parser: *PARSER |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 DESCRIPTION |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Inflate dates into L<DateTime> objects. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
For a corresponding deflator, see L<HTML::FormFu::Deflator::Strftime>. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 METHODS |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 parser |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Arguments: \%args |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Required. Define the expected input string, so L<DateTime::Format::Builder> |
154
|
|
|
|
|
|
|
knows how to inflate it into a L<DateTime> object. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Accepts arguments to be passed to L<DateTime::Format::Builder/parser>. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 strptime |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Arguments: \%args |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Arguments: $string |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Optional. Define the format that should be used if the L<DateTime> object is |
165
|
|
|
|
|
|
|
stringified. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head2 time_zone |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Arguments: $string |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Optional. You can pass along a time_zone in which the DateTime will be |
172
|
|
|
|
|
|
|
created. This is useful if the string to parse does not contain time zone |
173
|
|
|
|
|
|
|
information and you want the DateTime to be in a specific zone instead |
174
|
|
|
|
|
|
|
of the floating one (which is likely). |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Accepts a hashref of arguments to be passed to |
177
|
|
|
|
|
|
|
L<DateTime::Format::Strptime/new>. Alternatively, accepts a single string |
178
|
|
|
|
|
|
|
argument, suitable for passing to |
179
|
|
|
|
|
|
|
C<< DateTime::Format::Strptime->new( pattern => $string ) >>. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 AUTHOR |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Carl Franks, C<cfranks@cpan.org> |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 LICENSE |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under |
188
|
|
|
|
|
|
|
the same terms as Perl itself. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=cut |