AsType/Draft4/Types.pm

filter: Statementstmt 98.7% 235 / 238 Branchbran 95.5% 65 / 68 Conditioncond 60.0% 18 / 30 MC/DCmcdc 45.0% 9 / 20 Subroutinesub 97.6% 83 / 85 Podpod 0.0% 0 / 1 totaltotal 92.7% 410 / 442 SCAR 38.4
CC
46
Cov
95%
same_structs
5.0
__ANON__
4.0
__ANON__
4.0
CRAP 46.3
↑ Summary AsType.pm »
1 package JSON::Schema::AsType::Draft4::Types;
2 17 our $AUTHORITY = 'cpan:YANICK';
3 # ABSTRACT: JSON-schema v4 keywords as types
4 17 $JSON::Schema::AsType::Draft4::Types::VERSION = '0.4.2';
5  
6 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 17 ▶use Type::Utils -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 17 use Types::Standard qw/
11 Str StrictNum HashRef ArrayRef
12 Int
13 Dict slurpy Optional Any
14 Tuple
15 ConsumerOf
16 InstanceOf
17 17 ▶/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 use Type::Library
20 17 -base,
21 -declare => qw(
22 Minimum
23 ExclusiveMinimum
24 Maximum
25 ExclusiveMaximum
26 MultipleOf
27  
28 Null
29 Boolean
30 Array
31 Object
32 String
33 Integer
34 Pattern
35 Number
36  
37 Required
38  
39 Not
40  
41 OneOf
42 AllOf
43 AnyOf
44  
45 MaxLength
46 MinLength
47  
48 Items
49 AdditionalItems
50 MaxItems
51 MinItems
52  
53 Properties
54 PatternProperties
55 AdditionalProperties
56 MaxProperties
57 MinProperties
58  
59  
60 Dependencies
61 Dependency
62  
63 Enum
64  
65 UniqueItems
66  
67 Schema
68  
69 17 ▶ );
Subroutine BEGIN: called CC=1 SCAR=0.0
70  
71 17 ▶use List::MoreUtils qw/ all any zip none /;
Subroutine BEGIN: called CC=1 SCAR=0.0
72 17 ▶use List::Util qw/ pairs pairmap reduce uniq /;
Subroutine BEGIN: called CC=1 SCAR=0.0
73  
74 17 ▶use JSON qw/ to_json from_json /;
Subroutine BEGIN: called CC=1 SCAR=0.0
75  
76 17 ▶use JSON::Schema::AsType;
Subroutine BEGIN: called CC=1 SCAR=0.0
77  
78 declare AdditionalProperties,
79 constraint_generator => sub {
80 79 ▶ my( $known_properties, $type_or_boolean ) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
81  
82 sub {
83 516 ▶ return 1 unless Object->check($_);
Subroutine __ANON__: called CC=4 SCAR=13.9
Branch: 1 branch
BranchTrueFalseTotal
unless &Object()->check($_) 18 498 516
84 my @add_keys = grep {
85 498 my $key = $_;
86 none {
87 297 ▶ ref $_ ? $key =~ $_ : $key eq $_
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 39 258 297
88 716 } @$known_properties
89 } keys %$_;
90  
91 498 ▶ if ( eval { $type_or_boolean->can('check') } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { $type_or_boolean->can('check') } }) { } 441 57 498
92 441 my $obj = $_;
93 441 ▶ return all { $type_or_boolean->check($obj->{$_}) } @add_keys;
Subroutine __ANON__: called CC=1 SCAR=0.0
94 }
95 else {
96 57 ▶ return not( @add_keys and not $type_or_boolean );
Condition66%2/3
@add_keys && !$type_or_boolean
!ll&&!rl&&r
41016
MC/DC50%1/2
@add_keys && !$type_or_boolean
@add_keys !$type_or_boolean
Truth table66%2/3
A && not(B)
A= @add_keysB= !$type_or_boolean
ABresult
0X0
100
111
97 }
98 }
99 79 };
100  
101 declare UniqueItems,
102 where {
103 164 ▶ return 1 unless Array->check($_);
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless &Array()->check($_) 2 162 164
104 162 @$_ == uniq map { to_json $_ , { allow_nonref => 1 } } @$_
105 17 };
106  
107 17 my $json = JSON->new->allow_nonref->canonical;
108 17 ▶use List::AllUtils qw/ zip none uniq /;
Subroutine BEGIN: called CC=1 SCAR=0.0
109  
110 sub same_structs {
111 1342 ▶ my @s = @_;
Subroutine same_structs: called CC=5 SCAR=16.1
Pod undocumented
112  
113 1342 my @refs = grep { $_ } map { ref } @s;
114  
115 1342 ▶ return if @refs == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @refs == 1 47 1295 1342
116  
117 17 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
118  
119 1295 ▶ return $s[0] eq $s[1] unless @refs;
Branch: 1 branch
BranchTrueFalseTotal
unless @refs 1271 24 1295
120  
121 24 @refs = uniq @refs;
122 24 ▶ return unless @refs == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @refs == 1 10 14 24
123  
124 14 ▶ if ( ref $s[0] eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $s[0] eq "ARRAY") 3 11 14
125 3 ▶ return all { same_structs($a,$b) } zip @{$s[0]}, @{$s[1]};
Subroutine __ANON__: not called CC=1 SCAR=0.2
126 }
127  
128 11 ▶ all { same_structs($s[0]{$_},$s[1]{$_}) } uniq map { keys %$_ } @s;
Subroutine __ANON__: called CC=1 SCAR=0.0
129 }
130  
131 declare Enum,
132 constraint_generator => sub {
133 271 ▶ my @items = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
134  
135 sub {
136 314 ▶ my $j = $_;
Subroutine __ANON__: called CC=1 SCAR=0.0
137 314 ▶ any { same_structs($_,$j) } @items;
Subroutine __ANON__: called CC=1 SCAR=0.0
138 }
139 271 };
140  
141 # Dependencies[ foo => $type, bar => [ 'baz' ] ]
142 # TODO name of generated type should be better
143 declare Dependencies,
144 constraint_generator => sub {
145 16 ▶ my %deps = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
146  
147 16 ▶ return reduce { $a & $b } pairmap { Dependency[$a => $b] } %deps;
Subroutine __ANON__: called CC=1 SCAR=0.0
148 17 };
149  
150 # Depencency[ foo => $type ]
151 declare Dependency,
152 constraint_generator => sub {
153 29 ▶ my( $property, $dep) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
154  
155 sub {
156 1991 ▶ return 1 unless Object->check($_);
Subroutine __ANON__: called CC=4 SCAR=13.9
Branch: 1 branch
BranchTrueFalseTotal
unless &Object()->check($_) 1 1990 1991
157 1990 ▶ return 1 unless exists $_->{$property};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $_->{$property} 1975 15 1990
158  
159 15 my $obj = $_;
160  
161 15 ▶ return all { exists $obj->{$_} } @$dep if ref $dep eq 'ARRAY';
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if ref $dep eq "ARRAY" 9 6 15
162  
163 6 return $dep->check($_);
164 }
165 29 };
166  
167 declare PatternProperties,
168 constraint_generator => sub {
169 29 ▶ my %props = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
170  
171 sub {
172 302 ▶ return 1 unless Object->check($_);
Subroutine __ANON__: called CC=4 SCAR=13.9
Branch: 1 branch
BranchTrueFalseTotal
unless &Object()->check($_) 12 290 302
173  
174 290 my $obj = $_;
175 290 for my $key ( keys %props ) {
176 123 ▶ return unless all { $props{$key}->check($obj->{$_}) } grep { /$key/ } keys %$_;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
unless &all(sub { $props{$key}->check($obj->{$_}); } , grep({/$key/;} keys %$_)) 43 80 123
177 }
178  
179 247 return 1;
180  
181 }
182 29 };
183 declare Properties,
184 constraint_generator => sub {
185 509 ▶ my @types = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
186  
187 509 ▶ @types = pairmap { $a => Optional[$b] } @types;
Subroutine __ANON__: called CC=1 SCAR=0.0
188  
189 509 my $type = Dict[@types,slurpy Any];
190  
191 sub {
192 1797 ▶ return 1 unless Object->check($_);
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless &Object()->check($_) 16 1781 1797
193 1781 return $type->check($_);
194 }
195 509 };
196  
197 declare Items,
198 constraint_generator => sub {
199 156 ▶ my $types = shift;
Subroutine __ANON__: called CC=4 SCAR=13.9
200  
201 156 ▶ if ( Boolean->check($types) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Boolean()->check($types)) 1 155 156
202 1 ▶ return $types ? Any : sub { !@$_ };
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
$types ? : 0 1 1
203 }
204  
205 my $type = ref $types eq 'ARRAY'
206 155 ▶ ? Tuple[ ( map { Optional[$_] } @$types ), slurpy Any ]
Branch: 1 branch
BranchTrueFalseTotal
ref $types eq 'ARRAY' ? : 15 140 155
207 : Tuple[ slurpy ArrayRef[ $types ] ];
208  
209 155 return ~ArrayRef | $type;
210  
211 17 };
212  
213 declare AdditionalItems,
214 constraint_generator=> sub {
215 7 ▶ if( @_ > 1 ) {
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) { } 4 3 7
216 4 my $to_skip = shift;
217 4 my $schema = shift;
218 return sub {
219 18 ▶ all { $schema->check($_) } splice @$_, $to_skip;
Subroutine __ANON__: called CC=1 SCAR=0.0
220 }
221 4 }
222 else {
223 3 my $size = shift;
224 3 ▶ return sub { @$_ <= $size };
Subroutine __ANON__: called CC=1 SCAR=0.0
225 }
226 17 };
227  
228 declare MaxLength,
229 constraint_generator => sub {
230 12 ▶ my $length = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
231 sub {
232 58 ▶ !String->check($_) or $length >= length;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
not &String()->check($_) or $length >= length $_ 42 16 58
233 }
234 12 };
235  
236 declare MinLength,
237 constraint_generator => sub {
238 10 ▶ my $length = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
239 sub {
240 48 ▶ !String->check($_) or $length <= length;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
not &String()->check($_) or $length <= length $_ 39 9 48
241 }
242 10 };
243  
244 declare AllOf,
245 constraint_generator => sub {
246 33 ▶ my @types = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
247 sub {
248 56 ▶ my $v = $_;
Subroutine __ANON__: called CC=1 SCAR=0.0
249 56 ▶ all { $_->check($v) } @types;
Subroutine __ANON__: called CC=1 SCAR=0.0
250 }
251 33 };
252  
253 declare AnyOf,
254 constraint_generator => sub {
255 90 ▶ my @types = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
256 sub {
257 316 ▶ my $v = $_;
Subroutine __ANON__: called CC=1 SCAR=0.0
258 316 ▶ any { $_->check($v) } @types;
Subroutine __ANON__: called CC=1 SCAR=0.0
259 }
260 90 };
261  
262 declare OneOf,
263 constraint_generator => sub {
264 11 ▶ my @types = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
265 sub {
266 34 ▶ my $v = $_;
Subroutine __ANON__: called CC=1 SCAR=0.0
267 34 1 == grep { $_->check($v) } @types;
268 }
269 11 };
270  
271 declare MaxProperties,
272 constraint_generator => sub {
273 4 ▶ my $nbr = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
274 14 ▶ sub { !Object->check($_) or $nbr >= keys %$_; },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
not &Object()->check($_) or $nbr >= keys %$_ 11 3 14
275 4 };
276  
277 declare MinProperties,
278 constraint_generator => sub {
279 3 ▶ my $nbr = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
280 sub {
281 12 ▶ !Object->check($_)
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
not &Object()->check($_) or $nbr <= scalar keys %$_ 9 3 12
282 or $nbr <= scalar keys %$_
283 },
284 3 };
285  
286 declare Not,
287 constraint_generator => sub {
288 16 ▶ my $type = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
289 42 ▶ sub { not $type->check($_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
290 16 };
291  
292  
293 # ~Str or ~String?
294 declare Pattern,
295 constraint_generator => sub {
296 39 ▶ my $regex = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
297 16 ▶ sub { !String->check($_) or /$regex/ },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
not &String()->check($_) or /$regex/ 13 3 16
298 39 };
299  
300  
301 6290 ▶declare Object => as HashRef ,where sub { ref eq 'HASH' };
Subroutine __ANON__: called CC=1 SCAR=0.0
302  
303 declare Required,
304 constraint_generator => sub {
305 29 ▶ my @keys = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
306 sub {
307 405 ▶ return 1 unless Object->check($_);
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless &Object()->check($_) 6 399 405
308 399 my $obj = $_;
309 399 ▶ all { exists $obj->{$_} } @keys;
Subroutine __ANON__: called CC=1 SCAR=0.0
310 }
311 29 };
312  
313 17 declare Array => as ArrayRef;
314  
315 511 ▶declare Boolean => where sub { ref =~ /JSON/ };
Subroutine __ANON__: called CC=1 SCAR=0.0
316  
317 declare LaxNumber =>
318 as StrictNum,
319 where sub {
320 4 ▶ return !(!defined || ref);
Subroutine __ANON__: called CC=2 SCAR=9.2
Condition33%1/3
!defined($_) || ref $_
l!l&&r!l&&!r
004
MC/DC0%0/2
!defined($_) || ref $_
!defined($_) ref $_
Truth table33%1/3
not(A) || B
A= !defined($_)B= ref $_
ABresult
1X1
011
000
321 17 };
322  
323 declare Number =>
324 where sub {
325 760 ▶ return 0 if !defined || ref;
Subroutine __ANON__: called CC=4 SCAR=13.9
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_ or ref $_ 22 738 760
Condition100%3/3
not defined $_ or ref $_
l!l&&r!l&&!r
616738
MC/DC100%2/2
not defined $_ or ref $_
not defined $_ ref $_
Truth table100%3/3
not(A) or B
A= not defined $_B= ref $_
ABresult
1X1
011
000
326  
327 738 my $b_obj = B::svref_2object(\$_);
328 738 my $flags = $b_obj->FLAGS;
329 738 ▶ return( $flags & ( B::SVp_IOK | B::SVp_NOK ) and not ($flags & B::SVp_POK) );
Condition66%2/3
$flags & 12288 && !($flags & 16384)
!ll&&!rl&&r
320706
MC/DC50%1/2
$flags & 12288 && !($flags & 16384)
$flags & 12288 !($flags & 16384)
Truth table66%2/3
A && not(B)
A= $flags & 12288B= !($flags & 16384)
ABresult
0X0
100
111
330 17 };
331  
332 declare LaxInteger =>
333 as Int,
334 0 ▶ where sub { return !(!defined || ref ) };
Subroutine __ANON__: not called CC=2 SCAR=14.0
Condition0%0/3
!defined($_) || ref $_
l!l&&r!l&&!r
000
MC/DC0%0/2
!defined($_) || ref $_
!defined($_) ref $_
Truth table0%0/3
not(A) || B
A= !defined($_)B= ref $_
ABresult
1X1
011
000
335  
336 declare Integer =>
337 where sub {
338 424 ▶ return 0 if !defined || ref;
Subroutine __ANON__: called CC=4 SCAR=13.9
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_ or ref $_ 53 371 424
Condition100%3/3
not defined $_ or ref $_
l!l&&r!l&&!r
845371
MC/DC100%2/2
not defined $_ or ref $_
not defined $_ ref $_
Truth table100%3/3
not(A) or B
A= not defined $_B= ref $_
ABresult
1X1
011
000
339  
340 371 my $b_obj = B::svref_2object(\$_);
341 371 my $flags = $b_obj->FLAGS;
342 371 ▶ return( $flags & B::SVp_IOK and not ($flags & B::SVp_POK) );
Condition66%2/3
$flags & 4096 && !($flags & 16384)
!ll&&!rl&&r
1670204
MC/DC50%1/2
$flags & 4096 && !($flags & 16384)
$flags & 4096 !($flags & 16384)
Truth table66%2/3
A && not(B)
A= $flags & 4096B= !($flags & 16384)
ABresult
0X0
100
111
343 17 };
344  
345 declare LaxString => as Str,
346 6 ▶ where sub { return defined && not ref; };
Subroutine __ANON__: called CC=2 SCAR=8.1
Condition33%1/3
defined $_ && !ref($_)
!ll&&!rl&&r
006
MC/DC0%0/2
defined $_ && !ref($_)
defined $_ !ref($_)
Truth table33%1/3
A && not(B)
A= defined $_B= !ref($_)
ABresult
0X0
100
111
347  
348 declare String => as Str,
349 where sub {
350 673 ▶ return 0 if !defined || ref;
Subroutine __ANON__: called CC=3 SCAR=12.0
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_ or ref $_ 0 673 673
Condition33%1/3
not defined $_ or ref $_
l!l&&r!l&&!r
00673
MC/DC0%0/2
not defined $_ or ref $_
not defined $_ ref $_
Truth table33%1/3
not(A) or B
A= not defined $_B= ref $_
ABresult
1X1
011
000
351  
352 673 my $b_obj = B::svref_2object(\$_);
353 673 my $flags = $b_obj->FLAGS;
354 673 return ($flags & B::SVp_POK);
355 17 };
356  
357 67 ▶declare Null => where sub { not defined };
Subroutine __ANON__: called CC=1 SCAR=0.0
358  
359 declare 'MaxItems',
360 constraint_generator => sub {
361 8 ▶ my $max = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
362  
363 return sub {
364 27 ▶ ref ne 'ARRAY' or @$_ <= $max;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ne "ARRAY" or @$_ <= $max 23 4 27
365 8 };
366 17 };
367  
368 declare 'MinItems',
369 constraint_generator => sub {
370 17 ▶ my $min = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
371  
372 return sub {
373 170 ▶ ref ne 'ARRAY' or @$_ >= $min;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ne "ARRAY" or @$_ >= $min 161 9 170
374 17 };
375 17 };
376  
377 declare 'MultipleOf',
378 constraint_generator => sub {
379 10 ▶ my $num =shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
380  
381 return sub {
382 30 ▶ !Number->check($_)
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%3/3
&Number()->check($_) && ($_ / $num) =~ /\./
!ll&&!rl&&r
41313
MC/DC100%2/2
&Number()->check($_) && ($_ / $num) =~ /\./
&Number()->check($_) ($_ / $num) =~ /\./
Truth table100%3/3
A && B
A= &Number()->check($_)B= ($_ / $num) =~ /\./
ABresult
0X0
100
111
383 or ($_ / $num) !~ /\./;
384 }
385 10 };
386  
387 declare Minimum,
388 constraint_generator => sub {
389 28 ▶ my $minimum = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
390 return sub {
391 77 ▶ ! Number->check($_)
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
not &Number()->check($_) or $_ >= $minimum 69 8 77
392 or $_ >= $minimum;
393 28 };
394 17 };
395  
396 declare ExclusiveMinimum,
397 constraint_generator => sub {
398 16 ▶ my $minimum = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
399 return sub {
400 14 ▶ ! StrictNum->check($_)
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
not &StrictNum()->check($_) or $_ > $minimum 12 2 14
401 or $_ > $minimum;
402 }
403 16 };
404  
405 declare Maximum,
406 constraint_generator => sub {
407 11 ▶ my $max = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
408 return sub {
409 37 ▶ ! StrictNum->check($_)
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
not &StrictNum()->check($_) or $_ <= $max 32 5 37
410 or $_ <= $max;
411 11 };
412 17 };
413  
414 declare ExclusiveMaximum,
415 constraint_generator => sub {
416 4 ▶ my $max = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
417 return sub {
418 14 ▶ ! StrictNum->check($_)
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
not &StrictNum()->check($_) or $_ < $max 12 2 14
419 or $_ < $max;
420 }
421 4 };
422  
423 17 declare Schema, as InstanceOf['Type::Tiny'];
424  
425 coerce Schema,
426 from HashRef,
427 via {
428 1 ▶ my $schema = JSON::Schema::AsType->new( draft_version => 4, schema => $_ );
Subroutine __ANON__: called CC=2 SCAR=7.4
429  
430 1 ▶ if ( $schema->validate_schema ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema->validate_schema) 0 1 1
431 0 die "not a valid draft4 json schema\n";
432 }
433  
434 $schema->type
435 1 };
436  
437 17 1;
438  
439 __END__
440  
441 =pod
442  
443 =encoding UTF-8
444  
445 =head1 NAME
446  
447 JSON::Schema::AsType::Draft4::Types - JSON-schema v4 keywords as types
448  
449 =head1 VERSION
450  
451 version 0.4.2
452  
453 =head1 SYNOPSIS
454  
455 use JSON::Schema::AsType::Draft4::Types '-all';
456  
457 my $type = Object &
458 Properties[
459 foo => Minimum[3]
460 ];
461  
462 $type->check({ foo => 5 }); # => 1
463 $type->check({ foo => 1 }); # => 0
464  
465 =head1 EXPORTED TYPES
466  
467 Null Boolean Array Object String Integer Pattern Number Enum
468  
469 OneOf AllOf AnyOf
470  
471 Required Not
472  
473 Minimum ExclusiveMinimum Maximum ExclusiveMaximum MultipleOf
474  
475 MaxLength MinLength
476  
477 Items AdditionalItems MaxItems MinItems UniqueItems
478  
479 Properties PatternProperties AdditionalProperties MaxProperties MinProperties
480  
481 Dependencies Dependency
482  
483 =head2 Schema
484  
485 Only verifies that the variable is a L<Type::Tiny>.
486  
487 Can coerce the value from a hashref defining the schema.
488  
489 my $schema = Schema->coerce( \%schema );
490  
491 # equivalent to
492  
493 $schema = JSON::Schema::AsType::Draft4->new(
494 draft_version => 4,
495 schema => \%schema;
496 )->type;
497  
498 =head1 AUTHOR
499  
500 Yanick Champoux <yanick@babyl.dyndns.org>
501  
502 =head1 COPYRIGHT AND LICENSE
503  
504 This software is copyright (c) 2015 by Yanick Champoux.
505  
506 This is free software; you can redistribute it and/or modify it under
507 the same terms as the Perl 5 programming language system itself.
508  
509 =cut
↑ Summary AsType.pm »