| 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
Condition0%0/3
defined $date and $date =~ /$re/
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/
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$month >= 1 and $month <= 12
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
| |||||||||||||||||||||||||||||
| 25 | 0 | ▶ | die "Day must be between 1 and 31. Current value is $day." unless $day >= 1 && $day <= 31; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$day >= 1 and $day <= 31
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
| |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | die "Year must be between 1900 and 2110. Current value is $year." unless $year >= 1900 && $year <= 2110; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$year >= 1900 and $year <= 2110
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
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | Salvation::TC::Type::Time->Check( $time ) if ( $time ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | defined( Time::Piece -> strptime( "$year-$month-$day", '%Y-%m-%d' ) ) || die "Unknow date format: $date."; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | }; | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | Salvation::TC::Exception::WrongType -> throw( type => 'Date', value => $date ); | |||||||||||||||||||||||||||
| 36 | }; | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 4 | 1; | |||||||||||||||||||||||||||
| 40 | __END__ | ||||||||||||||||||||||||||||