AsType/Draft6.pm

filter: Statementstmt 100% 55 / 55 Branchbran 100% 14 / 14 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 16 / 16 Podpod n/a totaltotal 100% 88 / 88 CC 10 SCAR 7.5
CC
10
Cov
100%
__ANON__
4.0
__ANON__
3.0
_has_id
3.0
CRAP 2.1
« AsType/Draft4.pm ↑ Summary AsType.pm »
1 package JSON::Schema::AsType::Draft6;
2 4 our $AUTHORITY = 'cpan:YANICK';
3 4 $JSON::Schema::AsType::Draft6::VERSION = '1.0.0';
4 # ABSTRACT: A draft 6 JSON Schema
5  
6  
7 4 ▶use 5.42.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 ▶use feature ':5.42';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use JSON::Schema::AsType::Visit;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use List::Util qw/ uniq /;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 4 extends qw/ JSON::Schema::AsType /;
19  
20 4 with 'JSON::Schema::AsType::Draft6::Keywords';
21  
22 4 ▶use feature qw/ signatures /;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 4 my $_uri_port = 1;
25 235 ▶has '+uri' => default => sub($self) {
Subroutine __ANON__: called CC=2 SCAR=6.9
26 my $id =
27 235 ▶ 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++
l!l
22213
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"} } }
Aresult
11
00
28 235 $self->clear_parent_schema;
29 235 return $id;
30 4 };
31  
32 4 has '+draft' => default => 6;
33  
34 has '+metaschema' => (
35 938 ▶ default => sub($self) {
Subroutine __ANON__: called CC=1 SCAR=0.0
36 938 _metaschema();
37 }
38 4 );
39  
40 750 ▶override all_keywords => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
41 750 my $self = shift;
42  
43 # $ref trumps all
44 750 ▶ return '$ref' if $self->schema->{'$ref'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->schema->{"\$ref"} 171 579 750
45  
46 579 return uniq '$id', super();
47 4 };
48  
49 700 ▶around sub_schema => sub ( $orig, $self, $subschema, $uri ) {
Subroutine __ANON__: called CC=3 SCAR=11.0
50  
51 # ah AH, resolve the subschema id
52 700 ▶ if ( my $id = $self->_has_id($subschema) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $id = $self->_has_id($subschema)) 66 634 700
53 66 ▶ $uri = $self->resolve_uri($id) unless $subschema->{'$ref'};
Branch: 1 branch
BranchTrueFalseTotal
unless $subschema->{"\$ref"} 61 5 66
54 }
55 700 $orig->( $self, $subschema, $uri );
56 4 };
57  
58 938 ▶sub _schema_trigger( $self, $schema, @ ) {
Subroutine _schema_trigger: called CC=1 SCAR=0.0
59 JSON::Schema::AsType::Visit::visit(
60 $schema,
61 3294 ▶ sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
62 3294 ▶ return unless ref $_ eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_ eq "HASH" 2162 1132 3294
63  
64 1132 ▶ my $id = $self->_has_id($_) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $id = $self->_has_id($_) or return 28 1104 1132
65  
66 # that doesn't look like a 'id' for the schema
67 28 ▶ return if ref $id;
Branch: 1 branch
BranchTrueFalseTotal
if ref $id 6 22 28
68  
69 22 $self->sub_schema( $_, $id );
70 22 return;
71 }
72 938 );
73 }
74  
75 1895 ▶sub _has_id ( $self, $schema = {} ) {
Subroutine _has_id: called CC=3 SCAR=11.0
76 1895 ▶ return unless ref $schema eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $schema eq "HASH" 55 1840 1895
77 1840 return $schema->{'$id'};
78 }
79  
80 940 ▶sub _metaschema {
Subroutine _metaschema: called CC=1 SCAR=0.0
81 940 state $METASCHEMA = __PACKAGE__->new(
82 uri => "https://json-schema.org/draft-06/schema",
83 schema => from_json join '',
84 <DATA>,
85 );
86  
87 940 return $METASCHEMA;
88 }
89  
90 =pod
91  
92 =encoding UTF-8
93  
94 =head1 NAME
95  
96 JSON::Schema::AsType::Draft6 - A draft 6 JSON Schema
97  
98 =head1 VERSION
99  
100 version 1.0.0
101  
102 =head1 DESCRIPTION
103  
104 Internal module for L<JSON::Schema:::AsType>.
105  
106 =head1 AUTHOR
107  
108 Yanick Champoux <yanick@babyl.dyndns.org>
109  
110 =head1 COPYRIGHT AND LICENSE
111  
112 This software is copyright (c) 2026 by Yanick Champoux.
113  
114 This is free software; you can redistribute it and/or modify it under
115 the same terms as the Perl 5 programming language system itself.
116  
117 =cut
118  
119 __DATA__
« AsType/Draft4.pm ↑ Summary AsType.pm »