AsType/Draft7.pm

filter: Statementstmt 100% 54 / 54 Branchbran 100% 12 / 12 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 16 / 16 Podpod n/a totaltotal 100% 85 / 85 CC 9 SCAR 6.5
CC
9
Cov
100%
__ANON__
3.0
__ANON__
3.0
_has_id
3.0
CRAP 1.9
« AsType/Draft3.pm ↑ Summary AsType/Draft3/Types.pm »
1 package JSON::Schema::AsType::Draft7;
2 6 our $AUTHORITY = 'cpan:YANICK';
3 6 $JSON::Schema::AsType::Draft7::VERSION = '1.0.0';
4 # ABSTRACT: draft 7 JSON Schema
5  
6  
7 6 ▶use 5.42.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 ▶use feature ':5.42';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use JSON::Schema::AsType::Visit;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 6 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶use List::Util qw/ uniq /;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 6 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 6 extends qw/ JSON::Schema::AsType /;
19  
20 6 with 'JSON::Schema::AsType::Draft7::Keywords';
21  
22 6 ▶use feature qw/ signatures /;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 6 my $_uri_port = 1;
25 266 ▶has '+uri' => default => sub($self) {
Subroutine __ANON__: called CC=2 SCAR=6.9
26 my $id =
27 266 ▶ 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
23243
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 266 $self->clear_parent_schema;
29 266 return $id;
30 6 };
31  
32 6 has '+draft' => default => "7";
33  
34 has '+metaschema' => (
35 1142 ▶ default => sub($self) {
Subroutine __ANON__: called CC=1 SCAR=0.0
36 1142 _metaschema();
37 }
38 6 );
39  
40 903 ▶override all_keywords => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
41 903 my $self = shift;
42  
43 # $ref trumps all
44 903 ▶ return '$ref' if $self->schema->{'$ref'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->schema->{"\$ref"} 219 684 903
45  
46 684 return uniq 'id', super();
47 6 };
48  
49 871 ▶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 871 ▶ if ( my $id = $self->_has_id($subschema) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $id = $self->_has_id($subschema)) 93 778 871
53 93 ▶ $uri = $self->resolve_uri($id) unless $subschema->{'$ref'};
Branch: 1 branch
BranchTrueFalseTotal
unless $subschema->{"\$ref"} 79 14 93
54 }
55 871 $orig->( $self, $subschema, $uri );
56 6 };
57  
58 1142 ▶sub _schema_trigger( $self, $schema, @ ) {
Subroutine _schema_trigger: called CC=1 SCAR=0.0
59 JSON::Schema::AsType::Visit::visit(
60 $schema,
61 5565 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
62 5565 ▶ return unless ref $_ eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_ eq "HASH" 3538 2027 5565
63  
64 2027 ▶ my $id = $self->_has_id($_) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $id = $self->_has_id($_) or return 41 1986 2027
65  
66 41 $self->sub_schema( $_, $id );
67 41 return;
68 }
69 1142 );
70 }
71  
72 2979 ▶sub _has_id ( $self, $schema = {} ) {
Subroutine _has_id: called CC=3 SCAR=11.0
73 2979 ▶ return unless ref $schema eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $schema eq "HASH" 71 2908 2979
74 2908 return $schema->{'$id'};
75 }
76  
77 1144 ▶sub _metaschema {
Subroutine _metaschema: called CC=1 SCAR=0.0
78 1144 state $METASCHEMA = __PACKAGE__->new(
79 uri => "https://json-schema.org/draft-07/schema",
80 schema => from_json join '',
81 <DATA>
82 );
83  
84 1144 return $METASCHEMA;
85 }
86  
87 =pod
88  
89 =encoding UTF-8
90  
91 =head1 NAME
92  
93 JSON::Schema::AsType::Draft7 - draft 7 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__
« AsType/Draft3.pm ↑ Summary AsType/Draft3/Types.pm »