| 1 | 38 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 38 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | package JSON::Schema::Modern::Vocabulary; | ||||||||||
| 4 | # vim: set ts=8 sts=2 sw=2 tw=100 et : | ||||||||||
| 5 | # ABSTRACT: Base role for JSON Schema vocabulary classes | ||||||||||
| 6 | |||||||||||
| 7 | 38 | our $VERSION = '0.654'; | |||||||||
| 8 | |||||||||||
| 9 | 38 | ▶ | use 5.020; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 38 | ▶ | use Moo::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 38 | ▶ | use strictures 2; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 38 | ▶ | use stable 0.031 'postderef'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 38 | ▶ | use experimental 'signatures'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 38 | ▶ | no autovivification warn => qw(fetch store exists delete); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 38 | ▶ | use if "$]" >= 5.022, experimental => 're_strict'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 38 | ▶ | no if "$]" >= 5.031009, feature => 'indirect'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 38 | ▶ | no if "$]" >= 5.033001, feature => 'multidimensional'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 38 | ▶ | no if "$]" >= 5.033006, feature => 'bareword_filehandles'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 38 | ▶ | no if "$]" >= 5.041009, feature => 'smartmatch'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 38 | ▶ | no feature 'switch'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 38 | ▶ | use JSON::Schema::Modern::Utilities qw(jsonp assert_keyword_type abort); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 38 | ▶ | use Carp (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 38 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | |||||||||||
| 25 | 38 | our @CARP_NOT = qw(JSON::Schema::Modern); | |||||||||
| 26 | |||||||||||
| 27 | 38 | requires qw(vocabulary keywords); | |||||||||
| 28 | |||||||||||
| 29 | 3 | ▶ | sub evaluation_order { 999 } # override, if needed | ||||||||
|
Subroutine
evaluation_order: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 30 | |||||||||||
| 31 | 0 | ▶ | sub BUILD { die 'these classes are never instantiated' } | ||||||||
|
Subroutine
BUILD: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 32 | |||||||||||
| 33 | 0 | ▶ | sub traverse ($class, $schema, $state) { | ||||||||
|
Subroutine
traverse: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 34 | 0 | $state->{evaluator}->_traverse_subschema($schema, $state); | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 6851 | ▶ | sub traverse_subschema ($class, $schema, $state) { | ||||||||
|
Subroutine
traverse_subschema: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 38 | $state->{evaluator}->_traverse_subschema($schema->{$state->{keyword}}, | ||||||||||
| 39 | 6851 | +{ %$state, keyword_path => $state->{keyword_path}.'/'.$state->{keyword} }); | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 3821 | ▶ | sub traverse_array_schemas ($class, $schema, $state) { | ||||||||
|
Subroutine
traverse_array_schemas: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||
| 43 | 3821 | ▶ | return if not assert_keyword_type($state, $schema, 'array'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 3821 | ▶ | return E($state, '%s array is empty', $state->{keyword}) if not $schema->{$state->{keyword}}->@*; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | |||||||||||
| 46 | 3821 | my $valid = 1; | |||||||||
| 47 | 3821 | foreach my $idx (0 .. $schema->{$state->{keyword}}->$#*) { | |||||||||
| 48 | $valid = 0 if not $state->{evaluator}->_traverse_subschema($schema->{$state->{keyword}}[$idx], | ||||||||||
| 49 | 6840 | ▶ | +{ %$state, keyword_path => $state->{keyword_path}.'/'.$state->{keyword}.'/'.$idx }); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | } | ||||||||||
| 51 | 3821 | return $valid; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 7022 | ▶ | sub traverse_object_schemas ($class, $schema, $state) { | ||||||||
|
Subroutine
traverse_object_schemas: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 55 | 7022 | ▶ | return if not assert_keyword_type($state, $schema, 'object'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | |||||||||||
| 57 | 7019 | my $valid = 1; | |||||||||
| 58 | 7019 | foreach my $property (sort keys $schema->{$state->{keyword}}->%*) { | |||||||||
| 59 | $valid = 0 if not $state->{evaluator}->_traverse_subschema($schema->{$state->{keyword}}{$property}, | ||||||||||
| 60 | 10368 | ▶ | +{ %$state, keyword_path => jsonp($state->{keyword_path}, $state->{keyword}, $property) }); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | } | ||||||||||
| 62 | 7019 | return $valid; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 280 | ▶ | sub traverse_property_schema ($class, $schema, $state, $property) { | ||||||||
|
Subroutine
traverse_property_schema: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 66 | 280 | ▶ | return if not assert_keyword_type($state, $schema, 'object'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | |||||||||||
| 68 | $state->{evaluator}->_traverse_subschema($schema->{$state->{keyword}}{$property}, | ||||||||||
| 69 | 280 | +{ %$state, keyword_path => jsonp($state->{keyword_path}, $state->{keyword}, $property) }); | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 13741 | ▶ | sub eval ($class, $data, $schema, $state) { | ||||||||
|
Subroutine
eval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 73 | 13741 | $state->{evaluator}->_evaluate_subschema($data, $schema, $state); | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 3968 | ▶ | sub eval_subschema_at_uri ($class, $data, $schema, $state, $uri) { | ||||||||
|
Subroutine
eval_subschema_at_uri: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 77 | 3968 | my $schema_info = $state->{evaluator}->_fetch_from_uri($uri); | |||||||||
| 78 | 3968 | ▶ | abort($state, 'EXCEPTION: unable to find resource "%s"', $uri) if not $schema_info; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | abort($state, 'EXCEPTION: bad reference to "%s": not a schema', $schema_info->{canonical_uri}) | ||||||||||
| 80 | 3962 | ▶ | if $schema_info->{document}->get_entity_at_location($schema_info->{document_path}) ne 'schema'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | |||||||||||
| 82 | 3959 | my $scope_uri = $schema_info->{canonical_uri}->clone->fragment(undef); | |||||||||
| 83 | 3959 | ▶ | push $state->{dynamic_scope}->@*, $scope_uri if $state->{dynamic_scope}->[-1] ne $scope_uri; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | |||||||||||
| 85 | return $state->{evaluator}->_evaluate_subschema($data, $schema_info->{schema}, | ||||||||||
| 86 | +{ | ||||||||||
| 87 | %$state, | ||||||||||
| 88 | # keyword is assumed to be json pointer-encoded (if a suffix path is needed), so we just concat | ||||||||||
| 89 | traversed_keyword_path => $state->{traversed_keyword_path}.$state->{keyword_path}.'/'.$state->{keyword}, | ||||||||||
| 90 | initial_schema_uri => $schema_info->{canonical_uri}, | ||||||||||
| 91 | 3959 | $schema_info->%{qw(document specification_version vocabularies)}, | |||||||||
| 92 | keyword_path => '', | ||||||||||
| 93 | }); | ||||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | 38 | 1; | |||||||||
| 97 | |||||||||||
| 98 | __END__ | ||||||||||