| 1 | package Workflow::Validator::MatchesDateFormat; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 15 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 15 | ▶ | use v5.14.0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 15 | ▶ | use parent qw( Workflow::Validator ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 15 | ▶ | use DateTime::Format::Strptime; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 15 | ▶ | use Workflow::Exception qw( configuration_error validation_error ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 15 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 15 | $Workflow::Validator::MatchesDateFormat::VERSION = '2.12'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 15 | __PACKAGE__->mk_accessors('formatter'); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 18 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 18 | my ( $self, $params ) = @_; | |||||||||||||||||||||||||||
| 17 | 18 | $self->SUPER::init( $params ); | |||||||||||||||||||||||||||
| 18 | 18 | ▶ | unless ( $params->{date_format} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 1 | configuration_error "You must define a value for 'date_format' in ", | |||||||||||||||||||||||||||
| 20 | "declaration of validator ", $self->name; | ||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | 17 | ▶ | if ( ref $params->{date_format} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 1 | configuration_error | |||||||||||||||||||||||||||
| 24 | "The value for 'date_format' must be a simple scalar in ", | ||||||||||||||||||||||||||||
| 25 | "declaration of validator ", $self->name; | ||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | my $formatter = DateTime::Format::Strptime->new( | ||||||||||||||||||||||||||||
| 28 | pattern => $params->{date_format}, | ||||||||||||||||||||||||||||
| 29 | 16 | on_error => 'undef' | |||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||
| 31 | 16 | $self->formatter($formatter); | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 15 | ▶ | sub validate { | ||||||||||||||||||||||||||
|
Subroutine
validate: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 15 | my ( $self, $wf, $date_string ) = @_; | |||||||||||||||||||||||||||
| 36 | 15 | ▶ | return unless ($date_string); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 13 | ▶ | if ( blessed $date_string and $date_string->isa('DateTime') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($date_string) and $date_string->isa("DateTime")
MC/DC100%2/2
builtin::blessed($date_string) and $date_string->isa("DateTime")
builtin::blessed($date_string)
$date_string->isa("DateTime")
Truth table100%3/3
A and B
A= builtin::blessed($date_string)B= $date_string->isa("DateTime")
| |||||||||||||||||||||||||||||
| 39 | # already converted! | ||||||||||||||||||||||||||||
| 40 | 9 | return; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 4 | my $fmt = $self->formatter; | |||||||||||||||||||||||||||
| 44 | 4 | my $date_object = $fmt->parse_datetime($date_string); | |||||||||||||||||||||||||||
| 45 | 4 | ▶ | unless ($date_object) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 2 | validation_error | |||||||||||||||||||||||||||
| 47 | "Date '$date_string' does not match required pattern '", | ||||||||||||||||||||||||||||
| 48 | $fmt->pattern, "'"; | ||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 15 | 1; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | __END__ | ||||||||||||||||||||||||||||