AsType/Draft7/Types.pm

filter: Statementstmt 89.1% 33 / 37 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod n/a totaltotal 86.5% 45 / 52 CC 3 SCAR 5.3
CC
3
Cov
85%
__ANON__
4.5
__ANON__
2.0
BEGIN
1.0
CRAP 1.7
« AsType/Draft3/Types.pm ↑ Summary AsType/Annotations.pm »
1 package JSON::Schema::AsType::Draft7::Types;
2 22 our $AUTHORITY = 'cpan:YANICK';
3 22 $JSON::Schema::AsType::Draft7::Types::VERSION = '1.0.0';
4 # ABSTRACT: Type::Tiny types for draft 7 schemas
5  
6  
7 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 22 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 22 ▶use Type::Utils -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 22 ▶use Types::Standard qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
12 Str StrictNum HashRef ArrayRef
13 Int
14 Dict slurpy Optional Any
15 Tuple
16 InstanceOf
17 22 /;
18  
19 use Type::Library
20 22 ▶ -base,
Subroutine BEGIN: called CC=1 SCAR=0.0
21 -declare => qw(
22 Schema
23 22 );
24  
25 22 ▶use List::MoreUtils qw/ all any zip none /;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 22 ▶use List::Util qw/ pairs pairmap reduce uniq /;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 22 ▶use JSON::Schema::AsType;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 # __PACKAGE__->meta->add_type( $_ ) for Integer, Boolean, Number, String, Null, Object, Array, Items, ExclusiveMaximum, ExclusiveMinimum;
31  
32 44 ▶declare If => constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
33 44 my ( $if, $then, $else ) = @_;
34  
35 130 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
36 130 ▶ $if->check($_) ? $then->check($_) : $else->check($_);
Branch: 1 branch
BranchTrueFalseTotal
$if->check($_) ? : 65 65 130
37 }
38  
39 44 };
40  
41 22 declare Schema, as InstanceOf ['Type::Tiny'];
42  
43 0 ▶coerce Schema, from HashRef, via {
Subroutine __ANON__: not called CC=2 SCAR=15.1
44 0 my $schema = JSON::Schema::AsType->new( draft => 7, schema => $_ );
45  
46 0 ▶ if ( $schema->validate_schema ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema->validate_schema) 0 0 0
47 0 die "not a valid draft7 json schema\n";
48 }
49  
50 $schema->type
51 0 };
52  
53 22 1;
54  
55 __END__
« AsType/Draft3/Types.pm ↑ Summary AsType/Annotations.pm »