blib/lib/Salvation/TC/Type/Date.pm

filter: Statementstmt 64.5% 20 / 31 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 36.9% 27 / 73 SCAR 39.4
CC
12
Cov
35%
Check
156.0
BEGIN
1.0
BEGIN
1.0
CRAP 51.4
« blib/lib/Salvation/TC/Type/Time.pm ↑ Summary blib/lib/Salvation/TC/Meta/Type.pm »
1 package Salvation::TC::Type::Date;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use base 'Salvation::TC::Type';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use Salvation::TC::Type::Time ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Salvation::TC::Exception::WrongType ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Time::Piece ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 my $re = qr/^(\d{1,2})[\.\/\-](\d{1,2})[\.\/\-](\d{4})\s*(\d+:\d+(:\d+)*?)?$/;
13  
14 sub Check {
15  
16 0 ▶ my ( $class, $date ) = @_;
Subroutine Check: not called CC=12 SCAR=50.5
Pod documented
17  
18 0 eval {
19  
20 0 ▶ die "Wrong date format. Expected day[.-/]month[./-]year time" if ( ! defined( $date ) || $date !~ $re );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date and $date =~ /$re/ 0 0 0
Condition0%0/3
defined $date and $date =~ /$re/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $date and $date =~ /$re/
defined $date $date =~ /$re/
Truth table0%0/3
A and B
A= defined $dateB= $date =~ /$re/
ABresult
0X0
100
111
21  
22 0 my ( $day, $month, $year, $time ) = ( $1, $2, $3, $4 );
23  
24 0 ▶ die "Month must be between 1 and 12. Current value is $month." unless $month >= 1 && $month <= 12;
Branch: 1 branch
BranchTrueFalseTotal
unless $month >= 1 and $month <= 12 0 0 0
Condition0%0/3
$month >= 1 and $month <= 12
!ll&&!rl&&r
000
MC/DC0%0/2
$month >= 1 and $month <= 12
$month >= 1 $month <= 12
Truth table0%0/3
A and B
A= $month >= 1B= $month <= 12
ABresult
0X0
100
111
25 0 ▶ die "Day must be between 1 and 31. Current value is $day." unless $day >= 1 && $day <= 31;
Branch: 1 branch
BranchTrueFalseTotal
unless $day >= 1 and $day <= 31 0 0 0
Condition0%0/3
$day >= 1 and $day <= 31
!ll&&!rl&&r
000
MC/DC0%0/2
$day >= 1 and $day <= 31
$day >= 1 $day <= 31
Truth table0%0/3
A and B
A= $day >= 1B= $day <= 31
ABresult
0X0
100
111
26 0 ▶ die "Year must be between 1900 and 2110. Current value is $year." unless $year >= 1900 && $year <= 2110;
Branch: 1 branch
BranchTrueFalseTotal
unless $year >= 1900 and $year <= 2110 0 0 0
Condition0%0/3
$year >= 1900 and $year <= 2110
!ll&&!rl&&r
000
MC/DC0%0/2
$year >= 1900 and $year <= 2110
$year >= 1900 $year <= 2110
Truth table0%0/3
A and B
A= $year >= 1900B= $year <= 2110
ABresult
0X0
100
111
27  
28 0 ▶ Salvation::TC::Type::Time->Check( $time ) if ( $time );
Branch: 1 branch
BranchTrueFalseTotal
if $time 0 0 0
29  
30 0 ▶ defined( Time::Piece -> strptime( "$year-$month-$day", '%Y-%m-%d' ) ) || die "Unknow date format: $date.";
Branch: 1 branch
BranchTrueFalseTotal
defined "Time::Piece"->strptime("$year-$month-$day", "%Y-%m-%d") or die "Unknow date format: $date." 0 0 0
31 };
32  
33 0 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
34  
35 0 Salvation::TC::Exception::WrongType -> throw( type => 'Date', value => $date );
36 };
37 }
38  
39 4 1;
40 __END__
« blib/lib/Salvation/TC/Type/Time.pm ↑ Summary blib/lib/Salvation/TC/Meta/Type.pm »