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