| 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
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 151 | ▶ | return ( ( $self->schema eq JSON::true ) ? Any : ~Any ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
MC/DC100%1/1
$self->schema->{"minContains"} // 1
$self->schema->{"minContains"}
Truth table100%2/2
A
A= $self->schema->{"minContains"}
| |||||||||||||||||||||||||||||
| 48 | 31 | ▶ | my $max = $self->schema->{maxContains} // 9E99; # for 2019-09 | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->schema->{"maxContains"} // "9e+99"
MC/DC100%1/1
$self->schema->{"maxContains"} // "9e+99"
$self->schema->{"maxContains"}
Truth table100%2/2
A
A= $self->schema->{"maxContains"}
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 31 | ▶ | if ( JSON::is_bool($type) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 6 | ▶ | if ($type) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 85 | 22 | ▶ | return if $items; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 3 | return Items [JSON::false]; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 157 | ▶ | if ( ref $items eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
ref $b eq "HASH" or ref $b eq "JSON::PP::Boolean"
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"
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||