| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
$schema_type eq $given_type or $schema_type eq "number" and $given_type eq "integer"
$schema_type eq "number" and $given_type eq "integer"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 515 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 272 | ▶ | if ( $given_type eq "number_or_string" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 10 | ▶ | return 1 if ( $schema_type eq "string" || $schema_type eq "number" ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$schema_type eq "string" or $schema_type eq "number"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
$schema_type eq "string" or $schema_type eq "number" or $schema_type eq "integer"
$schema_type eq "string" or $schema_type eq "number"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 160 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 45 | 1; | |||||||||||||||||||||||||||||||||||||||||