| 1 | package JSON::Schema::AsType::Draft3; | ||||||||||||
| 2 | 5 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||||
| 3 | # | ||||||||||||
| 4 | # ABSTRACT: A draft 3 JSON Schema | ||||||||||||
| 5 | 5 | $JSON::Schema::AsType::Draft3::VERSION = '1.0.0'; | |||||||||||
| 6 | |||||||||||||
| 7 | 5 | ▶ | use 5.42.0; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 5 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 5 | ▶ | use JSON; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | 5 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | 5 | ▶ | use feature ':5.42'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | |||||||||||||
| 16 | 5 | ▶ | use JSON::Schema::AsType::Visit; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | 5 | ▶ | use List::Util qw/ uniq /; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | |||||||||||||
| 19 | 5 | extends qw/ JSON::Schema::AsType /; | |||||||||||
| 20 | |||||||||||||
| 21 | 5 | with 'JSON::Schema::AsType::Draft3::Keywords'; | |||||||||||
| 22 | |||||||||||||
| 23 | 5 | ▶ | use feature qw/ signatures /; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 24 | |||||||||||||
| 25 | 5 | has '+draft' => default => 3; | |||||||||||
| 26 | |||||||||||||
| 27 | 5 | my $_uri_port = 1; | |||||||||||
| 28 | 124 | ▶ | has '+uri' => default => sub($self) { | ||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||
| 29 | my $id = | ||||||||||||
| 30 | 124 | ▶ | eval { $self->schema->{id} } // 'http://254.0.0.1:' . $_uri_port++; | ||||||||||
|
Condition100%2/2
eval {
do {
$self->schema->{"id"}
}
} // 'http://254.0.0.1:' . $_uri_port++
MC/DC100%1/1
eval {
do {
$self->schema->{"id"}
}
} // 'http://254.0.0.1:' . $_uri_port++
eval {
do {
$self->schema->{"id"}
}
}
Truth table100%2/2
A
A= eval {
do {
$self->schema->{"id"}
}
}
| |||||||||||||
| 31 | 124 | $self->clear_parent_schema; | |||||||||||
| 32 | 124 | return $id; | |||||||||||
| 33 | 5 | }; | |||||||||||
| 34 | |||||||||||||
| 35 | has '+metaschema' => ( | ||||||||||||
| 36 | 434 | ▶ | default => sub($self) { | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 37 | 434 | _metaschema(); | |||||||||||
| 38 | } | ||||||||||||
| 39 | 5 | ); | |||||||||||
| 40 | |||||||||||||
| 41 | 370 | ▶ | override all_keywords => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||
| 42 | 370 | my $self = shift; | |||||||||||
| 43 | |||||||||||||
| 44 | # $ref trumps all | ||||||||||||
| 45 | 370 | ▶ | return '$ref' if $self->schema->{'$ref'}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 46 | |||||||||||||
| 47 | 315 | return uniq 'id', super(); | |||||||||||
| 48 | 5 | }; | |||||||||||
| 49 | |||||||||||||
| 50 | 333 | ▶ | sub _has_id ( $self, $schema = {} ) { | ||||||||||
|
Subroutine
_has_id: called CC=3 SCAR=11.0
| |||||||||||||
| 51 | 333 | ▶ | return unless ref $schema eq 'HASH'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 52 | 327 | return $schema->{id}; | |||||||||||
| 53 | } | ||||||||||||
| 54 | |||||||||||||
| 55 | 434 | ▶ | sub _schema_trigger( $self, $schema, @ ) { | ||||||||||
|
Subroutine
_schema_trigger: called CC=1 SCAR=0.0
| |||||||||||||
| 56 | JSON::Schema::AsType::Visit::visit( | ||||||||||||
| 57 | $schema, | ||||||||||||
| 58 | 2663 | ▶ | sub { | ||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||
| 59 | 2663 | ▶ | return unless ref $_ eq 'HASH'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 60 | |||||||||||||
| 61 | 942 | ▶ | return unless $_->{id}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 62 | |||||||||||||
| 63 | 10 | $self->sub_schema( $_, $_->{id} ); | |||||||||||
| 64 | } | ||||||||||||
| 65 | 434 | ); | |||||||||||
| 66 | } | ||||||||||||
| 67 | |||||||||||||
| 68 | 435 | ▶ | sub _metaschema { | ||||||||||
|
Subroutine
_metaschema: called CC=1 SCAR=0.0
| |||||||||||||
| 69 | 435 | state $METASCHEMA = __PACKAGE__->new( | |||||||||||
| 70 | uri => "https://json-schema.org/draft-03/schema", | ||||||||||||
| 71 | schema => from_json join '', | ||||||||||||
| 72 | <DATA>, | ||||||||||||
| 73 | ); | ||||||||||||
| 74 | |||||||||||||
| 75 | 435 | return $METASCHEMA; | |||||||||||
| 76 | } | ||||||||||||
| 77 | |||||||||||||
| 78 | 306 | ▶ | around sub_schema => sub ( $orig, $self, $subschema, $uri ) { | ||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||
| 79 | |||||||||||||
| 80 | # ah AH, resolve the subschema id | ||||||||||||
| 81 | 306 | ▶ | if ( my $id = $self->_has_id($subschema) ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 82 | 17 | ▶ | $uri = $self->resolve_uri($id) unless $subschema->{'$ref'}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 83 | } | ||||||||||||
| 84 | 306 | $orig->( $self, $subschema, $uri ); | |||||||||||
| 85 | 5 | }; | |||||||||||
| 86 | |||||||||||||
| 87 | =pod | ||||||||||||
| 88 | |||||||||||||
| 89 | =encoding UTF-8 | ||||||||||||
| 90 | |||||||||||||
| 91 | =head1 NAME | ||||||||||||
| 92 | |||||||||||||
| 93 | JSON::Schema::AsType::Draft3 - A draft 3 JSON Schema | ||||||||||||
| 94 | |||||||||||||
| 95 | =head1 VERSION | ||||||||||||
| 96 | |||||||||||||
| 97 | version 1.0.0 | ||||||||||||
| 98 | |||||||||||||
| 99 | =head1 DESCRIPTION | ||||||||||||
| 100 | |||||||||||||
| 101 | Internal module for L<JSON::Schema:::AsType>. | ||||||||||||
| 102 | |||||||||||||
| 103 | =head1 AUTHOR | ||||||||||||
| 104 | |||||||||||||
| 105 | Yanick Champoux <yanick@babyl.dyndns.org> | ||||||||||||
| 106 | |||||||||||||
| 107 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 108 | |||||||||||||
| 109 | This software is copyright (c) 2026 by Yanick Champoux. | ||||||||||||
| 110 | |||||||||||||
| 111 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 112 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 113 | |||||||||||||
| 114 | =cut | ||||||||||||
| 115 | |||||||||||||
| 116 | __DATA__ | ||||||||||||