Nested/Filter/DateTime.pm

filter: Statementstmt 85.0% 34 / 40 Branchbran 41.6% 5 / 12 Conditioncond 25.0% 2 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 67.1% 49 / 73 CC 12 SCAR 29.2
CC
12
Cov
68%
date
27.4
BEGIN
1.0
BEGIN
1.0
CRAP 18.6
« Nested/Validator/DBIC.pm ↑ Summary Nested/Validator/File.pm »
1 package FormValidator::Nested::Filter::DateTime;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use DateTime::TimeZone;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use FormValidator::Nested::FilterInvalid;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 our $time_zone = DateTime::TimeZone->new(name => 'Asia/Tokyo');
11  
12  
13 117 ▶sub date {
Subroutine date: called CC=12 SCAR=33.1
Pod undocumented
14 117 my ( $value, $options, $req ) = @_;
15 117 my %datetime_args = ();
16  
17 117 ▶ if ( $options->{prefix} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($options->{'prefix'}) { } 117 0 117
elsif ($options->{'regex'}) { } 0 0 0
18 117 foreach my $target ( qw/year month day/ ) {
19 206 my $val = $req->param($options->{prefix} . '_' . $target);
20 206 ▶ if ( !defined($val) || $val eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $val or $val eq "") 74 132 206
Condition66%2/3
not defined $val or $val eq ""
l!l&&r!l&&!r
740132
MC/DC50%1/2
not defined $val or $val eq ""
not defined $val $val eq ""
Truth table66%2/3
not(A) or B
A= not defined $valB= $val eq ""
ABresult
1X1
011
000
21 74 return '';
22 }
23 132 $datetime_args{$target} = $val;
24 }
25 }
26 elsif ( $options->{regex} ) {
27 0 ▶ if ( !defined($value) || $value eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $value or $value eq "") 0 0 0
Condition0%0/3
not defined $value or $value eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $value or $value eq ""
not defined $value $value eq ""
Truth table0%0/3
not(A) or B
A= not defined $valueB= $value eq ""
ABresult
1X1
011
000
28 0 return '';
29 }
30 0 ▶ my $params = $options->{params} || [qw/year month day/];
Condition0%0/2
$options->{'params'} || ['year', 'month', 'day']
l!l
00
MC/DC0%0/1
$options->{'params'} || ['year', 'month', 'day']
$options->{'params'}
Truth table0%0/2
A
A= $options->{'params'}
Aresult
11
00
31 0 ▶ if ( $value =~ /$options->{regex}/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /$options->{"regex"}/) 0 0 0
32 0 for my $idx ( 1..@$params ) {
33 0 $datetime_args{$params->[$idx-1]} = eval "\$$idx"; ## no critic
34 }
35 }
36 }
37  
38 43 my $dt;
39 43 eval {
40 43 $dt = DateTime->new(
41 time_zone => $time_zone,
42 %datetime_args,
43 );
44 };
45 43 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 8 35 43
46 8 return FormValidator::Nested::FilterInvalid->new;
47 }
48 35 return $dt;
49 }
50  
51 4 1;
52  
« Nested/Validator/DBIC.pm ↑ Summary Nested/Validator/File.pm »