| 1 | package JSON::Schema::AsType::Draft6; | ||||||||||||||||||||||||||||
| 2 | 3 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: Role processing draft6 JSON Schema | ||||||||||||||||||||||||||||
| 4 | 3 | $JSON::Schema::AsType::Draft6::VERSION = '0.4.2'; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Type::Utils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Scalar::Util qw/ looks_like_number /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use List::Util qw/ reduce pairmap pairs /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use List::MoreUtils qw/ any all none uniq zip /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use Types::Standard qw/InstanceOf HashRef StrictNum Any Str ArrayRef Int slurpy Dict Optional slurpy /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use JSON; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 3 | ▶ | use JSON::Schema::AsType; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 3 | ▶ | use JSON::Schema::AsType::Draft6::Types '-all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | with 'JSON::Schema::AsType::Draft4'; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | override all_keywords => sub { | ||||||||||||||||||||||||||||
| 26 | 6228 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # $ref trumps all | ||||||||||||||||||||||||||||
| 29 | 6228 | ▶ | return '$ref' if $self->schema->{'$ref'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 6010 | return uniq '$id', super(); | |||||||||||||||||||||||||||
| 32 | 3 | }; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | override _build_type => sub { | ||||||||||||||||||||||||||||
| 35 | 8962 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 8962 | ▶ | return super() if ref $self->schema eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 3 | ▶ | use JSON; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 44 | ▶ | return( ( $self->schema eq JSON::true) ? Any : ~Any ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 3 | }; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | sub _keyword_const { | ||||||||||||||||||||||||||||
| 45 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_keyword_const: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 4 | $self->_keyword_enum([@_]); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | sub _keyword_contains { | ||||||||||||||||||||||||||||
| 51 | 4 | ▶ | my( $self, $type ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_keyword_contains: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 4 | return Contains[ | |||||||||||||||||||||||||||
| 54 | $self->sub_schema($type)->type | ||||||||||||||||||||||||||||
| 55 | ]; | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | }; | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | sub _keyword_exclusiveMaximum { | ||||||||||||||||||||||||||||
| 60 | 1 | ▶ | my( $self, $maximum ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_keyword_exclusiveMaximum: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 1 | ExclusiveMaximum[$maximum]; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | sub _keyword_exclusiveMinimum { | ||||||||||||||||||||||||||||
| 66 | 1 | ▶ | my( $self, $maximum ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_keyword_exclusiveMinimum: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 1 | ExclusiveMinimum[$maximum]; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub _keyword_propertyNames { | ||||||||||||||||||||||||||||
| 72 | 3 | ▶ | my( $self, $schema ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_keyword_propertyNames: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 3 | PropertyNames[ $self->sub_schema($schema)->type ]; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | sub _keyword_items { | ||||||||||||||||||||||||||||
| 78 | 39 | ▶ | my( $self, $items ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_keyword_items: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 39 | ▶ | if ( Boolean->check($items) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 2 | ▶ | return if $items; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 1 | return Items[JSON::false]; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 37 | ▶ | if( ref $items eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 31 | my $type = $self->sub_schema($items)->type; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 31 | return Items[$type]; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # TODO forward declaration not workie | ||||||||||||||||||||||||||||
| 92 | 6 | my @types; | |||||||||||||||||||||||||||
| 93 | 6 | for ( @$items ) { | |||||||||||||||||||||||||||
| 94 | 11 | push @types, $self->sub_schema($_)->type; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 6 | return Items[\@types]; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | sub _keyword_dependencies { | ||||||||||||||||||||||||||||
| 101 | 5 | ▶ | my( $self, $dependencies ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_keyword_dependencies: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | return Dependencies[ | ||||||||||||||||||||||||||||
| 104 | pairmap { | ||||||||||||||||||||||||||||
| 105 | 6 | ▶ | $a => ( ref $b eq 'HASH' or ref $b eq 'JSON::PP::Boolean' ) ? $self->sub_schema($b) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
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"
| |||||||||||||||||||||||||||||
| 106 | 5 | : $b } %$dependencies | |||||||||||||||||||||||||||
| 107 | ]; | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | __PACKAGE__->meta->add_method( '_keyword_$id' => sub { | ||||||||||||||||||||||||||||
| 112 | 189 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_keyword_$id: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 113 | 189 | $self->_keyword_id(@_); | |||||||||||||||||||||||||||
| 114 | 3 | } ); | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 3 | 1; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | __END__ | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =pod | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =head1 NAME | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | JSON::Schema::AsType::Draft6 - Role processing draft6 JSON Schema | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =head1 VERSION | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | version 0.4.2 | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | This role is not intended to be used directly. It is used internally | ||||||||||||||||||||||||||||
| 135 | by L<JSON::Schema::AsType> objects. | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | Importing this module auto-populate the Draft4 schema in the | ||||||||||||||||||||||||||||
| 138 | L<JSON::Schema::AsType> schema cache. | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | Yanick Champoux <yanick@babyl.dyndns.org> | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | This software is copyright (c) 2015 by Yanick Champoux. | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 149 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =cut | ||||||||||||||||||||||||||||