Modern/Vocabulary/FormatAnnotation.pm

filter: Statementstmt 98.8% 84 / 85 Branchbran 88.8% 16 / 18 Conditioncond 86.6% 13 / 15 MC/DCmcdc 50.0% 4 / 8 Subroutinesub 100% 26 / 26 Podpod 0.0% 0 / 3 totaltotal 92.2% 143 / 155 CC 15 SCAR 17.3
CC
15
Cov
96%
_eval_keyword_format
14.1
_traverse_keyword_format
2.1
BEGIN
1.0
CRAP 5.6
« Modern/Document.pm ↑ Summary Modern/Vocabulary/Content.pm »
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
BranchTrueFalseTotal
unless assert_keyword_type($state, $schema, "string") 0 1481 1481
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
BranchTrueFalseTotal
unless $$state{"validate_formats"} 1042 966 2008
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"})
l!l&&r!l&&!r
7187124
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"})
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless $spec 157 809 966
62  
63 809 my $type = get_type($data);
64 809 ▶ $type = 'number' if $type eq 'integer';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "integer" 90 719 809
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
BranchTrueFalseTotal
ref $$spec{'type'} eq 'ARRAY' ? : 0 3 3
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)
!ll&&!rl&&r
35112
$$state{"stringy_numbers"} and $type eq "string" and ref $$spec{"type"} eq "ARRAY" ? CORE::any({$_ eq "number";} @{$$spec{"type"}}) : $$spec{"type"} eq "number"
!ll&&!rl&&r
35103
$$state{"stringy_numbers"} and $type eq "string"
!ll&&!rl&&r
35103
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)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
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
BranchTrueFalseTotal
unless 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) 352 457 809
ref $$spec{'type'} eq 'ARRAY' ? : 40 769 809
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)
l!l&&r!l&&!r
4552352
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)
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless $valid 223 234 457
ref $$spec{'type'} eq 'ARRAY' ? : 12 211 223
84 234 return 1;
85 }
86  
87 38 1;
88  
89 __END__
« Modern/Document.pm ↑ Summary Modern/Vocabulary/Content.pm »