blib/lib/Valiemon/Attributes/Format.pm

filter: Statementstmt 100% 33 / 33 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 2 totaltotal 96.3% 52 / 54 CC 5 SCAR 5.1
CC
5
Cov
100%
__ANON__
3.0
is_valid
2.0
_validate_date_time
2.0
CRAP 1.7
« blib/lib/Valiemon/Attributes.pm ↑ Summary blib/lib/Valiemon/Attributes/Type.pm »
1 package Valiemon::Attributes::Format;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use parent qw(Valiemon::Attributes);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Data::Validate::URI qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 40 ▶sub attr_name { 'format' }
Subroutine attr_name: called CC=1 SCAR=0.0
Pod undocumented
11  
12 sub is_valid {
13 41 ▶ my ($class, $context, $schema, $data) = @_;
Subroutine is_valid: called CC=2 SCAR=6.9
Pod undocumented
14  
15 41 ▶ return 1 unless $context->prims->is_string($data);
Branch: 1 branch
BranchTrueFalseTotal
unless $context->prims->is_string($data) 1 40 41
16  
17 $context->in_attr($class, sub {
18 40 ▶ my $format = $schema->{format};
Subroutine __ANON__: called CC=3 SCAR=11.0
19  
20 40 ▶ if ($format eq 'date-time') {
Branch: 1 branch
BranchTrueFalseTotal
if ($format eq "date-time") 10 30 40
21 10 return _validate_date_time($data);
22 }
23  
24 30 ▶ if ($format eq 'uri') {
Branch: 1 branch
BranchTrueFalseTotal
if ($format eq "uri") 16 14 30
25 16 return _validate_uri($data);
26 }
27  
28 # TODO: email, hostname, ipv4, ipv6
29  
30 14 croak sprintf 'invalid format: `%s`', $format;
31 40 });
32 }
33  
34 sub _validate_date_time {
35 10 ▶ my ($data) = @_;
Subroutine _validate_date_time: called CC=2 SCAR=6.9
36 # TODO: check range of value (date-month must be `01-12` etc...)
37 10 ▶ $data =~ /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})/ ? : 5 5 10
38 }
39  
40 sub _validate_uri {
41 16 ▶ my ($data) = @_;
Subroutine _validate_uri: called CC=1 SCAR=0.0
42 16 Data::Validate::URI::is_uri($data);
43 }
44  
45 3 1;
« blib/lib/Valiemon/Attributes.pm ↑ Summary blib/lib/Valiemon/Attributes/Type.pm »