Workflow/Validator/MatchesDateFormat.pm

filter: Statementstmt 100% 39 / 39 Branchbran 100% 10 / 10 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 100% 65 / 65 CC 7 SCAR 10.1
CC
7
Cov
100%
validate
5.0
init
3.0
BEGIN
1.0
CRAP 2.7
« Workflow/Persister.pm ↑ Summary Workflow/Validator/HasRequiredField.pm »
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
BranchTrueFalseTotal
unless ($params->{"date_format"}) 1 17 18
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
BranchTrueFalseTotal
if (ref $params->{"date_format"}) 1 16 17
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
BranchTrueFalseTotal
unless $date_string 2 13 15
37  
38 13 ▶ if ( blessed $date_string and $date_string->isa('DateTime') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($date_string) and $date_string->isa("DateTime")) 9 4 13
Condition100%3/3
builtin::blessed($date_string) and $date_string->isa("DateTime")
!ll&&!rl&&r
319
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")
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless ($date_object) 2 2 4
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__
« Workflow/Persister.pm ↑ Summary Workflow/Validator/HasRequiredField.pm »