lib/HTML/FormFu/Deflator/CompoundDateTime.pm

filter: Statementstmt 100% 46 / 46 Branchbran 60.0% 6 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 1 totaltotal 87.5% 63 / 72 SCAR 23.1
CC
10
Cov
90%
deflator
10.7
__ANON__
1.0
__ANON__
1.0
CRAP 10.1
« lib/HTML/FormFu/Filter/Encode.pm ↑ Summary lib/HTML/FormFu/Deflator/PathClassFile.pm »
1 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Deflator::CompoundDateTime;
4 3 $HTML::FormFu::Deflator::CompoundDateTime::VERSION = '2.06';
5 # ABSTRACT: CompoundDateTime deflator
6  
7 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use MooseX::Attribute::Chained;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 extends 'HTML::FormFu::Deflator';
10  
11 3 ▶use HTML::FormFu::Constants qw( $EMPTY_STR );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use List::Util 1.33 qw( none );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 3 has field_order => ( is => 'rw', traits => ['Chained'] );
17  
18 3 my @known_fields = qw( year month day hour minute second nanosecond time_zone );
19  
20 sub deflator {
21 2 ▶ my ( $self, $value ) = @_;
Subroutine deflator: called CC=10 SCAR=23.7
Pod undocumented
22  
23 2 ▶ return if !defined $value || $value eq $EMPTY_STR;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or $value eq $HTML::FormFu::Deflator::CompoundDateTime::EMPTY_STR 0 2 2
Condition33%1/3
not defined $value or $value eq $HTML::FormFu::Deflator::CompoundDateTime::EMPTY_STR
l!l&&r!l&&!r
002
MC/DC0%0/2
not defined $value or $value eq $HTML::FormFu::Deflator::CompoundDateTime::EMPTY_STR
not defined $value $value eq $HTML::FormFu::Deflator::CompoundDateTime::EMPTY_STR
Truth table33%1/3
not(A) or B
A= not defined $valueB= $value eq $HTML::FormFu::Deflator::CompoundDateTime::EMPTY_STR
ABresult
1X1
011
000
24  
25 # do we have a DateTime object?
26  
27 2 eval { $value->$_ for @known_fields };
28  
29 2 ▶ return $value if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
30  
31 2 my ( $multi, @fields ) = @{ $self->parent->get_fields };
32  
33 2 ▶ if ( defined( my $order = $self->field_order ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $order = $self->field_order)) { } 1 1 2
34 1 for my $order (@$order) {
35 croak "unknown DateTime field_order name"
36 3 ▶ if none { $order eq $_ } @known_fields;
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
if &none(sub { $order eq $_; } , @known_fields) 0 3 3
37  
38 3 my $field = shift @fields;
39  
40 3 $field->default( $value->$order );
41 }
42 }
43 else {
44 1 for my $field (@fields) {
45 3 my $name = $field->name;
46  
47 croak "unknown DateTime field name"
48 3 ▶ if none { $name eq $_ } @known_fields;
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
if &none(sub { $name eq $_; } , @known_fields) 0 3 3
49  
50 3 $field->default( $value->$name );
51 }
52 }
53  
54 2 return;
55 }
56  
57 3 __PACKAGE__->meta->make_immutable;
58  
59 3 1;
60  
61 __END__
62  
63 =pod
64  
65 =encoding UTF-8
66  
67 =head1 NAME
68  
69 HTML::FormFu::Deflator::CompoundDateTime - CompoundDateTime deflator
70  
71 =head1 VERSION
72  
73 version 2.06
74  
75 =head1 SYNOPSIS
76  
77 ---
78 element:
79 - type: Multi
80 name: date
81  
82 elements:
83 - name: day
84 - name: month
85 - name: year
86  
87 deflator:
88 - type: CompoundDateTime
89  
90 # set the default
91  
92 $form->get_field('date')->default( $datetime );
93  
94 =head1 DESCRIPTION
95  
96 For use with a L<HTML::FormFu::Element::Multi> group of fields.
97  
98 Sets the default values of several fields from a single L<DateTime> value.
99  
100 By default, expects the field names to be any of the following:
101  
102 =over
103  
104 =item year
105  
106 =item month
107  
108 =item day
109  
110 =item hour
111  
112 =item minute
113  
114 =item second
115  
116 =item nanosecond
117  
118 =item time_zone
119  
120 =back
121  
122 =head1 METHODS
123  
124 =head2 field_order
125  
126 Arguments: \@order
127  
128 If your field names don't follow the convention listed above, you must
129 provide an arrayref containing the above names, in the order they correspond
130 with your own fields.
131  
132 ---
133 element:
134 - type: Multi
135 name: date
136  
137 elements:
138 - name: m
139 - name: d
140 - name: y
141  
142 deflator:
143 - type: CompoundDateTime
144 field_order:
145 - month
146 - day
147 - year
148  
149 =head1 AUTHOR
150  
151 Carl Franks
152  
153 =head1 LICENSE
154  
155 This library is free software, you can redistribute it and/or modify it under
156 the same terms as Perl itself.
157  
158 =head1 AUTHOR
159  
160 Carl Franks <cpan@fireartist.com>
161  
162 =head1 COPYRIGHT AND LICENSE
163  
164 This software is copyright (c) 2018 by Carl Franks.
165  
166 This is free software; you can redistribute it and/or modify it under
167 the same terms as the Perl 5 programming language system itself.
168  
169 =cut
« lib/HTML/FormFu/Filter/Encode.pm ↑ Summary lib/HTML/FormFu/Deflator/PathClassFile.pm »