line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormFu::Element::DateTime; |
2
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
837
|
use strict; |
|
9
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
372
|
|
4
|
|
|
|
|
|
|
our $VERSION = '2.05'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
9
|
|
|
9
|
|
35
|
use Moose; |
|
9
|
|
|
|
|
13
|
|
|
9
|
|
|
|
|
63
|
|
7
|
9
|
|
|
9
|
|
44946
|
use MooseX::Attribute::FormFuChained; |
|
9
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
300
|
|
8
|
|
|
|
|
|
|
extends 'HTML::FormFu::Element::Date'; |
9
|
|
|
|
|
|
|
|
10
|
9
|
|
|
9
|
|
35
|
use Moose::Util qw( apply_all_roles ); |
|
9
|
|
|
|
|
12
|
|
|
9
|
|
|
|
|
61
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
__PACKAGE__->mk_attrs(qw/ hour minute second /); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
for my $name ( qw( |
15
|
|
|
|
|
|
|
printf_hour |
16
|
|
|
|
|
|
|
printf_minute |
17
|
|
|
|
|
|
|
printf_second |
18
|
|
|
|
|
|
|
) ) |
19
|
|
|
|
|
|
|
{ |
20
|
|
|
|
|
|
|
has $name => ( |
21
|
|
|
|
|
|
|
is => 'rw', |
22
|
|
|
|
|
|
|
default => '%02d', |
23
|
|
|
|
|
|
|
lazy => 1, |
24
|
|
|
|
|
|
|
traits => ['FormFuChained'], |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
after BUILD => sub { |
29
|
|
|
|
|
|
|
my ( $self, $args ) = @_; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$self->strftime("%d-%m-%Y %H:%M"); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$self->_known_fields( [qw/ day month year hour minute second /] ); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$self->field_order( [qw( day month year hour minute )] ); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$self->hour( { prefix => [], } ); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$self->minute( { prefix => [], } ); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$self->second( { prefix => [], } ); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$self->printf_hour('%02d'); |
44
|
|
|
|
|
|
|
$self->printf_minute('%02d'); |
45
|
|
|
|
|
|
|
$self->printf_second('%02d'); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
return; |
48
|
|
|
|
|
|
|
}; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _add_hour { |
51
|
16
|
|
|
16
|
|
33
|
my ($self) = @_; |
52
|
|
|
|
|
|
|
|
53
|
16
|
|
|
|
|
356
|
my $hour = $self->hour; |
54
|
|
|
|
|
|
|
|
55
|
16
|
|
|
|
|
73
|
my $hour_name = $self->_build_name('hour'); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my @hour_prefix |
58
|
|
|
|
|
|
|
= ref $hour->{prefix} |
59
|
16
|
|
|
|
|
54
|
? @{ $hour->{prefix} } |
60
|
16
|
50
|
|
|
|
110
|
: $hour->{prefix}; |
61
|
|
|
|
|
|
|
|
62
|
16
|
50
|
|
|
|
58
|
if ( exists $hour->{prefix_loc} ) { |
63
|
|
|
|
|
|
|
@hour_prefix |
64
|
|
|
|
|
|
|
= ref $hour->{prefix_loc} |
65
|
0
|
|
|
|
|
0
|
? map { $self->form->localize($_) } @{ $hour->{prefix_loc} } |
|
0
|
|
|
|
|
0
|
|
66
|
0
|
0
|
|
|
|
0
|
: $self->form->localize( $hour->{prefix_loc} ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
16
|
|
|
|
|
41
|
@hour_prefix = map { [ '', $_ ] } @hour_prefix; |
|
0
|
|
|
|
|
0
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $element = $self->element( { |
72
|
|
|
|
|
|
|
type => 'Select', |
73
|
|
|
|
|
|
|
name => $hour_name, |
74
|
|
|
|
|
|
|
options => [ |
75
|
|
|
|
|
|
|
@hour_prefix, |
76
|
384
|
|
|
|
|
722
|
map { [ $_, $_ ] } map { sprintf '%02d', $_ } 0 .. 23 |
|
384
|
|
|
|
|
460
|
|
77
|
|
|
|
|
|
|
], |
78
|
|
|
|
|
|
|
attributes => $hour->{attributes}, |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
defined $hour->{default} |
81
|
|
|
|
|
|
|
? ( default => sprintf '%02d', $hour->{default} ) |
82
|
16
|
100
|
|
|
|
53
|
: (), |
83
|
|
|
|
|
|
|
} ); |
84
|
|
|
|
|
|
|
|
85
|
16
|
|
|
|
|
191
|
apply_all_roles( $element, 'HTML::FormFu::Role::Element::MultiElement' ); |
86
|
|
|
|
|
|
|
|
87
|
16
|
|
|
|
|
145179
|
return; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub _add_minute { |
91
|
16
|
|
|
16
|
|
41
|
my ($self) = @_; |
92
|
|
|
|
|
|
|
|
93
|
16
|
|
|
|
|
99
|
my $minute = $self->minute; |
94
|
|
|
|
|
|
|
|
95
|
16
|
|
|
|
|
84
|
my $minute_name = $self->_build_name('minute'); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my @minute_prefix |
98
|
|
|
|
|
|
|
= ref $minute->{prefix} |
99
|
16
|
|
|
|
|
53
|
? @{ $minute->{prefix} } |
100
|
16
|
50
|
|
|
|
74
|
: $minute->{prefix}; |
101
|
|
|
|
|
|
|
|
102
|
16
|
50
|
|
|
|
64
|
if ( exists $minute->{prefix_loc} ) { |
103
|
|
|
|
|
|
|
@minute_prefix |
104
|
|
|
|
|
|
|
= ref $minute->{prefix_loc} |
105
|
0
|
|
|
|
|
0
|
? map { $self->form->localize($_) } @{ $minute->{prefix_loc} } |
|
0
|
|
|
|
|
0
|
|
106
|
0
|
0
|
|
|
|
0
|
: $self->form->localize( $minute->{prefix_loc} ); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
16
|
|
|
|
|
38
|
@minute_prefix = map { [ '', $_ ] } @minute_prefix; |
|
0
|
|
|
|
|
0
|
|
110
|
|
|
|
|
|
|
|
111
|
16
|
|
|
|
|
125
|
my @minutes = $self->_build_number_list( 0, 59, $minute->{interval} ); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
my $element = $self->element( { |
114
|
|
|
|
|
|
|
type => 'Select', |
115
|
|
|
|
|
|
|
name => $minute_name, |
116
|
|
|
|
|
|
|
options => [ |
117
|
|
|
|
|
|
|
@minute_prefix, |
118
|
912
|
|
|
|
|
1435
|
map { [ $_, $_ ] } map { sprintf '%02d', $_ } @minutes |
|
912
|
|
|
|
|
933
|
|
119
|
|
|
|
|
|
|
], |
120
|
|
|
|
|
|
|
attributes => $minute->{attributes}, |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
defined $minute->{default} |
123
|
|
|
|
|
|
|
? ( default => sprintf '%02d', $minute->{default} ) |
124
|
16
|
100
|
|
|
|
72
|
: (), |
125
|
|
|
|
|
|
|
} ); |
126
|
|
|
|
|
|
|
|
127
|
16
|
|
|
|
|
322
|
apply_all_roles( $element, 'HTML::FormFu::Role::Element::MultiElement' ); |
128
|
|
|
|
|
|
|
|
129
|
16
|
|
|
|
|
140745
|
return; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub _add_second { |
133
|
3
|
|
|
3
|
|
5
|
my ($self) = @_; |
134
|
|
|
|
|
|
|
|
135
|
3
|
|
|
|
|
17
|
my $second = $self->second; |
136
|
|
|
|
|
|
|
|
137
|
3
|
|
|
|
|
12
|
my $second_name = $self->_build_name('second'); |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
my @second_prefix |
140
|
|
|
|
|
|
|
= ref $second->{prefix} |
141
|
3
|
|
|
|
|
10
|
? @{ $second->{prefix} } |
142
|
3
|
50
|
|
|
|
13
|
: $second->{prefix}; |
143
|
|
|
|
|
|
|
|
144
|
3
|
50
|
|
|
|
9
|
if ( exists $second->{prefix_loc} ) { |
145
|
|
|
|
|
|
|
@second_prefix |
146
|
|
|
|
|
|
|
= ref $second->{prefix_loc} |
147
|
0
|
|
|
|
|
0
|
? map { $self->form->localize($_) } @{ $second->{prefix_loc} } |
|
0
|
|
|
|
|
0
|
|
148
|
0
|
0
|
|
|
|
0
|
: $self->form->localize( $second->{prefix_loc} ); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
3
|
|
|
|
|
8
|
@second_prefix = map { [ '', $_ ] } @second_prefix; |
|
0
|
|
|
|
|
0
|
|
152
|
|
|
|
|
|
|
|
153
|
3
|
|
|
|
|
13
|
my @seconds = $self->_build_number_list( 0, 59, $second->{interval} ); |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
my $element = $self->element( { |
156
|
|
|
|
|
|
|
type => 'Select', |
157
|
|
|
|
|
|
|
name => $second_name, |
158
|
|
|
|
|
|
|
options => [ |
159
|
|
|
|
|
|
|
@second_prefix, |
160
|
122
|
|
|
|
|
160
|
map { [ $_, $_ ] } map { sprintf '%02d', $_ } @seconds |
|
122
|
|
|
|
|
115
|
|
161
|
|
|
|
|
|
|
], |
162
|
|
|
|
|
|
|
attributes => $second->{attributes}, |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
defined $second->{default} |
165
|
|
|
|
|
|
|
? ( default => sprintf '%02d', $second->{default} ) |
166
|
3
|
100
|
|
|
|
14
|
: (), |
167
|
|
|
|
|
|
|
} ); |
168
|
|
|
|
|
|
|
|
169
|
3
|
|
|
|
|
38
|
apply_all_roles( $element, 'HTML::FormFu::Role::Element::MultiElement' ); |
170
|
|
|
|
|
|
|
|
171
|
3
|
|
|
|
|
25595
|
return; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
1; |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
__END__ |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 NAME |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
HTML::FormFu::Element::DateTime - Date / Time combo field |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 VERSION |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
version 2.05 |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 SYNOPSIS |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
--- |
191
|
|
|
|
|
|
|
elements: |
192
|
|
|
|
|
|
|
- type: DateTime |
193
|
|
|
|
|
|
|
name: start_datetime |
194
|
|
|
|
|
|
|
label: 'Start:' |
195
|
|
|
|
|
|
|
auto_inflate: 1 |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head1 DESCRIPTION |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Sub-class of L<Date element|HTML::FormFu::Element::Date>, providing extra |
201
|
|
|
|
|
|
|
C<hour> and C<minute> Select menus. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 METHODS |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head2 hour |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Arguments: \%setting |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Set values effecting the C<hour> select menu. Known keys are: |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head3 name |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Override the auto-generated name of the select menu. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head3 default |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Set the default value of the select menu |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head3 prefix |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Arguments: $value |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Arguments: \@values |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
A string or arrayref of strings to be inserted into the start of the select |
226
|
|
|
|
|
|
|
menu. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
Each value is only used as the label for a select item - the value for each |
229
|
|
|
|
|
|
|
of these items is always the empty string C<''>. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head3 prefix_loc |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
Arguments: $localization_key |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
Arguments: \@localization_keys |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
A localized string or arrayref of localized strings to be inserted into the |
238
|
|
|
|
|
|
|
start of the select menu. |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
Each value is localized and then only used as the label for a select item |
241
|
|
|
|
|
|
|
- the value for each of these items is always the empty string C<''>. |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
Use C<prefix_loc> insted of C<prefix>. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head2 minute |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
Arguments: \%setting |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
Set values effecting the C<minute> select menu. Known keys are: |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=head3 name |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
Override the auto-generated name of the select menu. |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=head3 default |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
Set the default value of the select menu |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=head3 prefix |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
Arguments: $value |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
Arguments: \@values |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
A string or arrayref of strings to be inserted into the start of the select |
266
|
|
|
|
|
|
|
menu. |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
Each value is only used as the label for a select item - the value for each |
269
|
|
|
|
|
|
|
of these items is always the empty string C<''>. |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=head3 prefix_loc |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
Arguments: $localization_key |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
Arguments: \@localization_keys |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
A localized string or arrayref of localized strings to be inserted into the |
278
|
|
|
|
|
|
|
start of the select menu. |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
Each value is localized and then only used as the label for a select item |
281
|
|
|
|
|
|
|
- the value for each of these items is always the empty string C<''>. |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
Use C<prefix_loc> insted of C<prefix>. |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=head2 second |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
Arguments: \%setting |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
Set values effecting the C<second> select menu. Known keys are: |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=head3 name |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
Override the auto-generated name of the select menu. |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=head3 default |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
Set the default value of the select menu |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
=head3 prefix |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
Arguments: $value |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
Arguments: \@values |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
A string or arrayref of strings to be inserted into the start of the select |
306
|
|
|
|
|
|
|
menu. |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
Each value is only used as the label for a select item - the value for each |
309
|
|
|
|
|
|
|
of these items is always the empty string C<''>. |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
=head3 prefix_loc |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
Arguments: $localization_key |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
Arguments: \@localization_keys |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
A localized string or arrayref of localized strings to be inserted into the |
318
|
|
|
|
|
|
|
start of the select menu. |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
Each value is localized and then only used as the label for a select item |
321
|
|
|
|
|
|
|
- the value for each of these items is always the empty string C<''>. |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
Use C<prefix_loc> insted of C<prefix>. |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
=head2 field_order |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
Arguments: \@fields |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
Default Value: ['day', 'month', 'year', 'hour', 'minute'] |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
Specify the order of the date fields in the rendered HTML. |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
If you want the L</second> selector to display, you must set both |
334
|
|
|
|
|
|
|
C</field_order> and L<strftime|HTML::FormFu::Element::DateTime/strftime> |
335
|
|
|
|
|
|
|
yourself. Eg: |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
elements: |
338
|
|
|
|
|
|
|
type: DateTime |
339
|
|
|
|
|
|
|
name: foo |
340
|
|
|
|
|
|
|
strftime: '%d-%m-%Y %H:%M:%S' |
341
|
|
|
|
|
|
|
field_order: ['day', 'month', 'year', 'hour', 'minute', 'second'] |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
Not all fields are required. No single field can be used more than once. |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
=head1 CAVEATS |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
See L<HTML::FormFu::Element::Date/CAVEATS> |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
=head1 SEE ALSO |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
Is a sub-class of, and inherits methods from |
352
|
|
|
|
|
|
|
L<HTML::FormFu::Element::Date> |
353
|
|
|
|
|
|
|
L<HTML::FormFu::Role::Element::Field>, |
354
|
|
|
|
|
|
|
L<HTML::FormFu::Element::Multi>, |
355
|
|
|
|
|
|
|
L<HTML::FormFu::Element::Block>, |
356
|
|
|
|
|
|
|
L<HTML::FormFu::Element> |
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
L<HTML::FormFu> |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
=head1 AUTHOR |
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
Carl Franks, C<cfranks@cpan.org> |
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
=head1 LICENSE |
365
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under |
367
|
|
|
|
|
|
|
the same terms as Perl itself. |