lib/HTML/FormFu/Inflator/CompoundDateTime.pm

filter: Statementstmt 98.4% 62 / 63 Branchbran 57.1% 8 / 14 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 1 totaltotal 85.7% 84 / 98 CC 12 SCAR 20.0
CC
12
Cov
88%
inflator
13.3
__ANON__
1.0
__ANON__
1.0
CRAP 7.4
« lib/HTML/FormFu/Constraint/Regex.pm ↑ Summary lib/HTML/FormFu/Element/Repeatable.pm »
1 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Inflator::CompoundDateTime;
4 5 $HTML::FormFu::Inflator::CompoundDateTime::VERSION = '2.09';
5 # ABSTRACT: CompoundDateTime inflator
6  
7 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use MooseX::Attribute::Chained;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 extends 'HTML::FormFu::Inflator';
10  
11 5 ▶use HTML::FormFu::Constants qw( $EMPTY_STR );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use DateTime::Format::Strptime;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use List::Util 1.33 qw( none );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use Scalar::Util qw( reftype );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 5 has strptime => ( is => 'rw', traits => ['Chained'] );
19 5 has field_order => ( is => 'rw', traits => ['Chained'] );
20  
21 5 my @known_fields = qw( year month day hour minute second nanosecond time_zone );
22  
23 2 ▶sub inflator {
Subroutine inflator: called CC=12 SCAR=25.9
Pod undocumented
24 2 my ( $self, $value ) = @_;
25  
26 2 ▶ return if !defined $value || $value eq $EMPTY_STR;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or $value eq $HTML::FormFu::Inflator::CompoundDateTime::EMPTY_STR 0 2 2
Condition33%1/3
not defined $value or $value eq $HTML::FormFu::Inflator::CompoundDateTime::EMPTY_STR
l!l&&r!l&&!r
002
MC/DC0%0/2
not defined $value or $value eq $HTML::FormFu::Inflator::CompoundDateTime::EMPTY_STR
not defined $value $value eq $HTML::FormFu::Inflator::CompoundDateTime::EMPTY_STR
Truth table33%1/3
not(A) or B
A= not defined $valueB= $value eq $HTML::FormFu::Inflator::CompoundDateTime::EMPTY_STR
ABresult
1X1
011
000
27  
28 2 my ( $multi, @fields ) = @{ $self->parent->get_fields };
29 2 my %input;
30  
31 2 ▶ if ( defined( my $order = $self->field_order ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $order = $self->field_order)) { } 1 1 2
32 1 for my $order (@$order) {
33 croak "unknown DateTime field_order name"
34 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
35  
36 3 my $field = shift @fields;
37 3 my $name = $field->name;
38  
39 3 $input{$order} = $value->{$name};
40 }
41 }
42 else {
43 1 for my $name ( keys %$value ) {
44 croak "unknown DateTime field name"
45 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
46 }
47  
48 1 %input = %$value;
49 }
50  
51 2 my $dt;
52  
53 2 eval { $dt = DateTime->new(%input) };
54  
55 2 ▶ return $value if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
56  
57 2 ▶ if ( defined $self->strptime ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->strptime) 2 0 2
58 2 my $strptime = $self->strptime;
59 2 my %args;
60  
61 2 ▶ if ( ( reftype($strptime) || '' ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ((builtin::reftype($strptime) || '') eq 'HASH') { } 0 2 2
Condition50%1/2
builtin::reftype($strptime) || ''
l!l
02
MC/DC0%0/1
builtin::reftype($strptime) || ''
builtin::reftype($strptime)
Truth table50%1/2
A
A= builtin::reftype($strptime)
Aresult
11
00
62 0 %args = %$strptime;
63 }
64 else {
65 2 %args = ( pattern => $strptime );
66 }
67  
68 2 my $formatter = DateTime::Format::Strptime->new(%args);
69  
70 2 $dt->set_formatter($formatter);
71 }
72  
73 2 return $dt;
74 }
75  
76 5 __PACKAGE__->meta->make_immutable;
77  
78 5 1;
79  
80 __END__
« lib/HTML/FormFu/Constraint/Regex.pm ↑ Summary lib/HTML/FormFu/Element/Repeatable.pm »