Modern/Vocabulary/Content.pm

filter: Statementstmt 98.9% 90 / 91 Branchbran 93.3% 28 / 30 Conditioncond 100% 5 / 5 MC/DCmcdc 100% 3 / 3 Subroutinesub 96.1% 25 / 26 Podpod 0.0% 0 / 3 totaltotal 95.5% 151 / 158 CC 18 SCAR 12.3
CC
18
Cov
98%
_eval_keyword_contentSchema
7.1
_eval_keyword_contentMediaType
7.0
_eval_keyword_contentEncoding
4.0
CRAP 3.4
« Modern/Vocabulary/FormatAnnotation.pm ↑ Summary Modern/Error.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::Content;
4 # vim: set ts=8 sts=2 sw=2 tw=100 et :
5 # ABSTRACT: Implementation of the JSON Schema Content 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 Clone 'clone';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 38 ▶use Feature::Compat::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 38 ▶use JSON::Schema::Modern::Utilities qw(is_type A assert_keyword_type E abort jsonp_set decode_media_type);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 38 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 38 with 'JSON::Schema::Modern::Vocabulary';
27  
28 22 ▶sub vocabulary ($class) {
Subroutine vocabulary: called CC=1 SCAR=0.0
Pod undocumented
29 22 'https://json-schema.org/draft/2019-09/vocab/content' => 'draft2019-09',
30 'https://json-schema.org/draft/2020-12/vocab/content' => 'draft2020-12';
31 }
32  
33 0 ▶sub evaluation_order ($class) { 4 }
Subroutine evaluation_order: not called CC=1 SCAR=6.9
Pod undocumented
34  
35 128 ▶sub keywords ($class, $spec_version) {
Subroutine keywords: called CC=3 SCAR=11.0
Pod undocumented
36 return (
37 128 ▶ $spec_version !~ /^draft[46]\z/ ? qw(contentEncoding contentMediaType) : (),
Branch: 2 branches
BranchTrueFalseTotal
!($spec_version =~ /^draft[46]\z/u) ? : 126 2 128
!($spec_version =~ /^draft[467]\z/u) ? : 95 33 128
38 $spec_version !~ /^draft[467]\z/ ? 'contentSchema' : (),
39 );
40 }
41  
42 174 ▶sub _traverse_keyword_contentEncoding ($class, $schema, $state) {
Subroutine _traverse_keyword_contentEncoding: called CC=1 SCAR=0.0
43 174 return assert_keyword_type($state, $schema, 'string');
44 }
45  
46 86 ▶sub _eval_keyword_contentEncoding ($class, $data, $schema, $state) {
Subroutine _eval_keyword_contentEncoding: called CC=4 SCAR=13.9
47 86 ▶ return 1 if not is_type('string', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("string", $data) 16 70 86
48  
49 70 ▶ if ($state->{validate_content_schemas}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$state{"validate_content_schemas"}) 20 50 70
50 20 my $decoder = $state->{evaluator}->get_encoding($schema->{contentEncoding});
51 abort($state, 'cannot find decoder for contentEncoding "%s"', $schema->{contentEncoding})
52 20 ▶ if not $decoder;
Branch: 1 branch
BranchTrueFalseTotal
unless $decoder 1 19 20
53  
54 # decode the data now, so we can report errors for the right keyword
55 19 try {
56 19 $state->{_content_ref} = $decoder->(\$data);
57 13 $state->{data} = jsonp_set($state->{data}, $state->{data_path}, $state->{_content_ref}->$*);
58 }
59 catch ($e) {
60 6 chomp $e;
61 6 return E($state, 'could not decode %s string: %s', $schema->{contentEncoding}, $e);
62 }
63 }
64  
65 63 return A($state, $schema->{$state->{keyword}});
66 }
67  
68 38 *_traverse_keyword_contentMediaType = \&_traverse_keyword_contentEncoding;
69  
70 86 ▶sub _eval_keyword_contentMediaType ($class, $data, $schema, $state) {
Subroutine _eval_keyword_contentMediaType: called CC=7 SCAR=19.5
71 86 ▶ return 1 if not is_type('string', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("string", $data) 16 70 86
72  
73 70 ▶ if ($state->{validate_content_schemas}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$state{"validate_content_schemas"}) 20 50 70
74 # contentEncoding failed to decode the content
75 20 ▶ return 1 if exists $schema->{contentEncoding} and not exists $state->{_content_ref};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$schema{"contentEncoding"} and not exists $$state{"_content_ref"} 3 17 20
Condition100%3/3
exists $$schema{"contentEncoding"} and not exists $$state{"_content_ref"}
!ll&&!rl&&r
6113
MC/DC100%2/2
exists $$schema{"contentEncoding"} and not exists $$state{"_content_ref"}
exists $$schema{"contentEncoding"} not exists $$state{"_content_ref"}
Truth table100%3/3
A and not(B)
A= exists $$schema{"contentEncoding"}B= not exists $$state{"_content_ref"}
ABresult
0X0
100
111
76  
77 # decode the data now, so we can report errors for the right keyword
78 17 my $contentref;
79 17 try {
80 17 ▶ $contentref = decode_media_type($schema->{contentMediaType}, $state->{_content_ref} // \$data);
Condition100%2/2
$$state{"_content_ref"} // \$data
l!l
116
MC/DC100%1/1
$$state{"_content_ref"} // \$data
$$state{"_content_ref"}
Truth table100%2/2
A
A= $$state{"_content_ref"}
Aresult
11
00
81 }
82 catch ($e) {
83 6 chomp $e;
84 6 delete $state->{_content_ref};
85 6 return E($state, 'could not decode %s string: %s', $schema->{contentMediaType}, $e);
86 }
87  
88 abort($state, 'cannot find decoder for contentMediaType "%s"', $schema->{contentMediaType})
89 11 ▶ if not $contentref;
Branch: 1 branch
BranchTrueFalseTotal
unless $contentref 1 10 11
90  
91 10 $state->{_content_ref} = $contentref;
92 10 $state->{data} = jsonp_set($state->{data}, $state->{data_path}, $state->{_content_ref}->$*);
93 }
94  
95 60 return A($state, $schema->{$state->{keyword}});
96 }
97  
98 43 ▶sub _traverse_keyword_contentSchema ($class, $schema, $state) {
Subroutine _traverse_keyword_contentSchema: called CC=1 SCAR=0.0
99 43 $class->traverse_subschema($schema, $state);
100 }
101  
102 41 ▶sub _eval_keyword_contentSchema ($class, $data, $schema, $state) {
Subroutine _eval_keyword_contentSchema: called CC=7 SCAR=19.6
103 41 ▶ return 1 if not exists $schema->{contentMediaType};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$schema{"contentMediaType"} 0 41 41
104 41 ▶ return 1 if not is_type('string', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("string", $data) 4 37 41
105  
106 37 ▶ if ($state->{validate_content_schemas}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$state{"validate_content_schemas"}) 7 30 37
107 7 ▶ return 1 if not exists $state->{_content_ref}; # contentMediaType failed to decode the content
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$state{"_content_ref"} 2 5 7
108 return E($state, 'subschema is not valid')
109 if not $class->eval($state->{_content_ref}->$*, $schema->{contentSchema},
110 5 ▶ { %$state, keyword_path => $state->{keyword_path}.'/contentSchema' });
Branch: 1 branch
BranchTrueFalseTotal
unless $class->eval(${$$state{"_content_ref"}}, $$schema{"contentSchema"}, {%$state, "keyword_path", $$state{"keyword_path"} . '/contentSchema'}) 2 3 5
111 }
112  
113 33 ▶ return A($state, ref $schema->{contentSchema} ? clone($schema->{contentSchema}) : $schema->{contentSchema});
Branch: 1 branch
BranchTrueFalseTotal
ref $$schema{'contentSchema'} ? : 33 0 33
114 }
115  
116 38 1;
117  
118 __END__
« Modern/Vocabulary/FormatAnnotation.pm ↑ Summary Modern/Error.pm »