AsType/Draft4/Types.pm

filter: Statementstmt 95.0% 268 / 282 Branchbran 83.7% 77 / 92 Conditioncond 54.1% 13 / 24 MC/DCmcdc 37.5% 6 / 16 Subroutinesub 96.6% 87 / 90 Podpod n/a totaltotal 89.4% 451 / 504 CC 60 SCAR 9.4
CC
60
Cov
90%
__ANON__
12.0
__ANON__
6.0
__ANON__
5.5
CRAP 2.6
« AsType/Draft6/Keywords.pm ↑ Summary AsType/Draft6/Types.pm »
1 package JSON::Schema::AsType::Draft4::Types;
2 39 our $AUTHORITY = 'cpan:YANICK';
3 39 $JSON::Schema::AsType::Draft4::Types::VERSION = '1.0.0';
4 # ABSTRACT: JSON-schema v4 keywords as types
5  
6  
7 39 ▶use 5.42.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 39 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 39 ▶use Test::Deep::NoTest qw/ eq_deeply /;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 39 ▶use Math::BigFloat;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 39 ▶use Hash::Merge qw/ merge /;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 39 ▶use Type::Utils -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 39 ▶use Types::Standard qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
16 Str StrictNum HashRef ArrayRef
17 Int
18 Dict Slurpy Optional Any slurpy
19 Tuple
20 ConsumerOf
21 InstanceOf
22 39 /;
23  
24 use Type::Library
25 39 ▶ -base,
Subroutine BEGIN: called CC=1 SCAR=0.0
26 -declare => qw(
27 Minimum
28 ExclusiveMinimum
29 Maximum
30 ExclusiveMaximum
31 MultipleOf
32  
33 Null
34 Boolean
35 Array
36 Object
37 String
38 Integer
39 Pattern
40 Number
41  
42 Required
43  
44 Not
45  
46 OneOf
47 AllOf
48 AnyOf
49  
50 MaxLength
51 MinLength
52  
53 Items
54 AdditionalItems
55 MaxItems
56 MinItems
57  
58 Properties
59 PatternProperties
60 AdditionalProperties
61 MaxProperties
62 MinProperties
63  
64 Dependencies
65 Dependency
66  
67 Enum
68  
69 UniqueItems
70  
71 Schema
72  
73 39 );
74  
75 39 ▶use List::MoreUtils qw/ all any zip none /;
Subroutine BEGIN: called CC=1 SCAR=0.0
76 39 ▶use List::Util qw/ pairs pairmap reduce uniq /;
Subroutine BEGIN: called CC=1 SCAR=0.0
77 39 ▶use List::AllUtils qw/ none uniq /;
Subroutine BEGIN: called CC=1 SCAR=0.0
78  
79 39 ▶use JSON qw/ to_json from_json /;
Subroutine BEGIN: called CC=1 SCAR=0.0
80  
81 39 ▶use JSON::Schema::AsType;
Subroutine BEGIN: called CC=1 SCAR=0.0
82 39 ▶use JSON::Schema::AsType::Annotations;
Subroutine BEGIN: called CC=1 SCAR=0.0
83  
84 declare AdditionalProperties,
85 211 ▶ constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
86 211 my ( $known_properties, $type_or_boolean ) = @_;
87  
88 621 ▶ sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
89 621 ▶ return 1 unless Object->check($_);
Branch: 1 branch
BranchTrueFalseTotal
unless &Object()->check($_) 236 385 621
90  
91 my @add_keys = grep {
92 385 my $key = $_;
93 457 ▶ none { ref $_ ? $key =~ $_ : $key eq $_ } @$known_properties
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 68 392 460
94 } keys %$_;
95  
96 385 add_annotation( 'additionalProperties', @add_keys );
97  
98 385 ▶ if ( eval { $type_or_boolean->can('check') } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { $type_or_boolean->can("check") } }) 256 129 385
99 256 my $obj = $_;
100 256 ▶ return all { $type_or_boolean->check( $obj->{$_} ) } @add_keys;
Subroutine __ANON__: called CC=1 SCAR=0.0
101 }
102  
103 129 ▶ return not( @add_keys and not $type_or_boolean );
Condition100%3/3
@add_keys && !$type_or_boolean
!ll&&!rl&&r
83541
MC/DC100%2/2
@add_keys && !$type_or_boolean
@add_keys !$type_or_boolean
Truth table100%3/3
A && not(B)
A= @add_keysB= !$type_or_boolean
ABresult
0X0
100
111
104 }
105 211 };
106  
107 256 ▶declare UniqueItems, where {
Subroutine __ANON__: called CC=2 SCAR=6.9
108 256 ▶ return 1 unless Array->check($_);
Branch: 1 branch
BranchTrueFalseTotal
unless &Array()->check($_) 19 237 256
109 237 @$_ == uniq map { to_json $_, { allow_nonref => 1, canonical => 1 } } @$_
110 39 };
111  
112 39 my $json = JSON->new->allow_nonref->canonical;
113  
114 92 ▶declare Enum, constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
115 92 my @items = @_;
116  
117 1314 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
118 1314 my $j = $_;
119  
120 # TODO horrible corner case for the test suite, worth it?
121 1314 ▶ any { eq_deeply( $_, $j ) } @items;
Subroutine __ANON__: called CC=1 SCAR=0.0
122 }
123 92 };
124  
125 # Dependencies[ foo => $type, bar => [ 'baz' ] ]
126 # TODO name of generated type should be better
127 8 ▶declare Dependencies, constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
128 8 my %deps = @_;
129  
130 8 ▶ return reduce { $a & $b } pairmap { Dependency [ $a => $b ] } %deps;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
131 39 };
132  
133 # Depencency[ foo => $type ]
134 14 ▶declare Dependency, constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
135 14 my ( $property, $dep ) = @_;
136  
137 92 ▶ sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
138 92 ▶ return 1 unless Object->check($_);
Branch: 1 branch
BranchTrueFalseTotal
unless &Object()->check($_) 3 89 92
139 89 ▶ return 1 unless exists $_->{$property};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $_->{$property} 63 26 89
140  
141 26 my $obj = $_;
142  
143 26 ▶ 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" 13 13 26
144  
145 13 return $dep->check($_);
146 }
147 14 };
148  
149 54 ▶declare PatternProperties, constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
150 54 my %props = @_;
151  
152 389 ▶ sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
153 389 ▶ return 1 unless Object->check($_);
Branch: 1 branch
BranchTrueFalseTotal
unless &Object()->check($_) 101 288 389
154  
155 288 my $obj = $_;
156  
157 288 my @keys;
158 288 for my $key ( keys %props ) {
159 336 push @keys, grep { /$key/ } keys %$obj;
160 }
161  
162 288 add_annotation( 'patternProperties', @keys );
163  
164 288 for my $key ( keys %props ) {
165 return
166 211 ▶ unless all { $props{$key}->check( $obj->{$_} ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
167 317 ▶ grep { /$key/ } keys %$_;
Branch: 1 branch
BranchTrueFalseTotal
unless &all(sub { $props{$key}->check($obj->{$_}); } , grep({/$key/u;} keys %$_)) 67 250 317
168 }
169  
170 221 return 1;
171  
172 }
173 54 };
174 442 ▶declare Properties, constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
175 442 my %types = @_;
176  
177 442 ▶ %types = pairmap { $a => Optional [$b] } %types;
Subroutine __ANON__: called CC=1 SCAR=0.0
178  
179 return ~HashRef # not an object, don't care
180 | (
181 36305 ▶ Dict [ %types, Slurpy [Any] ] & sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
182 36305 my $value = $_;
183 add_annotation( 'properties',
184 36305 grep { exists $value->{$_} } keys %types );
185 36305 return 1;
186 }
187 442 );
188 39 };
189  
190 228 ▶declare Items, constraint_generator => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
191 228 my $types = shift;
192  
193 228 ▶ if ( Boolean->check($types) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Boolean()->check($types)) 3 225 228
194 3 ▶ return $types ? Any : sub { !@$_ };
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
$types ? : 0 3 3
195 }
196  
197 my $type =
198 ref $types eq 'ARRAY'
199 225 ▶ ? Tuple [ ( map { Optional [$_] } @$types ), slurpy Any ]
Branch: 1 branch
BranchTrueFalseTotal
ref $types eq 'ARRAY' ? : 120 105 225
200 : Tuple [ slurpy ArrayRef [$types] ];
201  
202 return ~ArrayRef | (
203 10463 ▶ $type & sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
204 10463 ▶ if ( ref $types eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $types eq 'ARRAY') { } 2168 8295 10463
205 2168 add_annotation( 'items', 0 .. $types->$#* );
206 }
207 else {
208 8295 add_annotation( 'items', 0 .. $_->$#* );
209 }
210 10463 return 1;
211 }
212 225 );
213  
214 39 };
215  
216 52 ▶declare AdditionalItems, constraint_generator => sub {
Subroutine __ANON__: called CC=3 SCAR=17.0
217 52 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) { } 52 0 52
218 52 my $to_skip = shift;
219 52 my $schema = shift;
220 317 ▶ return sub {
Subroutine __ANON__: called CC=4 SCAR=16.6
221  
222 317 ▶ return unless ref eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_ eq "ARRAY" 4 313 317
223 313 my @additional = splice @$_, $to_skip;
224  
225 313 ▶ if ( ref $schema eq 'JSON::PP::Boolean' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema eq "JSON::PP::Boolean") 0 313 313
226 0 my $verdict = @additional;
227 0 ▶ $verdict = !$verdict unless $schema;
Branch: 1 branch
BranchTrueFalseTotal
unless $schema 0 0 0
228 0 return $verdict;
229 }
230  
231 313 ▶ return all { $schema->check($_) } @additional;
Subroutine __ANON__: called CC=1 SCAR=0.0
232 }
233 52 }
234 else {
235 0 my $size = shift;
236 0 ▶ if ( ref $size eq 'JSON::PP::Boolean' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $size eq "JSON::PP::Boolean") 0 0 0
237 0 ▶ return sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
238 0 ▶ my $s = ref($_) eq 'ARRAY' ? @_ : 0;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 0 0 0
239 0 $DB::single = 1;
240 0 ▶ return !!$size ? $s : !$s;
Branch: 1 branch
BranchTrueFalseTotal
!!$size ? : 0 0 0
241 }
242 0 }
243 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
244 0 ▶ my $s = ref($_) eq 'ARRAY' ? @_ : 0;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 0 0 0
245 0 $s <= $size;
246 0 };
247 }
248 39 };
249  
250 11 ▶declare MaxLength, constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
251 11 my $length = shift;
252 122 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
253 122 ▶ !String->check($_) or $length >= length;
Branch: 1 branch
BranchTrueFalseTotal
not &String()->check($_) or $length >= length $_ 23 99 122
254 }
255 11 };
256  
257 6 ▶declare MinLength, constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
258 6 my $length = shift;
259 115 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
260 115 ▶ !String->check($_) or $length <= length;
Branch: 1 branch
BranchTrueFalseTotal
not &String()->check($_) or $length <= length $_ 23 92 115
261 }
262 6 };
263  
264 153 ▶declare AllOf, constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
265 153 my @types = @_;
266 425 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
267 425 my $value = $_;
268  
269 425 my $matched = 1;
270 425 my $scope = {};
271  
272 425 for my $type (@types) {
273 601 my %scope;
274 return 0 unless annotation_scope(
275 601 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
276 601 ▶ return 0 unless $type->check($value);
Branch: 1 branch
BranchTrueFalseTotal
unless $type->check($value) 160 441 601
277  
278 441 $scope = annotation_merge($scope);
279  
280 441 return 1;
281 }
282 601 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
unless annotation_scope(sub { return 0 unless $type->check($value); $scope = annotation_merge($scope); return 1; } ) 160 441 601
283 }
284  
285 265 annotation_merge($scope);
286  
287 265 return 1;
288 }
289 153 };
290  
291 143 ▶declare AnyOf, constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
292 143 my @types = @_;
293 757 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
294 757 my $value = $_;
295  
296 757 my $matched = 0;
297 757 my $scope = {};
298  
299 757 for my $type (@types) {
300 annotation_scope(
301 1488 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
302 1488 ▶ return unless $type->check($value);
Branch: 1 branch
BranchTrueFalseTotal
unless $type->check($value) 852 636 1488
303  
304 636 $scope = annotation_merge($scope);
305 636 $matched = 1;
306 }
307 1488 );
308 }
309  
310 757 ▶ if ($matched) {
Branch: 1 branch
BranchTrueFalseTotal
if ($matched) 589 168 757
311 589 annotation_merge($scope);
312 }
313  
314 757 return $matched;
315 }
316 143 };
317  
318 57 ▶declare OneOf, constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
319 57 my @types = @_;
320 277 ▶ sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
321 277 my $value = $_;
322  
323 277 my $matched = 0;
324 277 my $scope = {};
325  
326 277 for my $type (@types) {
327 return 0 unless annotation_scope(
328 585 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
329 585 ▶ return 1 unless $type->check($value);
Branch: 1 branch
BranchTrueFalseTotal
unless $type->check($value) 324 261 585
330  
331 261 ▶ return 0 if $matched;
Branch: 1 branch
BranchTrueFalseTotal
if $matched 57 204 261
332  
333 204 $scope = annotation_merge($scope);
334 204 $matched = 1;
335  
336 204 return 1;
337  
338 }
339 585 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
unless annotation_scope(sub { return 1 unless $type->check($value); return 0 if $matched; $scope = annotation_merge($scope); $matched = 1; return 1; } ) 57 528 585
340 }
341  
342 220 ▶ if ($matched) {
Branch: 1 branch
BranchTrueFalseTotal
if ($matched) 147 73 220
343 147 annotation_merge($scope);
344 }
345  
346 220 return $matched;
347 }
348 57 };
349  
350 4 ▶declare MaxProperties, constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
351 4 my $nbr = shift;
352 4 ▶ sub { !Object->check($_) or $nbr >= keys %$_; },;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
not &Object()->check($_) or $nbr >= keys %$_ 16 38 54
353 39 };
354  
355 3 ▶declare MinProperties, constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
356 3 my $nbr = shift;
357 51 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
358 51 ▶ !Object->check($_)
Branch: 1 branch
BranchTrueFalseTotal
not &Object()->check($_) or $nbr <= scalar keys %$_ 16 35 51
359 or $nbr <= scalar keys %$_;
360 3 },;
361 39 };
362  
363 51 ▶declare Not, constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
364 51 my $type = shift;
365 51 ▶ sub { not $type->check($_) },;
Subroutine __ANON__: called CC=1 SCAR=0.0
366 39 };
367  
368 # ~Str or ~String?
369 13 ▶declare Pattern, constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
370 13 my $regex = shift;
371 13 ▶ sub { !String->check($_) or /$regex/ },;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
not &String()->check($_) or /$regex/u 36 51 87
372 39 };
373  
374 37540 ▶declare Object => as HashRef, where sub { ref eq 'HASH' };
Subroutine __ANON__: called CC=1 SCAR=0.0
375  
376 26 ▶declare Required, constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
377 26 my @keys = @_;
378 18493 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
379 18493 ▶ return 1 unless Object->check($_);
Branch: 1 branch
BranchTrueFalseTotal
unless &Object()->check($_) 39 18454 18493
380 18454 my $obj = $_;
381 18454 ▶ all { exists $obj->{$_} } @keys;
Subroutine __ANON__: called CC=1 SCAR=0.0
382 }
383 26 };
384  
385 39 declare Array => as ArrayRef;
386  
387 1565 ▶declare Boolean => where sub { ref =~ /JSON/ };
Subroutine __ANON__: called CC=1 SCAR=0.0
388  
389 declare
390 LaxNumber => as StrictNum,
391 4 ▶ where sub {
Subroutine __ANON__: called CC=2 SCAR=9.2
392 4 ▶ return !( !defined || ref );
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
393 39 };
394  
395 73370 ▶declare Number => where sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
396 73370 ▶ return 0 if !defined || ref;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_ or ref $_ 44 73326 73370
Condition100%3/3
not defined $_ or ref $_
l!l&&r!l&&!r
83673326
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
397  
398 73326 my $b_obj = B::svref_2object( \$_ );
399 73326 my $flags = $b_obj->FLAGS;
400 73326 ▶ return ( $flags & ( B::SVp_IOK | B::SVp_NOK )
Condition66%2/3
$flags & 12288 && !($flags & 16384)
!ll&&!rl&&r
115073211
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
401 and not( $flags & B::SVp_POK ) );
402 39 };
403  
404 declare
405 LaxInteger => as Int,
406 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
407  
408 1245 ▶declare Integer => where sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
409 1245 ▶ return 0 unless Int->check($_);
Branch: 1 branch
BranchTrueFalseTotal
unless &Int()->check($_) 365 880 1245
410  
411 # weeeird stuff stolen from JSON
412 880 my $b_obj = B::svref_2object( \$_ );
413  
414 880 my $flags = $b_obj->FLAGS;
415 880 ▶ my $verdict =
Condition66%2/3
$flags & 12288 && !($flags & 16384)
!ll&&!rl&&r
90871
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
416 $flags & ( B::SVp_IOK | B::SVp_NOK ) && !( $flags & B::SVp_POK() );
417 880 return !!$verdict;
418 39 };
419  
420 declare
421 LaxString => as Str,
422 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
423  
424 declare
425 String => as Str,
426 3939 ▶ where sub {
Subroutine __ANON__: called CC=3 SCAR=12.0
427 3939 ▶ return 0 if !defined || ref;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_ or ref $_ 0 3939 3939
Condition33%1/3
not defined $_ or ref $_
l!l&&r!l&&!r
003939
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
428  
429 3939 my $b_obj = B::svref_2object( \$_ );
430 3939 my $flags = $b_obj->FLAGS;
431 3939 return ( $flags & B::SVp_POK );
432 39 };
433  
434 281 ▶declare Null => where sub { not defined };
Subroutine __ANON__: called CC=1 SCAR=0.0
435  
436 3 ▶declare 'MaxItems', constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
437 3 my $max = shift;
438  
439 90 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
440 90 ▶ ref ne 'ARRAY' or @$_ <= $max;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ne "ARRAY" or @$_ <= $max 7 83 90
441 3 };
442 39 };
443  
444 7 ▶declare 'MinItems', constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
445 7 my $min = shift;
446  
447 212 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
448 212 ▶ ref ne 'ARRAY' or @$_ >= $min;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ne "ARRAY" or @$_ >= $min 156 56 212
449 7 };
450 39 };
451  
452 8 ▶declare 'MultipleOf', constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
453 8 my $num = shift;
454  
455 254 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
456 254 ▶ return 1 unless Number->check($_);
Branch: 1 branch
BranchTrueFalseTotal
unless &Number()->check($_) 7 247 254
457 247 my ( $q, $r ) = Math::BigFloat->new($_)->bdiv($num);
458 247 return !$r;
459 }
460 8 };
461  
462 13 ▶declare Minimum, constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
463 13 my $minimum = shift;
464 281 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
465 281 ▶ !Number->check($_)
Branch: 1 branch
BranchTrueFalseTotal
not &Number()->check($_) or $_ >= $minimum 29 252 281
466 or $_ >= $minimum;
467 13 };
468 39 };
469  
470 7 ▶declare ExclusiveMinimum, constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
471 7 my $minimum = shift;
472 24 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
473 24 ▶ !StrictNum->check($_)
Branch: 1 branch
BranchTrueFalseTotal
not &StrictNum()->check($_) or $_ > $minimum 5 19 24
474 or $_ > $minimum;
475 }
476 7 };
477  
478 6 ▶declare Maximum, constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
479 6 my $max = shift;
480 149 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
481 149 ▶ !StrictNum->check($_)
Branch: 1 branch
BranchTrueFalseTotal
not &StrictNum()->check($_) or $_ <= $max 9 140 149
482 or $_ <= $max;
483 6 };
484 39 };
485  
486 3 ▶declare ExclusiveMaximum, constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
487 3 my $max = shift;
488 60 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
489 60 ▶ !StrictNum->check($_)
Branch: 1 branch
BranchTrueFalseTotal
not &StrictNum()->check($_) or $_ < $max 5 55 60
490 or $_ < $max;
491 }
492 3 };
493  
494 39 declare Schema, as InstanceOf ['Type::Tiny'];
495  
496 1 ▶coerce Schema, from HashRef, via {
Subroutine __ANON__: called CC=2 SCAR=7.4
497 1 my $schema = JSON::Schema::AsType->new( draft => 4, schema => $_ );
498  
499 1 ▶ if ( $schema->validate_schema ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema->validate_schema) 0 1 1
500 0 die "not a valid draft4 json schema\n";
501 }
502  
503 $schema->type
504 1 };
505  
506 39 1;
507  
508 __END__
« AsType/Draft6/Keywords.pm ↑ Summary AsType/Draft6/Types.pm »