AsType/Draft4.pm

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