line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
890
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
188
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTML::FormFu::Inflator::CompoundDateTime; |
4
|
|
|
|
|
|
|
$HTML::FormFu::Inflator::CompoundDateTime::VERSION = '2.07'; |
5
|
|
|
|
|
|
|
# ABSTRACT: CompoundDateTime inflator |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
29
|
use Moose; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
27
|
|
8
|
3
|
|
|
3
|
|
21380
|
use MooseX::Attribute::Chained; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
128
|
|
9
|
|
|
|
|
|
|
extends 'HTML::FormFu::Inflator'; |
10
|
|
|
|
|
|
|
|
11
|
3
|
|
|
3
|
|
20
|
use HTML::FormFu::Constants qw( $EMPTY_STR ); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
375
|
|
12
|
3
|
|
|
3
|
|
1846
|
use DateTime; |
|
3
|
|
|
|
|
937839
|
|
|
3
|
|
|
|
|
144
|
|
13
|
3
|
|
|
3
|
|
1542
|
use DateTime::Format::Strptime; |
|
3
|
|
|
|
|
114398
|
|
|
3
|
|
|
|
|
27
|
|
14
|
3
|
|
|
3
|
|
347
|
use List::Util 1.33 qw( none ); |
|
3
|
|
|
|
|
167
|
|
|
3
|
|
|
|
|
218
|
|
15
|
3
|
|
|
3
|
|
23
|
use Scalar::Util qw( reftype ); |
|
3
|
|
|
|
|
15
|
|
|
3
|
|
|
|
|
159
|
|
16
|
3
|
|
|
3
|
|
18
|
use Carp qw( croak ); |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
1484
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has strptime => ( is => 'rw', traits => ['Chained'] ); |
19
|
|
|
|
|
|
|
has field_order => ( is => 'rw', traits => ['Chained'] ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my @known_fields = qw( year month day hour minute second nanosecond time_zone ); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub inflator { |
24
|
2
|
|
|
2
|
0
|
8
|
my ( $self, $value ) = @_; |
25
|
|
|
|
|
|
|
|
26
|
2
|
50
|
33
|
|
|
26
|
return if !defined $value || $value eq $EMPTY_STR; |
27
|
|
|
|
|
|
|
|
28
|
2
|
|
|
|
|
29
|
my ( $multi, @fields ) = @{ $self->parent->get_fields }; |
|
2
|
|
|
|
|
19
|
|
29
|
2
|
|
|
|
|
7
|
my %input; |
30
|
|
|
|
|
|
|
|
31
|
2
|
100
|
|
|
|
71
|
if ( defined( my $order = $self->field_order ) ) { |
32
|
1
|
|
|
|
|
13
|
for my $order (@$order) { |
33
|
|
|
|
|
|
|
croak "unknown DateTime field_order name" |
34
|
3
|
50
|
|
6
|
|
16
|
if none { $order eq $_ } @known_fields; |
|
6
|
|
|
|
|
13
|
|
35
|
|
|
|
|
|
|
|
36
|
3
|
|
|
|
|
10
|
my $field = shift @fields; |
37
|
3
|
|
|
|
|
8
|
my $name = $field->name; |
38
|
|
|
|
|
|
|
|
39
|
3
|
|
|
|
|
12
|
$input{$order} = $value->{$name}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
else { |
43
|
1
|
|
|
|
|
4
|
for my $name ( keys %$value ) { |
44
|
|
|
|
|
|
|
croak "unknown DateTime field name" |
45
|
3
|
50
|
|
6
|
|
14
|
if none { $name eq $_ } @known_fields; |
|
6
|
|
|
|
|
28
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
7
|
%input = %$value; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
2
|
|
|
|
|
4
|
my $dt; |
52
|
|
|
|
|
|
|
|
53
|
2
|
|
|
|
|
6
|
eval { $dt = DateTime->new(%input) }; |
|
2
|
|
|
|
|
47
|
|
54
|
|
|
|
|
|
|
|
55
|
2
|
50
|
|
|
|
1095
|
return $value if $@; |
56
|
|
|
|
|
|
|
|
57
|
2
|
50
|
|
|
|
117
|
if ( defined $self->strptime ) { |
58
|
2
|
|
|
|
|
66
|
my $strptime = $self->strptime; |
59
|
2
|
|
|
|
|
6
|
my %args; |
60
|
|
|
|
|
|
|
|
61
|
2
|
50
|
50
|
|
|
17
|
if ( ( reftype($strptime) || '' ) eq 'HASH' ) { |
62
|
0
|
|
|
|
|
0
|
%args = %$strptime; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
else { |
65
|
2
|
|
|
|
|
10
|
%args = ( pattern => $strptime ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
2
|
|
|
|
|
18
|
my $formatter = DateTime::Format::Strptime->new(%args); |
69
|
|
|
|
|
|
|
|
70
|
2
|
|
|
|
|
3678
|
$dt->set_formatter($formatter); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
2
|
|
|
|
|
140
|
return $dt; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=pod |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=encoding UTF-8 |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 NAME |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
HTML::FormFu::Inflator::CompoundDateTime - CompoundDateTime inflator |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 VERSION |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
version 2.07 |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 SYNOPSIS |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
--- |
97
|
|
|
|
|
|
|
element: |
98
|
|
|
|
|
|
|
- type: Multi |
99
|
|
|
|
|
|
|
name: date |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
elements: |
102
|
|
|
|
|
|
|
- name: day |
103
|
|
|
|
|
|
|
- name: month |
104
|
|
|
|
|
|
|
- name: year |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
inflator: |
107
|
|
|
|
|
|
|
- type: CompoundDateTime |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# get the submitted value as a DateTime object |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
my $date = $form->param_value('date'); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 DESCRIPTION |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
For use with a L<HTML::FormFu::Element::Multi> group of fields. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Changes the input from several fields into a single L<DateTime> value. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
By default, expects the field names to be any of the following: |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=over |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item year |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item month |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item day |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item hour |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item minute |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item second |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item nanosecond |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item time_zone |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=back |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 METHODS |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head2 field_order |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Arguments: \@order |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
If your field names doesn't follow the convention listed above, you must |
148
|
|
|
|
|
|
|
provide an arrayref containing the above names, in the order they correspond |
149
|
|
|
|
|
|
|
with your own fields. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
--- |
152
|
|
|
|
|
|
|
element: |
153
|
|
|
|
|
|
|
- type: Multi |
154
|
|
|
|
|
|
|
name: date |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
elements: |
157
|
|
|
|
|
|
|
- name: m |
158
|
|
|
|
|
|
|
- name: d |
159
|
|
|
|
|
|
|
- name: y |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
inflator: |
162
|
|
|
|
|
|
|
- type: CompoundDateTime |
163
|
|
|
|
|
|
|
field_order: |
164
|
|
|
|
|
|
|
- month |
165
|
|
|
|
|
|
|
- day |
166
|
|
|
|
|
|
|
- year |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 strptime |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Arguments: \%args |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Arguments: $string |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Optional. Define the format that should be used if the L<DateTime> object is |
175
|
|
|
|
|
|
|
stringified. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Accepts a hashref of arguments to be passed to |
178
|
|
|
|
|
|
|
L<DateTime::Format::Strptime/new>. Alternatively, accepts a single string |
179
|
|
|
|
|
|
|
argument, suitable for passing to |
180
|
|
|
|
|
|
|
C<< DateTime::Format::Strptime->new( pattern => $string ) >>. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
--- |
183
|
|
|
|
|
|
|
inflator: |
184
|
|
|
|
|
|
|
- type: CompoundDateTime |
185
|
|
|
|
|
|
|
strptime: |
186
|
|
|
|
|
|
|
pattern: '%d-%b-%Y' |
187
|
|
|
|
|
|
|
locale: de |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
--- |
190
|
|
|
|
|
|
|
inflator: |
191
|
|
|
|
|
|
|
- type: CompoundDateTime |
192
|
|
|
|
|
|
|
strptime: '%d-%m-%Y' |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 AUTHOR |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Carl Franks |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head1 LICENSE |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under |
201
|
|
|
|
|
|
|
the same terms as Perl itself. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 AUTHOR |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Carl Franks <cpan@fireartist.com> |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
This software is copyright (c) 2018 by Carl Franks. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
212
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=cut |