| 1 | 38 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 38 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package JSON::Schema::Modern::Vocabulary::FormatAnnotation; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # vim: set ts=8 sts=2 sw=2 tw=100 et : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Implementation of the JSON Schema Format-Annotation vocabulary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 38 | our $VERSION = '0.654'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 38 | ▶ | use 5.020; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 38 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 38 | ▶ | use strictures 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 38 | ▶ | use stable 0.031 'postderef'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 38 | ▶ | use experimental 'signatures'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 38 | ▶ | no autovivification warn => qw(fetch store exists delete); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 38 | ▶ | use if "$]" >= 5.022, experimental => 're_strict'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 38 | ▶ | no if "$]" >= 5.031009, feature => 'indirect'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 38 | ▶ | no if "$]" >= 5.033001, feature => 'multidimensional'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 38 | ▶ | no if "$]" >= 5.033006, feature => 'bareword_filehandles'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 38 | ▶ | no if "$]" >= 5.041009, feature => 'smartmatch'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 38 | ▶ | no feature 'switch'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 38 | ▶ | use Feature::Compat::Try; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 38 | ▶ | use JSON::Schema::Modern::Utilities qw(A E assert_keyword_type get_type); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 38 | ▶ | use JSON::Schema::Modern::Vocabulary::FormatAssertion; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 38 | ▶ | use if "$]" < 5.041010, 'List::Util' => 'any'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 38 | ▶ | use if "$]" >= 5.041010, experimental => 'keyword_any'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 38 | ▶ | use Scalar::Util 'looks_like_number'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 38 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 38 | with 'JSON::Schema::Modern::Vocabulary'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 22 | ▶ | sub vocabulary ($class) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
vocabulary: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 22 | 'https://json-schema.org/draft/2019-09/vocab/format' => 'draft2019-09', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 'https://json-schema.org/draft/2020-12/vocab/format-annotation' => 'draft2020-12'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | ▶ | sub evaluation_order ($class) { 2 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evaluation_order: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 162 | ▶ | sub keywords ($class, $spec_version) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
keywords: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 162 | qw(format); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 1481 | ▶ | sub _traverse_keyword_format ($class, $schema, $state) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_traverse_keyword_format: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 1481 | ▶ | return if not assert_keyword_type($state, $schema, 'string'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1481 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 2008 | ▶ | sub _eval_keyword_format ($class, $data, $schema, $state) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_eval_keyword_format: called CC=14 SCAR=26.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 2008 | A($state, $schema->{format}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 2008 | ▶ | return 1 if not $state->{validate_formats}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # { type => .., sub => .. } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | my $spec = $state->{evaluator}->_get_format_validation($schema->{format}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 966 | ▶ | // JSON::Schema::Modern::Vocabulary::FormatAssertion->_get_default_format_validation($state, $schema->{format}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$$state{"evaluator"}->_get_format_validation($$schema{"format"}) // "JSON::Schema::Modern::Vocabulary::FormatAssertion"->_get_default_format_validation($state, $$schema{"format"})
MC/DC100%2/2
$$state{"evaluator"}->_get_format_validation($$schema{"format"}) // "JSON::Schema::Modern::Vocabulary::FormatAssertion"->_get_default_format_validation($state, $$schema{"format"})
$$state{"evaluator"}->_get_format_validation($$schema{"format"})
"JSON::Schema::Modern::Vocabulary::FormatAssertion"->_get_default_format_validation($state, $$schema{"format"})
Truth table100%3/3
A // B
A= $$state{"evaluator"}->_get_format_validation($$schema{"format"})B= "JSON::Schema::Modern::Vocabulary::FormatAssertion"->_get_default_format_validation($state, $$schema{"format"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # §7.2.1 (draft2020-12) "Specifying the Format-Annotation vocabulary and enabling validation in an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # implementation should not be viewed as being equivalent to specifying the Format-Assertion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # vocabulary since implementations are not required to provide full validation support when the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # Format-Assertion vocabulary is not specified." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # §7.2.3 (draft2019-09) "An implementation MUST NOT fail validation or cease processing due to an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # unknown format attribute." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 966 | ▶ | return 1 if not $spec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 809 | my $type = get_type($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 809 | ▶ | $type = 'number' if $type eq 'integer'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | return 1 if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 67 | ▶ | not ref $spec->{type} eq 'ARRAY' ? any { $type eq $_ } $spec->{type}->@* : $type eq $spec->{type} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
$$state{"stringy_numbers"} and $type eq "string" and ref $$spec{"type"} eq "ARRAY" ? CORE::any({$_ eq "number";} @{$$spec{"type"}}) : $$spec{"type"} eq "number" and &looks_like_number($data)
$$state{"stringy_numbers"} and $type eq "string" and ref $$spec{"type"} eq "ARRAY" ? CORE::any({$_ eq "number";} @{$$spec{"type"}}) : $$spec{"type"} eq "number"
$$state{"stringy_numbers"} and $type eq "string"
MC/DC0%0/4
$$state{"stringy_numbers"} and $type eq "string" and ref $$spec{"type"} eq "ARRAY" ? CORE::any({$_ eq "number";} @{$$spec{"type"}}) : $$spec{"type"} eq "number" and &looks_like_number($data)
$$state{"stringy_numbers"}
$type eq "string"
ref $$spec{"type"} eq "ARRAY" ? CORE::any({$_ eq "number";} @{$$spec{"type"}}) : $$spec{"type"} eq "number"
&looks_like_number($data)
Truth table0%0/5
A and B and C and D
A= $$state{"stringy_numbers"}B= $type eq "string"C= ref $$spec{"type"} eq "ARRAY" ? CORE::any({$_ eq "number";} @{$$spec{"type"}}) : $$spec{"type"} eq "number"D= &looks_like_number($data)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | and not ($state->{stringy_numbers} and $type eq 'string' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | and ref $spec->{type} eq 'ARRAY' ? any { $_ eq 'number' } $spec->{type}->@* : $spec->{type} eq 'number' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
ref $$spec{"type"} eq "ARRAY" ? CORE::any({$type eq $_;} @{$$spec{"type"}}) : $type eq $$spec{"type"} or $$state{"stringy_numbers"} and $type eq "string" and ref $$spec{"type"} eq "ARRAY" ? CORE::any({$_ eq "number";} @{$$spec{"type"}}) : $$spec{"type"} eq "number" and &looks_like_number($data)
MC/DC100%2/2
ref $$spec{"type"} eq "ARRAY" ? CORE::any({$type eq $_;} @{$$spec{"type"}}) : $type eq $$spec{"type"} or $$state{"stringy_numbers"} and $type eq "string" and ref $$spec{"type"} eq "ARRAY" ? CORE::any({$_ eq "number";} @{$$spec{"type"}}) : $$spec{"type"} eq "number" and &looks_like_number($data)
ref $$spec{"type"} eq "ARRAY" ? CORE::any({$type eq $_;} @{$$spec{"type"}}) : $type eq $$spec{"type"}
$$state{"stringy_numbers"} and $type eq "string" and ref $$spec{"type"} eq "ARRAY" ? CORE::any({$_ eq "number";} @{$$spec{"type"}}) : $$spec{"type"} eq "number" and &looks_like_number($data)
Truth table100%3/3
A or B
A= ref $$spec{"type"} eq "ARRAY" ? CORE::any({$type eq $_;} @{$$spec{"type"}}) : $type eq $$spec{"type"}B= $$state{"stringy_numbers"} and $type eq "string" and ref $$spec{"type"} eq "ARRAY" ? CORE::any({$_ eq "number";} @{$$spec{"type"}}) : $$spec{"type"} eq "number" and &looks_like_number($data)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | and looks_like_number($data)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 457 | my $valid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 457 | try { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 457 | $valid = $spec->{sub}->($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | catch ($e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # we treat a missing optional prereq as if the format is not implemented, therefore it is valid | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 10 | $valid = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | return E($state, 'not a valid %s %s', $schema->{format}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | ref $spec->{type} eq 'ARRAY' ? join(', ', $spec->{type}->@*) : $spec->{type}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 457 | ▶ | if not $valid; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 234 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 38 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||