lib/HTML/FormFu/Inflator/DateTime.pm

filter: Statementstmt 98.2% 55 / 56 Branchbran 92.8% 13 / 14 Conditioncond 81.8% 9 / 11 MC/DCmcdc 71.4% 5 / 7 Subroutinesub 100% 11 / 11 Podpod 33.3% 1 / 3 totaltotal 92.1% 94 / 102 CC 12 SCAR 16.9
CC
12
Cov
95%
inflator
10.1
parser
3.0
BEGIN
1.0
CRAP 5.4
« lib/HTML/FormFu/Transformer.pm ↑ Summary lib/HTML/FormFu/Constraint/Range.pm »
1 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Inflator::DateTime;
4 27 $HTML::FormFu::Inflator::DateTime::VERSION = '2.09';
5 # ABSTRACT: DateTime inflator
6  
7 27 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 27 ▶use MooseX::Attribute::Chained;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 27 extends 'HTML::FormFu::Inflator';
10  
11 27 ▶use HTML::FormFu::Constants qw( $EMPTY_STR );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 27 ▶use DateTime::Format::Builder;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 27 ▶use DateTime::Format::Strptime;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 27 ▶use Scalar::Util qw( reftype );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 27 has strptime => ( is => 'rw', traits => ['Chained'] );
17 27 has time_zone => ( is => 'rw', traits => ['Chained'] );
18  
19 has _builder => (
20 is => 'rw',
21 26 ▶ default => sub { DateTime::Format::Builder->new },
Subroutine __ANON__: called CC=1 SCAR=0.0
22 27 lazy => 1,
23 );
24  
25 26 ▶sub parser {
Subroutine parser: called CC=3 SCAR=11.0
Pod documented
26 26 my ( $self, $arg ) = @_;
27  
28 26 ▶ if ( exists $arg->{regex} && !ref $arg->{regex} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $arg->{"regex"} and not ref $arg->{"regex"}) 1 25 26
Condition100%3/3
exists $arg->{"regex"} and not ref $arg->{"regex"}
!ll&&!rl&&r
2411
MC/DC100%2/2
exists $arg->{"regex"} and not ref $arg->{"regex"}
exists $arg->{"regex"} not ref $arg->{"regex"}
Truth table100%3/3
A and not(B)
A= exists $arg->{"regex"}B= not ref $arg->{"regex"}
ABresult
0X0
100
111
29 1 $arg->{regex} = qr/$arg->{regex}/;
30 }
31  
32 26 $self->_builder->parser($arg);
33  
34 26 return $self;
35 }
36  
37 27 ▶sub inflator {
Subroutine inflator: called CC=10 SCAR=23.1
Pod undocumented
38 27 my ( $self, $value ) = @_;
39  
40 27 ▶ return if !defined $value || $value eq $EMPTY_STR;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or $value eq $HTML::FormFu::Inflator::DateTime::EMPTY_STR 2 25 27
Condition100%3/3
not defined $value or $value eq $HTML::FormFu::Inflator::DateTime::EMPTY_STR
l!l&&r!l&&!r
1125
MC/DC100%2/2
not defined $value or $value eq $HTML::FormFu::Inflator::DateTime::EMPTY_STR
not defined $value $value eq $HTML::FormFu::Inflator::DateTime::EMPTY_STR
Truth table100%3/3
not(A) or B
A= not defined $valueB= $value eq $HTML::FormFu::Inflator::DateTime::EMPTY_STR
ABresult
1X1
011
000
41  
42 25 my $dt = $self->_builder->parse_datetime($value);
43  
44 22 ▶ if ( defined $self->time_zone ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->time_zone) 1 21 22
45 1 $dt->set_time_zone( $self->time_zone );
46 }
47  
48 22 ▶ if ( defined $self->strptime ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->strptime) 11 11 22
49 11 my $strptime = $self->strptime;
50 11 my %args;
51  
52 11 ▶ if ( ( reftype($strptime) || '' ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ((builtin::reftype($strptime) || '') eq 'HASH') { } 2 9 11
Condition100%2/2
builtin::reftype($strptime) || ''
l!l
29
MC/DC100%1/1
builtin::reftype($strptime) || ''
builtin::reftype($strptime)
Truth table100%2/2
A
A= builtin::reftype($strptime)
Aresult
11
00
53 2 %args = %$strptime;
54 }
55 else {
56 9 %args = ( pattern => $strptime );
57 }
58  
59 # Make strptime format the date with the specified time_zone,
60 # this is most likely what the user wants
61 11 ▶ if ( defined $self->time_zone ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->time_zone) 1 10 11
62 1 $args{time_zone} = $self->time_zone;
63 }
64  
65 11 ▶ if ( !exists $args{locale}
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $args{"locale"} and defined(my $locale = $self->locale)) 0 11 11
Condition33%1/3
not exists $args{"locale"} and defined(my $locale = $self->locale)
!ll&&!rl&&r
0110
MC/DC0%0/2
not exists $args{"locale"} and defined(my $locale = $self->locale)
not exists $args{"locale"} defined(my $locale = $self->locale)
Truth table33%1/3
not(A) and B
A= not exists $args{"locale"}B= defined(my $locale = $self->locale)
ABresult
0X0
100
111
66 && defined( my $locale = $self->locale ) )
67 {
68 0 $args{locale} = $locale;
69 }
70  
71 11 my $formatter = DateTime::Format::Strptime->new(%args);
72  
73 11 $dt->set_formatter($formatter);
74 }
75  
76 22 return $dt;
77 }
78  
79 2 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod undocumented
80 2 my $self = shift;
81  
82 2 my $clone = $self->SUPER::clone(@_);
83  
84 2 $clone->_builder( $self->_builder->clone );
85  
86 2 return $clone;
87 }
88  
89 27 __PACKAGE__->meta->make_immutable;
90  
91 27 1;
92  
93 __END__
« lib/HTML/FormFu/Transformer.pm ↑ Summary lib/HTML/FormFu/Constraint/Range.pm »