AsType/Draft6.pm

filter: Statementstmt 100% 78 / 78 Branchbran 100% 14 / 14 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 24 / 24 Podpod n/a totaltotal 100% 121 / 121 CC 10 SCAR 7.1
CC
10
Cov
100%
_keyword_items
5.0
__ANON__
3.0
__ANON__
3.0
CRAP 2.0
« AsType/Draft4/Types.pm ↑ Summary AsType/Draft4.pm »
1 package JSON::Schema::AsType::Draft6;
2 1 our $AUTHORITY = 'cpan:YANICK';
3 # ABSTRACT: Role processing draft6 JSON Schema
4 1 $JSON::Schema::AsType::Draft6::VERSION = '0.4.4';
5  
6 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 ▶use Type::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Scalar::Util qw/ looks_like_number /;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use List::Util qw/ reduce pairmap pairs /;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use List::MoreUtils qw/ any all none uniq zip /;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use Types::Standard qw/InstanceOf HashRef StrictNum Any Str ArrayRef Int slurpy Dict Optional slurpy /;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 3 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 3 ▶use JSON::Schema::AsType;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 3 ▶use JSON::Schema::AsType::Draft6::Types '-all';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 with 'JSON::Schema::AsType::Draft4';
24  
25 override all_keywords => sub {
26 6535 ▶ my $self = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
27
28 # $ref trumps all
29 6535 ▶ return '$ref' if $self->schema->{'$ref'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->schema->{"\$ref"} 296 6239 6535
30  
31 6239 return uniq '$id', super();
32 1 };
33  
34 override _build_type => sub {
35 9389 ▶ my $self = shift;
Subroutine __ANON__: called CC=3 SCAR=11.0
36  
37 9389 ▶ return super() if ref $self->schema eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->schema eq "HASH" 9345 44 9389
38  
39 3 ▶ use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 44 ▶ return( ( $self->schema eq JSON::true) ? Any : ~Any );
Branch: 1 branch
BranchTrueFalseTotal
$self->schema eq JSON::true() ? : 21 23 44
41
42 1 };
43  
44 sub _keyword_const {
45 4 ▶ my $self = shift;
Subroutine _keyword_const: called CC=1 SCAR=0.0
46  
47 4 $self->_keyword_enum([@_]);
48 }
49  
50 sub _keyword_contains {
51 4 ▶ my( $self, $type ) = @_;
Subroutine _keyword_contains: called CC=1 SCAR=0.0
52  
53 4 return Contains[
54 $self->sub_schema($type)->type
55 ];
56
57 };
58  
59 sub _keyword_exclusiveMaximum {
60 1 ▶ my( $self, $maximum ) = @_;
Subroutine _keyword_exclusiveMaximum: called CC=1 SCAR=0.0
61  
62 1 ExclusiveMaximum[$maximum];
63 }
64  
65 sub _keyword_exclusiveMinimum {
66 4 ▶ my( $self, $maximum ) = @_;
Subroutine _keyword_exclusiveMinimum: called CC=1 SCAR=0.0
67  
68 4 ExclusiveMinimum[$maximum];
69 }
70  
71 sub _keyword_propertyNames {
72 6 ▶ my( $self, $schema ) = @_;
Subroutine _keyword_propertyNames: called CC=1 SCAR=0.0
73  
74 6 PropertyNames[ $self->sub_schema($schema)->type ];
75 }
76  
77 sub _keyword_items {
78 51 ▶ my( $self, $items ) = @_;
Subroutine _keyword_items: called CC=5 SCAR=16.1
79  
80 51 ▶ if ( Boolean->check($items) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Boolean()->check($items)) 2 49 51
81 2 ▶ return if $items;
Branch: 1 branch
BranchTrueFalseTotal
if $items 1 1 2
82 1 return Items[JSON::false];
83 }
84  
85 49 ▶ if( ref $items eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $items eq "HASH") 43 6 49
86 43 my $type = $self->sub_schema($items)->type;
87  
88 43 return Items[$type];
89 }
90  
91 # TODO forward declaration not workie
92 6 my @types;
93 6 for ( @$items ) {
94 11 push @types, $self->sub_schema($_)->type;
95 }
96  
97 6 return Items[\@types];
98 }
99  
100 sub _keyword_dependencies {
101 5 ▶ my( $self, $dependencies ) = @_;
Subroutine _keyword_dependencies: called CC=1 SCAR=0.0
102  
103 return Dependencies[
104 pairmap {
105 6 ▶ $a => ( ref $b eq 'HASH' or ref $b eq 'JSON::PP::Boolean' ) ? $self->sub_schema($b)
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
ref $b eq 'HASH' || ref $b eq 'JSON::PP::Boolean' ? : 3 3 6
Condition100%3/3
ref $b eq "HASH" or ref $b eq "JSON::PP::Boolean"
l!l&&r!l&&!r
123
MC/DC100%2/2
ref $b eq "HASH" or ref $b eq "JSON::PP::Boolean"
ref $b eq "HASH" ref $b eq "JSON::PP::Boolean"
Truth table100%3/3
A or B
A= ref $b eq "HASH"B= ref $b eq "JSON::PP::Boolean"
ABresult
1X1
011
000
106 5 : $b } %$dependencies
107 ];
108  
109 }
110  
111 __PACKAGE__->meta->add_method( '_keyword_$id' => sub {
112 1 ▶ my $self = shift;
Subroutine _keyword_$id: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
113 1 $self->_keyword_id(@_);
114 1 } );
115  
116  
117 1 JSON::Schema::AsType->new(
118 specification => 'draft6',
119 uri => 'https://json-schema.org/draft-06/schema',
120 schema => from_json <<'END_JSON' )->type;
121 {
122 "$schema": "https://json-schema.org/draft-06/schema#",
123 "$id": "https://json-schema.org/draft-06/schema#",
124 "title": "Core schema meta-schema",
125 "definitions": {
126 "schemaArray": {
127 "type": "array",
128 "minItems": 1,
129 "items": { "$ref": "#" }
130 },
131 "nonNegativeInteger": {
132 "type": "integer",
133 "minimum": 0
134 },
135 "nonNegativeIntegerDefault0": {
136 "allOf": [
137 { "$ref": "#/definitions/nonNegativeInteger" },
138 { "default": 0 }
139 ]
140 },
141 "simpleTypes": {
142 "enum": [
143 "array",
144 "boolean",
145 "integer",
146 "null",
147 "number",
148 "object",
149 "string"
150 ]
151 },
152 "stringArray": {
153 "type": "array",
154 "items": { "type": "string" },
155 "uniqueItems": true,
156 "default": []
157 }
158 },
159 "type": ["object", "boolean"],
160 "properties": {
161 "$id": {
162 "type": "string",
163 "format": "uri-reference"
164 },
165 "$schema": {
166 "type": "string",
167 "format": "uri"
168 },
169 "$ref": {
170 "type": "string",
171 "format": "uri-reference"
172 },
173 "title": {
174 "type": "string"
175 },
176 "description": {
177 "type": "string"
178 },
179 "default": {},
180 "examples": {
181 "type": "array",
182 "items": {}
183 },
184 "multipleOf": {
185 "type": "number",
186 "exclusiveMinimum": 0
187 },
188 "maximum": {
189 "type": "number"
190 },
191 "exclusiveMaximum": {
192 "type": "number"
193 },
194 "minimum": {
195 "type": "number"
196 },
197 "exclusiveMinimum": {
198 "type": "number"
199 },
200 "maxLength": { "$ref": "#/definitions/nonNegativeInteger" },
201 "minLength": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
202 "pattern": {
203 "type": "string",
204 "format": "regex"
205 },
206 "additionalItems": { "$ref": "#" },
207 "items": {
208 "anyOf": [
209 { "$ref": "#" },
210 { "$ref": "#/definitions/schemaArray" }
211 ],
212 "default": {}
213 },
214 "maxItems": { "$ref": "#/definitions/nonNegativeInteger" },
215 "minItems": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
216 "uniqueItems": {
217 "type": "boolean",
218 "default": false
219 },
220 "contains": { "$ref": "#" },
221 "maxProperties": { "$ref": "#/definitions/nonNegativeInteger" },
222 "minProperties": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
223 "required": { "$ref": "#/definitions/stringArray" },
224 "additionalProperties": { "$ref": "#" },
225 "definitions": {
226 "type": "object",
227 "additionalProperties": { "$ref": "#" },
228 "default": {}
229 },
230 "properties": {
231 "type": "object",
232 "additionalProperties": { "$ref": "#" },
233 "default": {}
234 },
235 "patternProperties": {
236 "type": "object",
237 "additionalProperties": { "$ref": "#" },
238 "propertyNames": { "format": "regex" },
239 "default": {}
240 },
241 "dependencies": {
242 "type": "object",
243 "additionalProperties": {
244 "anyOf": [
245 { "$ref": "#" },
246 { "$ref": "#/definitions/stringArray" }
247 ]
248 }
249 },
250 "propertyNames": { "$ref": "#" },
251 "const": {},
252 "enum": {
253 "type": "array",
254 "minItems": 1,
255 "uniqueItems": true
256 },
257 "type": {
258 "anyOf": [
259 { "$ref": "#/definitions/simpleTypes" },
260 {
261 "type": "array",
262 "items": { "$ref": "#/definitions/simpleTypes" },
263 "minItems": 1,
264 "uniqueItems": true
265 }
266 ]
267 },
268 "format": { "type": "string" },
269 "allOf": { "$ref": "#/definitions/schemaArray" },
270 "anyOf": { "$ref": "#/definitions/schemaArray" },
271 "oneOf": { "$ref": "#/definitions/schemaArray" },
272 "not": { "$ref": "#" }
273 },
274 "default": {}
275 }
276 END_JSON
277  
278 1 1;
279  
280 __END__
281  
282 =pod
283  
284 =encoding UTF-8
285  
286 =head1 NAME
287  
288 JSON::Schema::AsType::Draft6 - Role processing draft6 JSON Schema
289  
290 =head1 VERSION
291  
292 version 0.4.4
293  
294 =head1 DESCRIPTION
295  
296 This role is not intended to be used directly. It is used internally
297 by L<JSON::Schema::AsType> objects.
298  
299 Importing this module auto-populate the Draft4 schema in the
300 L<JSON::Schema::AsType> schema cache.
301  
302 =head1 AUTHOR
303  
304 Yanick Champoux <yanick@babyl.dyndns.org>
305  
306 =head1 COPYRIGHT AND LICENSE
307  
308 This software is copyright (c) 2024 by Yanick Champoux.
309  
310 This is free software; you can redistribute it and/or modify it under
311 the same terms as the Perl 5 programming language system itself.
312  
313 =cut
« AsType/Draft4/Types.pm ↑ Summary AsType/Draft4.pm »