AsType/Draft6/Keywords.pm

filter: Statementstmt 100% 79 / 79 Branchbran 100% 16 / 16 Conditioncond 100% 7 / 7 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 23 / 23 Podpod n/a totaltotal 100% 129 / 129 CC 14 SCAR 10.0
CC
14
Cov
100%
_keyword_items
6.0
_keyword_contains
5.0
__ANON__
3.0
CRAP 2.7
« AsType/Draft2019_09.pm ↑ Summary AsType/Draft4/Types.pm »
1 package JSON::Schema::AsType::Draft6::Keywords;
2 12 our $AUTHORITY = 'cpan:YANICK';
3 12 $JSON::Schema::AsType::Draft6::Keywords::VERSION = '1.0.0';
4 # ABSTRACT: Role processing draft6 JSON Schema
5  
6  
7 24 ▶use 5.42.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 24 ▶use feature qw/ signatures/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 24 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 24 ▶use Type::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 24 ▶use Scalar::Util qw/ looks_like_number /;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 24 ▶use List::Util qw/ reduce pairmap pairs /;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 24 ▶use List::MoreUtils qw/ any all none uniq zip /;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 use Types::Standard
19 24 ▶ qw/InstanceOf HashRef StrictNum Any Str ArrayRef Int slurpy Dict Optional slurpy /;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 24 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 24 ▶use JSON::Schema::AsType;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 24 ▶use JSON::Schema::AsType::Draft6::Types '-all';
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 12 with 'JSON::Schema::AsType::Draft4::Keywords';
28  
29 2785 ▶override _build_type => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
30 2785 my $self = shift;
31  
32 2785 ▶ return super() if ref $self->schema eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->schema eq "HASH" 2634 151 2785
33  
34 151 ▶ return ( ( $self->schema eq JSON::true ) ? Any : ~Any );
Branch: 1 branch
BranchTrueFalseTotal
$self->schema eq JSON::true() ? : 98 53 151
35  
36 12 };
37  
38 156 ▶sub _keyword_const {
Subroutine _keyword_const: called CC=1 SCAR=0.0
39 156 my $self = shift;
40  
41 156 $self->_keyword_enum( [@_] );
42 }
43  
44 31 ▶sub _keyword_contains {
Subroutine _keyword_contains: called CC=5 SCAR=16.1
45 31 my ( $self, $type ) = @_;
46  
47 31 ▶ my $min = $self->schema->{minContains} // 1; # for 2019-09
Condition100%2/2
$self->schema->{"minContains"} // 1
l!l
922
MC/DC100%1/1
$self->schema->{"minContains"} // 1
$self->schema->{"minContains"}
Truth table100%2/2
A
A= $self->schema->{"minContains"}
Aresult
11
00
48 31 ▶ my $max = $self->schema->{maxContains} // 9E99; # for 2019-09
Condition100%2/2
$self->schema->{"maxContains"} // "9e+99"
l!l
724
MC/DC100%1/1
$self->schema->{"maxContains"} // "9e+99"
$self->schema->{"maxContains"}
Truth table100%2/2
A
A= $self->schema->{"maxContains"}
Aresult
11
00
49  
50 31 ▶ if ( JSON::is_bool($type) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&JSON::is_bool($type)) 6 25 31
51 6 ▶ if ($type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type) { } 3 3 6
52 3 $min = 1;
53 }
54 else {
55 3 $max = 0;
56 }
57 }
58  
59 31 return Contains [ $self->sub_schema( $type, '#./contains' )->type, $min,
60 $max ];
61  
62 }
63  
64 16 ▶sub _keyword_exclusiveMaximum {
Subroutine _keyword_exclusiveMaximum: called CC=1 SCAR=0.0
65 16 my ( $self, $maximum ) = @_;
66  
67 16 ExclusiveMaximum [$maximum];
68 }
69  
70 17 ▶sub _keyword_exclusiveMinimum {
Subroutine _keyword_exclusiveMinimum: called CC=1 SCAR=0.0
71 17 my ( $self, $maximum ) = @_;
72  
73 17 ExclusiveMinimum [$maximum];
74 }
75  
76 47 ▶sub _keyword_propertyNames {
Subroutine _keyword_propertyNames: called CC=1 SCAR=0.0
77 47 my ( $self, $schema ) = @_;
78  
79 47 PropertyNames [ $self->sub_schema( $schema, '#./propertyNames' )->type ];
80 }
81  
82 179 ▶sub _keyword_items( $self, $items, $keyword = 'items' ) {
Subroutine _keyword_items: called CC=6 SCAR=17.9
83  
84 179 ▶ if ( Boolean->check($items) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Boolean()->check($items)) 22 157 179
85 22 ▶ return if $items;
Branch: 1 branch
BranchTrueFalseTotal
if $items 19 3 22
86 3 return Items [JSON::false];
87 }
88  
89 157 ▶ if ( ref $items eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $items eq "HASH") 64 93 157
90 64 my $type = $self->sub_schema( $items, "#./$keyword" )->type;
91  
92 64 return Items [$type];
93 }
94  
95 # TODO forward declaration not workie
96 93 my @types;
97 93 my $i = 0;
98 93 for (@$items) {
99 162 push @types, $self->sub_schema( $_, "#./$keyword/" . $i++ )->type;
100 }
101  
102 93 return Items [ \@types ];
103 }
104  
105 14 ▶sub _keyword_dependencies {
Subroutine _keyword_dependencies: called CC=1 SCAR=0.0
106 14 my ( $self, $dependencies ) = @_;
107  
108 return Dependencies [
109 22 ▶ pairmap {
Subroutine __ANON__: called CC=3 SCAR=11.0
110 22 ▶ $a => ( ref $b eq 'HASH' or ref $b eq 'JSON::PP::Boolean' )
Branch: 1 branch
BranchTrueFalseTotal
ref $b eq 'HASH' || ref $b eq 'JSON::PP::Boolean' ? : 12 10 22
Condition100%3/3
ref $b eq "HASH" or ref $b eq "JSON::PP::Boolean"
l!l&&r!l&&!r
8410
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
111 ? $self->sub_schema( $b, '#./dependencies/' . $a )
112 : $b
113 14 } %$dependencies
114 ];
115  
116 }
117  
118 __PACKAGE__->meta->add_method(
119 8 ▶ '_keyword_$id' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine _keyword_$id: called CC=1 SCAR=0.0
120 8 my $self = shift;
121 8 $self->_keyword_id(@_);
122 }
123 12 );
124  
125 12 1;
126  
127 __END__
« AsType/Draft2019_09.pm ↑ Summary AsType/Draft4/Types.pm »