Corvus/Dialect.pm

filter: Statementstmt 97.8% 45 / 46 Branchbran 52.6% 20 / 38 Conditioncond 54.2% 19 / 35 MC/DCmcdc 31.5% 6 / 19 Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 4 totaltotal 65.5% 101 / 154 CC 32 SCAR 40.9
CC
32
Cov
71%
subschema_kind
82.3
vocabulary_flag
6.0
BEGIN
1.0
CRAP 59.8
« Corvus/Loader.pm ↑ Summary Corvus/Pattern.pm »
1 package JSON::Schema::Corvus::Dialect;
2  
3 # JSON Schema dialects, vocabularies and the keywords that hold subschemas. A port of the Python package's dialect.py.
4  
5 4 ▶use 5.026;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # The dialects, in specification order.
11 4 ▶use constant { DRAFT4 => 0, DRAFT6 => 1, DRAFT7 => 2, DRAFT201909 => 3, DRAFT202012 => 4 };
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # The vocabularies in effect for a schema resource (2019-09 and later), as bits.
14 4 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 V_NONE => 0,
16 V_CORE => 1 << 0,
17 V_APPLICATOR => 1 << 1,
18 V_VALIDATION => 1 << 2,
19 V_META_DATA => 1 << 3,
20 V_FORMAT_ANNOTATION => 1 << 4,
21 V_FORMAT_ASSERTION => 1 << 5,
22 V_CONTENT => 1 << 6,
23 V_UNEVALUATED => 1 << 7,
24 4 };
25 4 ▶use constant V_ALL_ANNOTATING_FORMAT => V_CORE | V_APPLICATOR | V_VALIDATION | V_META_DATA | V_FORMAT_ANNOTATION
Subroutine BEGIN: called CC=1 SCAR=0.0
26 4 | V_CONTENT | V_UNEVALUATED;
27  
28 # Which keywords hold subschemas.
29 4 ▶use constant { K_NONE => 0, K_SINGLE => 1, K_SINGLE_OR_ARRAY => 2, K_ARRAY => 3, K_MAP => 4 };
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 4 our @EXPORT_OK = qw(
32 DRAFT4 DRAFT6 DRAFT7 DRAFT201909 DRAFT202012
33 V_NONE V_CORE V_APPLICATOR V_VALIDATION V_META_DATA V_FORMAT_ANNOTATION V_FORMAT_ASSERTION V_CONTENT V_UNEVALUATED
34 V_ALL_ANNOTATING_FORMAT
35 K_NONE K_SINGLE K_SINGLE_OR_ARRAY K_ARRAY K_MAP
36 known_dialect vocabulary_flag subschema_kind dialect_by_name
37 );
38 4 our %EXPORT_TAGS = (all => \@EXPORT_OK);
39  
40 4 my %KNOWN_DIALECTS = (
41 'http://json-schema.org/draft-04/schema' => DRAFT4,
42 'http://json-schema.org/draft-06/schema' => DRAFT6,
43 'http://json-schema.org/draft-07/schema' => DRAFT7,
44 'https://json-schema.org/draft/2019-09/schema' => DRAFT201909,
45 'https://json-schema.org/draft/2020-12/schema' => DRAFT202012,
46 );
47  
48 # The dialect of a well-known metaschema URI (normalised, no fragment), or undef.
49 9 ▶sub known_dialect { $KNOWN_DIALECTS{ $_[0] } }
Subroutine known_dialect: called CC=1 SCAR=0.0
Pod undocumented
50  
51 4 my %BY_NAME = ('draft4' => DRAFT4, 'draft6' => DRAFT6, 'draft7' => DRAFT7, 'draft2019-09' => DRAFT201909,
52 'draft2020-12' => DRAFT202012);
53  
54 # The dialect of an option's name (draft4 to draft2020-12), or undef.
55 6 ▶sub dialect_by_name { $BY_NAME{ $_[0] } }
Subroutine dialect_by_name: called CC=1 SCAR=0.0
Pod undocumented
56  
57 4 my %VOCABULARIES = (
58 'https://json-schema.org/draft/2020-12/vocab/core' => V_CORE,
59 'https://json-schema.org/draft/2019-09/vocab/core' => V_CORE,
60 'https://json-schema.org/draft/2020-12/vocab/applicator' => V_APPLICATOR,
61 'https://json-schema.org/draft/2019-09/vocab/applicator' => V_APPLICATOR,
62 'https://json-schema.org/draft/2020-12/vocab/validation' => V_VALIDATION,
63 'https://json-schema.org/draft/2019-09/vocab/validation' => V_VALIDATION,
64 'https://json-schema.org/draft/2020-12/vocab/meta-data' => V_META_DATA,
65 'https://json-schema.org/draft/2019-09/vocab/meta-data' => V_META_DATA,
66 'https://json-schema.org/draft/2020-12/vocab/format-annotation' => V_FORMAT_ANNOTATION,
67 'https://json-schema.org/draft/2019-09/vocab/format' => V_FORMAT_ANNOTATION,
68 'https://json-schema.org/draft/2020-12/vocab/format-assertion' => V_FORMAT_ASSERTION,
69 'https://json-schema.org/draft/2020-12/vocab/content' => V_CONTENT,
70 'https://json-schema.org/draft/2019-09/vocab/content' => V_CONTENT,
71 'https://json-schema.org/draft/2020-12/vocab/unevaluated' => V_UNEVALUATED,
72 );
73  
74 0 ▶sub vocabulary_flag { $VOCABULARIES{ $_[0] } // V_NONE }
Subroutine vocabulary_flag: not called CC=2 SCAR=17.9
Pod undocumented
Condition0%0/2
$VOCABULARIES{$_[0]} // 0
l!l
00
MC/DC0%0/1
$VOCABULARIES{$_[0]} // 0
$VOCABULARIES{$_[0]}
Truth table0%0/2
A
A= $VOCABULARIES{$_[0]}
Aresult
11
00
75  
76 # Which keywords hold subschemas, by dialect (SchemaKeywords.GetSubschemaKind).
77 262 ▶sub subschema_kind {
Subroutine subschema_kind: called CC=31 SCAR=44.1
Pod undocumented
78 262 my ($keyword, $dialect, $legacy_ref_overrides_siblings) = @_;
79 262 ▶ return K_MAP if $keyword eq 'definitions' || $keyword eq '$defs';
Branch: 1 branch
BranchTrueFalseTotal
if $keyword eq "definitions" or $keyword eq "\$defs" 5 257 262
Condition66%2/3
$keyword eq "definitions" or $keyword eq "\$defs"
l!l&&r!l&&!r
05257
MC/DC50%1/2
$keyword eq "definitions" or $keyword eq "\$defs"
$keyword eq "definitions" $keyword eq "\$defs"
Truth table66%2/3
A or B
A= $keyword eq "definitions"B= $keyword eq "\$defs"
ABresult
1X1
011
000
80 257 ▶ return K_NONE if $legacy_ref_overrides_siblings;
Branch: 1 branch
BranchTrueFalseTotal
if $legacy_ref_overrides_siblings 0 257 257
81 257 ▶ return K_MAP if $keyword eq 'properties' || $keyword eq 'patternProperties' || $keyword eq 'dependencies';
Branch: 1 branch
BranchTrueFalseTotal
if $keyword eq "properties" or $keyword eq "patternProperties" or $keyword eq "dependencies" 12 245 257
Condition66%4/6
$keyword eq "properties" or $keyword eq "patternProperties" or $keyword eq "dependencies"
l!l&&r!l&&!r
120245
$keyword eq "properties" or $keyword eq "patternProperties"
l!l&&r!l&&!r
120245
MC/DC33%1/3
$keyword eq "properties" or $keyword eq "patternProperties" or $keyword eq "dependencies"
$keyword eq "properties" $keyword eq "patternProperties" $keyword eq "dependencies"
Truth table50%2/4
A or B or C
A= $keyword eq "properties"B= $keyword eq "patternProperties"C= $keyword eq "dependencies"
ABCresult
1XX1
01X1
0011
0000
82 245 ▶ return K_SINGLE if $keyword eq 'additionalProperties' || $keyword eq 'not';
Branch: 1 branch
BranchTrueFalseTotal
if $keyword eq "additionalProperties" or $keyword eq "not" 8 237 245
Condition66%2/3
$keyword eq "additionalProperties" or $keyword eq "not"
l!l&&r!l&&!r
80237
MC/DC50%1/2
$keyword eq "additionalProperties" or $keyword eq "not"
$keyword eq "additionalProperties" $keyword eq "not"
Truth table66%2/3
A or B
A= $keyword eq "additionalProperties"B= $keyword eq "not"
ABresult
1X1
011
000
83 237 ▶ return K_ARRAY if $keyword eq 'allOf' || $keyword eq 'anyOf' || $keyword eq 'oneOf';
Branch: 1 branch
BranchTrueFalseTotal
if $keyword eq "allOf" or $keyword eq "anyOf" or $keyword eq "oneOf" 3 234 237
Condition83%5/6
$keyword eq "allOf" or $keyword eq "anyOf" or $keyword eq "oneOf"
l!l&&r!l&&!r
30234
$keyword eq "allOf" or $keyword eq "anyOf"
l!l&&r!l&&!r
12234
MC/DC66%2/3
$keyword eq "allOf" or $keyword eq "anyOf" or $keyword eq "oneOf"
$keyword eq "allOf" $keyword eq "anyOf" $keyword eq "oneOf"
Truth table75%3/4
A or B or C
A= $keyword eq "allOf"B= $keyword eq "anyOf"C= $keyword eq "oneOf"
ABCresult
1XX1
01X1
0011
0000
84 234 ▶ return $dialect >= DRAFT202012 ? K_SINGLE : K_SINGLE_OR_ARRAY if $keyword eq 'items';
Branch: 2 branches
BranchTrueFalseTotal
if $keyword eq "items" 6 228 234
$dialect >= 4 ? : 6 0 6
85 228 ▶ return $dialect <= DRAFT201909 ? K_SINGLE : K_NONE if $keyword eq 'additionalItems';
Branch: 2 branches
BranchTrueFalseTotal
if $keyword eq "additionalItems" 0 228 228
$dialect <= 3 ? : 0 0 0
86 228 ▶ return $dialect >= DRAFT6 ? K_SINGLE : K_NONE if $keyword eq 'contains' || $keyword eq 'propertyNames';
Branch: 2 branches
BranchTrueFalseTotal
if $keyword eq "contains" or $keyword eq "propertyNames" 2 226 228
$dialect >= 1 ? : 2 0 2
Condition66%2/3
$keyword eq "contains" or $keyword eq "propertyNames"
l!l&&r!l&&!r
02226
MC/DC50%1/2
$keyword eq "contains" or $keyword eq "propertyNames"
$keyword eq "contains" $keyword eq "propertyNames"
Truth table66%2/3
A or B
A= $keyword eq "contains"B= $keyword eq "propertyNames"
ABresult
1X1
011
000
87 226 ▶ return $dialect >= DRAFT7 ? K_SINGLE : K_NONE if $keyword eq 'if' || $keyword eq 'then' || $keyword eq 'else';
Branch: 2 branches
BranchTrueFalseTotal
if $keyword eq "if" or $keyword eq "then" or $keyword eq "else" 0 226 226
$dialect >= 2 ? : 0 0 0
Condition33%2/6
$keyword eq "if" or $keyword eq "then" or $keyword eq "else"
l!l&&r!l&&!r
00226
$keyword eq "if" or $keyword eq "then"
l!l&&r!l&&!r
00226
MC/DC0%0/3
$keyword eq "if" or $keyword eq "then" or $keyword eq "else"
$keyword eq "if" $keyword eq "then" $keyword eq "else"
Truth table25%1/4
A or B or C
A= $keyword eq "if"B= $keyword eq "then"C= $keyword eq "else"
ABCresult
1XX1
01X1
0011
0000
88 226 ▶ return $dialect >= DRAFT201909 ? K_SINGLE : K_NONE
Branch: 2 branches
BranchTrueFalseTotal
if $keyword eq "unevaluatedProperties" or $keyword eq "unevaluatedItems" or $keyword eq "contentSchema" 0 226 226
$dialect >= 3 ? : 0 0 0
Condition33%2/6
$keyword eq "unevaluatedProperties" or $keyword eq "unevaluatedItems" or $keyword eq "contentSchema"
l!l&&r!l&&!r
00226
$keyword eq "unevaluatedProperties" or $keyword eq "unevaluatedItems"
l!l&&r!l&&!r
00226
MC/DC0%0/3
$keyword eq "unevaluatedProperties" or $keyword eq "unevaluatedItems" or $keyword eq "contentSchema"
$keyword eq "unevaluatedProperties" $keyword eq "unevaluatedItems" $keyword eq "contentSchema"
Truth table25%1/4
A or B or C
A= $keyword eq "unevaluatedProperties"B= $keyword eq "unevaluatedItems"C= $keyword eq "contentSchema"
ABCresult
1XX1
01X1
0011
0000
89 if $keyword eq 'unevaluatedProperties' || $keyword eq 'unevaluatedItems' || $keyword eq 'contentSchema';
90 226 ▶ return $dialect >= DRAFT201909 ? K_MAP : K_NONE if $keyword eq 'dependentSchemas';
Branch: 2 branches
BranchTrueFalseTotal
if $keyword eq "dependentSchemas" 0 226 226
$dialect >= 3 ? : 0 0 0
91 226 ▶ return $dialect >= DRAFT202012 ? K_ARRAY : K_NONE if $keyword eq 'prefixItems';
Branch: 2 branches
BranchTrueFalseTotal
if $keyword eq "prefixItems" 0 226 226
$dialect >= 4 ? : 0 0 0
92 226 return K_NONE;
93 }
94  
95 4 1;
« Corvus/Loader.pm ↑ Summary Corvus/Pattern.pm »