blib/lib/JSV/Keyword/Draft4/Type.pm

filter: Statementstmt 100% 40 / 40 Branchbran 100% 16 / 16 Conditioncond 93.3% 14 / 15 MC/DCmcdc 87.5% 7 / 8 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 2 totaltotal 95.6% 88 / 92 SCAR 26.4
CC
14
Cov
99%
validate_singular_type
11.0
validate
4.0
BEGIN
1.0
CRAP 14.0
« blib/lib/JSV/Util/Type.pm ↑ Summary blib/lib/JSV/Keyword/Draft4/Properties.pm »
1 package JSV::Keyword::Draft4::Type;
2  
3 45 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 45 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 45 ▶use parent qw(JSV::Keyword);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 45 ▶use B;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 45 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 45 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 45 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 45 ▶use JSV::Keyword qw(:constants);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 sub instance_type() { INSTANCE_TYPE_ANY(); }
15 sub keyword() { "type" }
16 sub keyword_priority() { 10; }
17  
18 sub validate {
19 777 ▶ my ($class, $context, $schema, $instance) = @_;
Subroutine validate: called CC=4 SCAR=13.9
Pod undocumented
20  
21 777 my $keyword_value = $class->keyword_value($schema);
22  
23 777 ▶ if (ref $keyword_value eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $keyword_value eq 'ARRAY') { } 13 764 777
24 13 ▶ unless ( first { $class->validate_singular_type( $context, $_, $context->current_type, $instance ) } @$keyword_value ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
unless (&first(sub { $class->validate_singular_type($context, $_, $context->current_type, $instance); } , @$keyword_value)) 7 6 13
25 7 $context->log_error("instance type doesn't match schema type list");
26 }
27 }
28 else {
29 764 ▶ unless ($class->validate_singular_type( $context, $keyword_value, $context->current_type, $instance )) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->validate_singular_type($context, $keyword_value, $context->current_type, $instance)) 143 621 764
30 143 $context->log_error("instance type doesn't match schema type");
31 }
32 }
33 }
34  
35 sub validate_singular_type {
36 787 ▶ my ($class, $context, $schema_type, $given_type, $instance) = @_;
Subroutine validate_singular_type: called CC=11 SCAR=24.0
Pod undocumented
37  
38 787 ▶ if ( $schema_type eq $given_type || ( $schema_type eq "number" && $given_type eq "integer") ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema_type eq $given_type or $schema_type eq 'number' and $given_type eq 'integer') { } 515 272 787
Condition100%6/6
$schema_type eq $given_type or $schema_type eq "number" and $given_type eq "integer"
l!l&&r!l&&!r
45461272
$schema_type eq "number" and $given_type eq "integer"
!ll&&!rl&&r
17210061
MC/DC100%3/3
$schema_type eq $given_type or $schema_type eq "number" and $given_type eq "integer"
$schema_type eq $given_type $schema_type eq "number" $given_type eq "integer"
Truth table100%4/4
A or B and C
A= $schema_type eq $given_typeB= $schema_type eq "number"C= $given_type eq "integer"
ABCresult
1XX1
0111
00X0
0100
39 515 return 1;
40 }
41 else {
42 272 ▶ if ( $given_type eq "number_or_string" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($given_type eq 'number_or_string') { } 10 262 272
elsif ($given_type eq 'integer_or_string') { } 106 156 262
43 10 ▶ return 1 if ( $schema_type eq "string" || $schema_type eq "number" );
Branch: 1 branch
BranchTrueFalseTotal
if $schema_type eq "string" or $schema_type eq "number" 8 2 10
Condition66%2/3
$schema_type eq "string" or $schema_type eq "number"
l!l&&r!l&&!r
082
MC/DC50%1/2
$schema_type eq "string" or $schema_type eq "number"
$schema_type eq "string" $schema_type eq "number"
Truth table66%2/3
A or B
A= $schema_type eq "string"B= $schema_type eq "number"
ABresult
1X1
011
000
44 }
45 elsif ( $given_type eq "integer_or_string" ) {
46 106 ▶ return 1 if ( $schema_type eq "string" || $schema_type eq "number" || $schema_type eq "integer" );
Branch: 1 branch
BranchTrueFalseTotal
if $schema_type eq "string" or $schema_type eq "number" or $schema_type eq "integer" 93 2 95
Condition100%6/6
$schema_type eq "string" or $schema_type eq "number" or $schema_type eq "integer"
l!l&&r!l&&!r
75292
$schema_type eq "string" or $schema_type eq "number"
l!l&&r!l&&!r
116431
MC/DC100%3/3
$schema_type eq "string" or $schema_type eq "number" or $schema_type eq "integer"
$schema_type eq "string" $schema_type eq "number" $schema_type eq "integer"
Truth table100%4/4
A or B or C
A= $schema_type eq "string"B= $schema_type eq "number"C= $schema_type eq "integer"
ABCresult
1XX1
01X1
0011
0000
47 }
48 160 return 0;
49 }
50 }
51  
52 45 1;
« blib/lib/JSV/Util/Type.pm ↑ Summary blib/lib/JSV/Keyword/Draft4/Properties.pm »