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 CC 13 SCAR 15.3
CC
13
Cov
77%
_add_hour
5.9
_add_minute
5.8
_add_second
5.8
CRAP 4.6
« lib/HTML/FormFu/Constraint/Length.pm ↑ Summary lib/HTML/FormFu/Element/URL.pm »
1 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Element::DateTime;
4 11 $HTML::FormFu::Element::DateTime::VERSION = '2.09';
5 # ABSTRACT: Date / Time combo field
6  
7 11 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use MooseX::Attribute::Chained;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 extends 'HTML::FormFu::Element::Date';
10  
11 11 ▶use Moose::Util qw( apply_all_roles );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 11 __PACKAGE__->mk_attrs(qw/ hour minute second /);
14  
15 11 for my $name ( qw(
16 printf_hour
17 printf_minute
18 printf_second
19 ) )
20 {
21 33 has $name => (
22 is => 'rw',
23 default => '%02d',
24 lazy => 1,
25 traits => ['Chained'],
26 );
27 }
28  
29 11 ▶after BUILD => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
30 11 my ( $self, $args ) = @_;
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 11 };
50  
51 16 ▶sub _add_hour {
Subroutine _add_hour: called CC=5 SCAR=17.8
52 16 my ($self) = @_;
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 0 @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 16 ▶sub _add_minute {
Subroutine _add_minute: called CC=5 SCAR=17.6
92 16 my ($self) = @_;
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 0 @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 3 ▶sub _add_second {
Subroutine _add_second: called CC=5 SCAR=17.6
134 3 my ($self) = @_;
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 0 @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 11 __PACKAGE__->meta->make_immutable;
176  
177 11 1;
178  
179 __END__
« lib/HTML/FormFu/Constraint/Length.pm ↑ Summary lib/HTML/FormFu/Element/URL.pm »