lib/HTML/FormFu/Element/DateTime.pm

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