Modern/Result.pm

filter: Statementstmt 96.8% 153 / 158 Branchbran 77.5% 62 / 80 Conditioncond 73.2% 96 / 131 MC/DCmcdc 33.3% 21 / 63 Subroutinesub 91.8% 45 / 49 Podpod 58.3% 7 / 12 totaltotal 77.8% 384 / 493 CC 90 SCAR 32.9
CC
90
Cov
84%
format
71.4
__ANON__
17.6
combine
12.2
CRAP 26.9
« Modern/Vocabulary/FormatAssertion.pm ↑ Summary Modern/Utilities.pm »
1 46 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 46 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package JSON::Schema::Modern::Result;
4 # vim: set ts=8 sts=2 sw=2 tw=100 et :
5 # ABSTRACT: Contains the result of a JSON Schema evaluation
6  
7 46 our $VERSION = '0.654';
8  
9 46 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 46 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 46 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 46 ▶use stable 0.031 'postderef';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 46 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 46 ▶no autovivification warn => qw(fetch store exists delete);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 46 ▶use if "$]" >= 5.022, experimental => 're_strict';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 46 ▶no if "$]" >= 5.031009, feature => 'indirect';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 46 ▶no if "$]" >= 5.033001, feature => 'multidimensional';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 46 ▶no if "$]" >= 5.033006, feature => 'bareword_filehandles';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 46 ▶no if "$]" >= 5.041009, feature => 'smartmatch';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 46 ▶no feature 'switch';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 46 ▶use MooX::TypeTiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 46 ▶use Types::Standard qw(ArrayRef InstanceOf Enum Bool Str Maybe Tuple Map Any);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 46 ▶use Types::Common::Numeric 'PositiveInt';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 46 ▶use JSON::Schema::Modern::Annotation;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 46 ▶use JSON::Schema::Modern::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 46 ▶use JSON::Schema::Modern::Utilities qw(true false json_pointer_type jsonp_set);
Subroutine BEGIN: called CC=1 SCAR=0.0
27 46 ▶use JSON::PP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
28 46 ▶use List::Util 1.45 'uniqstr';
Subroutine BEGIN: called CC=1 SCAR=0.0
29 46 ▶use if "$]" < 5.041010, 'List::Util' => qw(any all);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 46 ▶use if "$]" >= 5.041010, experimental => qw(keyword_any keyword_all);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 46 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 46 ▶use builtin::compat qw(refaddr blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
33 46 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 use overload
36 46 ▶ '&' => \&combine,
Subroutine BEGIN: called CC=1 SCAR=0.2
37 0 ▶ '""' => sub { $_[0]->stringify },
Subroutine __ANON__: not called CC=1 SCAR=6.9
38 46 fallback => 1;
39  
40 has valid => (
41 is => 'ro',
42 isa => Bool|InstanceOf('JSON::PP::true')|InstanceOf('JSON::PP::false'),
43 17404 ▶ coerce => sub { $_[0] ? true : false }, # might be JSON::PP::* or builtin::* booleans
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 9530 7874 17404
44 lazy => 1,
45 3 ▶ default => sub ($self) { $self->error_count == 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
46 46 );
47 0 ▶sub result { goto \&valid } # backcompat only
Subroutine result: not called CC=1 SCAR=6.9
Pod undocumented
48  
49 has exception => (
50 is => 'ro',
51 isa => Bool,
52 lazy => 1,
53 12 ▶ default => sub ($self) { any { $_->exception or $_->error =~ /^EXCEPTION: / } $self->errors },
Subroutine __ANON__: called CC=2 SCAR=7.1
Condition66%2/3
$_->exception || $_->error =~ /^EXCEPTION: /u
l!l&&r!l&&!r
604
MC/DC50%1/2
$_->exception || $_->error =~ /^EXCEPTION: /u
$_->exception $_->error =~ /^EXCEPTION: /u
Truth table66%2/3
A || B
A= $_->exceptionB= $_->error =~ /^EXCEPTION: /u
ABresult
1X1
011
000
54 46 );
55  
56 # has errors
57 # has annotations
58 # turn hashrefs in _errors or _annotations into blessed objects
59 has $_.'s' => (
60 is => 'bare',
61 reader => '__'.$_.'s',
62 isa => ArrayRef[InstanceOf['JSON::Schema::Modern::'.ucfirst]],
63 lazy => 1,
64 default => do {
65 92 my $type = $_;
66 9349 ▶ sub ($self) {
Subroutine __ANON__: called CC=3 SCAR=11.0
67 9349 ▶ return [] if not (($self->{'_'.$type.'s'}//[])->@*);
Branch: 1 branch
BranchTrueFalseTotal
unless @{$$self{'_' . $type . 's'} // []} 9325 24 9349
Condition100%2/2
$$self{'_' . $type . 's'} // []
l!l
249325
MC/DC100%1/1
$$self{'_' . $type . 's'} // []
$$self{'_' . $type . 's'}
Truth table100%2/2
A
A= $$self{'_' . $type . 's'}
Aresult
11
00
68  
69 # E() and A() in ::Utilities returns an unblessed hashref, which is used to create a real object
70 # by its BUILDARGS sub
71 24 return [ map +(('JSON::Schema::Modern::'.ucfirst($type))->new($_)), $self->{'_'.$type.'s'}->@* ];
72 92 };
73 },
74 46 ) foreach qw(error annotation);
75  
76 28533 ▶sub errors { $_[0]->__errors->@* }
Subroutine errors: called CC=1 SCAR=0.0
Pod documented
77 6 ▶sub error_count { scalar(($_[0]->{errors}//[])->@*) || scalar(($_[0]->{_errors}//[])->@*) }
Subroutine error_count: called CC=4 SCAR=14.8
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
scalar @{$_[0]{"errors"} // []} or scalar @{$_[0]{"_errors"} // []} 3 3 6
Condition50%2/4
$_[0]{"errors"} // []
l!l
60
$_[0]{"_errors"} // []
l!l
03
MC/DC0%0/1
$_[0]{"errors"} // []
$_[0]{"errors"}
MC/DC0%0/1
$_[0]{"_errors"} // []
$_[0]{"_errors"}
Truth table50%1/2
A
A= $_[0]{"errors"}
Aresult
11
00
Truth table50%1/2
A
A= $_[0]{"_errors"}
Aresult
11
00
78 40 ▶sub annotations { $_[0]->__annotations->@* }
Subroutine annotations: called CC=1 SCAR=0.0
Pod documented
79 14134 ▶sub annotation_count { scalar(($_[0]->{annotations}//[])->@*) || scalar(($_[0]->{_annotations}//[])->@*) }
Subroutine annotation_count: called CC=4 SCAR=13.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
scalar @{$_[0]{"annotations"} // []} or scalar @{$_[0]{"_annotations"} // []} 1 14133 14134
Condition100%4/4
$_[0]{"annotations"} // []
l!l
614128
$_[0]{"_annotations"} // []
l!l
2414109
MC/DC100%1/1
$_[0]{"annotations"} // []
$_[0]{"annotations"}
MC/DC100%1/1
$_[0]{"_annotations"} // []
$_[0]{"_annotations"}
Truth table100%2/2
A
A= $_[0]{"annotations"}
Aresult
11
00
Truth table100%2/2
A
A= $_[0]{"_annotations"}
Aresult
11
00
80  
81 has recommended_response => (
82 is => 'rw',
83 isa => Maybe[Tuple[PositiveInt, Str]],
84 lazy => 1,
85 4 ▶ default => sub ($self) {
Subroutine __ANON__: called CC=5 SCAR=16.1
86 4 ▶ return if not $self->errors;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->errors 1 3 4
87  
88 3 for my $error ($self->errors) {
89 6 my $pe = $error->recommended_response;
90 6 ▶ return $pe if $pe;
Branch: 1 branch
BranchTrueFalseTotal
if $pe 1 5 6
91 }
92  
93 2 ▶ return [ 500, 'Internal Server Error' ] if $self->exception;
Branch: 1 branch
BranchTrueFalseTotal
if $self->exception 1 1 2
94 1 return [ 400, ($self->errors)[0]->stringify ];
95 },
96 46 );
97  
98 # strict_basic can only be used with draft2019-09.
99 46 ▶use constant OUTPUT_FORMATS => [qw(flag basic strict_basic terse data_only)];
Subroutine BEGIN: called CC=1 SCAR=0.0
100  
101 46 has output_format => (
102 is => 'rw',
103 isa => Enum(OUTPUT_FORMATS),
104 default => 'basic',
105 );
106  
107 46 has formatted_annotations => (
108 is => 'ro',
109 isa => Bool,
110 default => 1,
111 );
112  
113 46 has defaults => (
114 is => 'ro',
115 isa => Map[json_pointer_type() => Any],
116 );
117  
118 46 has data => (
119 is => 'ro',
120 );
121  
122 17406 ▶around BUILDARGS => sub ($orig, $class, @args) {
Subroutine __ANON__: called CC=16 SCAR=28.7
123 17406 my $args = $class->$orig(@args);
124  
125 # set unblessed hashrefs aside, and defer creation of blessed objects until needed
126 $args->{_errors} = delete $args->{errors} if
127 17406 ▶ exists $args->{errors} and any { !blessed($_) } $args->{errors}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if exists $$args{"errors"} and CORE::any {not builtin::blessed($_);} @{$$args{"errors"}} 0 17406 17406
Condition66%2/3
exists $$args{"errors"} and CORE::any {not builtin::blessed($_);} @{$$args{"errors"}}
!ll&&!rl&&r
952478820
MC/DC0%0/2
exists $$args{"errors"} and CORE::any {not builtin::blessed($_);} @{$$args{"errors"}}
exists $$args{"errors"} CORE::any {not builtin::blessed($_);} @{$$args{"errors"}}
Truth table66%2/3
A and B
A= exists $$args{"errors"}B= CORE::any {not builtin::blessed($_);} @{$$args{"errors"}}
ABresult
0X0
100
111
128 $args->{_annotations} = delete $args->{annotations} if
129 17406 ▶ exists $args->{annotations} and any { !blessed($_) } $args->{annotations}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if exists $$args{"annotations"} and CORE::any {not builtin::blessed($_);} @{$$args{"annotations"}} 24 17382 17406
Condition100%3/3
exists $$args{"annotations"} and CORE::any {not builtin::blessed($_);} @{$$args{"annotations"}}
!ll&&!rl&&r
173681424
MC/DC100%2/2
exists $$args{"annotations"} and CORE::any {not builtin::blessed($_);} @{$$args{"annotations"}}
exists $$args{"annotations"} CORE::any {not builtin::blessed($_);} @{$$args{"annotations"}}
Truth table100%3/3
A and B
A= exists $$args{"annotations"}B= CORE::any {not builtin::blessed($_);} @{$$args{"annotations"}}
ABresult
0X0
100
111
130  
131 croak 'inconsistent inputs: errors is not empty but valid is true'
132 if $args->{valid}
133 and (exists $args->{_errors} and $args->{_errors}->@*
134 17406 ▶ or exists $args->{errors} and $args->{errors}->@*);
Branch: 1 branch
BranchTrueFalseTotal
if $$args{"valid"} and exists $$args{"_errors"} && @{$$args{"_errors"}} || exists $$args{"errors"} && @{$$args{"errors"}} 1 17405 17406
Condition75%9/12
$$args{"valid"} and exists $$args{"_errors"} && @{$$args{"_errors"}} || exists $$args{"errors"} && @{$$args{"errors"}}
!ll&&!rl&&r
787895271
exists $$args{"_errors"} and @{$$args{"_errors"}} or exists $$args{"errors"} and @{$$args{"errors"}}
l!l&&r!l&&!r
019527
exists $$args{"_errors"} and @{$$args{"_errors"}}
!ll&&!rl&&r
952800
exists $$args{"errors"} and @{$$args{"errors"}}
!ll&&!rl&&r
952431
MC/DC60%3/5
$$args{"valid"} and exists $$args{"_errors"} && @{$$args{"_errors"}} || exists $$args{"errors"} && @{$$args{"errors"}}
$$args{"valid"} exists $$args{"_errors"} @{$$args{"_errors"}} exists $$args{"errors"} @{$$args{"errors"}}
Truth table50%4/8
A and B and C or D and E
A= $$args{"valid"}B= exists $$args{"_errors"}C= @{$$args{"_errors"}}D= exists $$args{"errors"}E= @{$$args{"errors"}}
ABCDEresult
0XXXX0
10X0X0
10X100
1100X0
110100
111XX1
10X111
110111
135  
136 croak 'inconsistent inputs: errors is empty but valid is false'
137 if exists $args->{valid} and not $args->{valid}
138 and (not exists $args->{_errors} or not $args->{_errors}->@*)
139 17405 ▶ and (not exists $args->{errors} or not $args->{errors}->@*);
Branch: 1 branch
BranchTrueFalseTotal
if exists $$args{"valid"} and not $$args{"valid"} and not exists $$args{"_errors"} && @{$$args{"_errors"}} and not exists $$args{"errors"} && @{$$args{"errors"}} 1 17404 17405
Condition73%11/15
exists $$args{"valid"} and not $$args{"valid"} and not exists $$args{"_errors"} && @{$$args{"_errors"}} and not exists $$args{"errors"} && @{$$args{"errors"}}
!ll&&!rl&&r
953078741
exists $$args{"valid"} and not $$args{"valid"} and not exists $$args{"_errors"} && @{$$args{"_errors"}}
!ll&&!rl&&r
953007875
exists $$args{"valid"} and not $$args{"valid"}
!ll&&!rl&&r
395277875
exists $$args{'_errors'} && @{$$args{'_errors'}}
!ll&&!rl&&r
787500
exists $$args{'errors'} && @{$$args{'errors'}}
!ll&&!rl&&r
017874
MC/DC50%3/6
exists $$args{"valid"} and not $$args{"valid"} and not exists $$args{"_errors"} && @{$$args{"_errors"}} and not exists $$args{"errors"} && @{$$args{"errors"}}
exists $$args{"valid"} not $$args{"valid"} exists $$args{'_errors'} @{$$args{'_errors'}} exists $$args{'errors'} @{$$args{'errors'}}
Truth table44%4/9
A and not(B) and not(C && D) and not(E && F)
A= exists $$args{"valid"}B= not $$args{"valid"}C= exists $$args{'_errors'}D= @{$$args{'_errors'}}E= exists $$args{'errors'}F= @{$$args{'errors'}}
ABCDEFresult
0XXXXX0
10XXXX0
1111XX0
110X110
1110110
110X0X1
110X101
11100X1
1110101
140  
141 17404 return $args;
142 46 };
143  
144 17404 ▶sub BUILD ($self, $args) {
Subroutine BUILD: called CC=6 SCAR=17.9
Pod undocumented
145 17404 ▶ $self->{_errors} = $args->{_errors} if exists $args->{_errors};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$args{"_errors"} 0 17404 17404
146 17404 ▶ $self->{_annotations} = $args->{_annotations} if exists $args->{_annotations};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$args{"_annotations"} 24 17380 17404
147  
148 17404 ▶ if (exists $args->{data} and exists $args->{defaults}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$args{"data"} and exists $$args{"defaults"}) 10 17394 17404
Condition100%3/3
exists $$args{"data"} and exists $$args{"defaults"}
!ll&&!rl&&r
1651722910
MC/DC100%2/2
exists $$args{"data"} and exists $$args{"defaults"}
exists $$args{"data"} exists $$args{"defaults"}
Truth table100%3/3
A and B
A= exists $$args{"data"}B= exists $$args{"defaults"}
ABresult
0X0
100
111
149 10 jsonp_set($args->{data}, $args->{defaults}->%{$_}) foreach keys $args->{defaults}->%*;
150 }
151 }
152  
153 25755 ▶sub format ($self, $style, $formatted_annotations = undef) {
Subroutine format: called CC=44 SCAR=42.7
Pod documented
154 25755 ▶ $formatted_annotations //= $self->formatted_annotations;
Condition33%1/3
$formatted_annotations //= $self->formatted_annotations
l!l&&r!l&&!r
0257550
MC/DC0%0/2
$formatted_annotations //= $self->formatted_annotations
$formatted_annotations $self->formatted_annotations
Truth table33%1/3
A //= B
A= $formatted_annotationsB= $self->formatted_annotations
ABresult
1X1
011
000
155  
156 25755 ▶ if ($style eq 'flag') {
Branch: 5 branches
BranchTrueFalseTotal
if ($style eq 'flag') { } 1 25754 25755
elsif ($style eq 'basic') { } 25749 5 25754
elsif ($style eq 'strict_basic') { } 1 4 5
elsif ($style eq 'terse') { } 2 2 4
elsif ($style eq 'data_only') { } 2 0 2
157 1 ▶ return +{ valid => $self->valid ? true : false };
Branch: 1 branch
BranchTrueFalseTotal
$self->valid ? : 0 1 1
158 }
159 elsif ($style eq 'basic') {
160 return +{
161 25749 ▶ valid => $self->valid ? true : false,
Branch: 4 branches
BranchTrueFalseTotal
$self->valid ? : 14135 11614 25749
$self->valid ? : 14135 11614 25749
$formatted_annotations && $self->annotation_count ? : 25 14110 14135
$self->valid && $self->defaults ? : 10 25739 25749
Condition100%6/6
$formatted_annotations and $self->annotation_count
!ll&&!rl&&r
11410925
$self->valid and $self->defaults
!ll&&!rl&&r
116141412510
MC/DC100%2/2
$formatted_annotations and $self->annotation_count
$formatted_annotations $self->annotation_count
MC/DC100%2/2
$self->valid and $self->defaults
$self->valid $self->defaults
Truth table100%3/3
A and B
A= $formatted_annotationsB= $self->annotation_count
ABresult
0X0
100
111
Truth table100%3/3
A and B
A= $self->validB= $self->defaults
ABresult
0X0
100
111
162 $self->valid
163 ? ($formatted_annotations && $self->annotation_count ? (annotations => [ map $_->TO_JSON, $self->annotations ]) : ())
164 : (errors => [ map $_->TO_JSON, $self->errors ]),
165 $self->valid && $self->defaults ? (defaults => $self->defaults) : (),
166 };
167 }
168 # note: strict_basic will NOT be supported after draft 2019-09!
169 elsif ($style eq 'strict_basic') {
170 return +{
171 1 ▶ valid => ($self->valid ? true : false),
Branch: 3 branches
BranchTrueFalseTotal
$self->valid ? : 0 1 1
$self->valid ? : 0 1 1
$formatted_annotations && $self->annotation_count ? : 0 0 0
Condition0%0/3
$formatted_annotations and $self->annotation_count
!ll&&!rl&&r
000
MC/DC0%0/2
$formatted_annotations and $self->annotation_count
$formatted_annotations $self->annotation_count
Truth table0%0/3
A and B
A= $formatted_annotationsB= $self->annotation_count
ABresult
0X0
100
111
172 $self->valid
173 ? ($formatted_annotations && $self->annotation_count ? (annotations => [ map _map_uris($_->TO_JSON), $self->annotations ]) : ())
174 : (errors => [ map _map_uris($_->TO_JSON), $self->errors ]),
175 };
176 }
177 elsif ($style eq 'terse') {
178 2 my (%instance_locations, %keyword_locations);
179  
180 2 my @errors = grep do {
181 29 my ($keyword, $error) = ($_->keyword, $_->error);
182  
183 29 ▶ my $keep = 0+!!(
Condition85%41/48
!$keyword || !grep(($keyword eq $_), ('allOf', 'anyOf', 'if', 'then', 'else', 'dependentSchemas', 'contains', 'propertyNames')) && ($keyword ne 'oneOf' || $error ne 'no subschemas are valid') && ($keyword ne 'prefixItems' || $error eq 'item not permitted') && ($keyword ne 'items' || $error eq 'item not permitted' || $error eq 'additional item not permitted') && ($keyword ne 'additionalItems' || $error eq 'additional item not permitted') && (!grep(($keyword eq $_), ('properties', 'patternProperties')) || $error eq 'property not permitted') && ($keyword ne 'additionalProperties' || $error eq 'additional property not permitted') && ($keyword ne 'dependentRequired' || $error ne 'not all dependencies are satisfied')
l!l&&r!l&&!r
01712
not grep(($keyword eq $_), ("allOf", "anyOf", "if", "then", "else", "dependentSchemas", "contains", "propertyNames")) and $keyword ne "oneOf" || $error ne "no subschemas are valid" and $keyword ne "prefixItems" || $error eq "item not permitted" and $keyword ne "items" || $error eq "item not permitted" || $error eq "additional item not permitted" and $keyword ne "additionalItems" || $error eq "additional item not permitted" and !grep(($keyword eq $_), ("properties", "patternProperties")) || $error eq "property not permitted" and $keyword ne "additionalProperties" || $error eq "additional property not permitted" and $keyword ne "dependentRequired" || $error ne "not all dependencies are satisfied"
!ll&&!rl&&r
12017
not grep(($keyword eq $_), ("allOf", "anyOf", "if", "then", "else", "dependentSchemas", "contains", "propertyNames")) and $keyword ne "oneOf" || $error ne "no subschemas are valid" and $keyword ne "prefixItems" || $error eq "item not permitted" and $keyword ne "items" || $error eq "item not permitted" || $error eq "additional item not permitted" and $keyword ne "additionalItems" || $error eq "additional item not permitted" and !grep(($keyword eq $_), ("properties", "patternProperties")) || $error eq "property not permitted" and $keyword ne "additionalProperties" || $error eq "additional property not permitted"
!ll&&!rl&&r
11117
not grep(($keyword eq $_), ("allOf", "anyOf", "if", "then", "else", "dependentSchemas", "contains", "propertyNames")) and $keyword ne "oneOf" || $error ne "no subschemas are valid" and $keyword ne "prefixItems" || $error eq "item not permitted" and $keyword ne "items" || $error eq "item not permitted" || $error eq "additional item not permitted" and $keyword ne "additionalItems" || $error eq "additional item not permitted" and !grep(($keyword eq $_), ("properties", "patternProperties")) || $error eq "property not permitted"
!ll&&!rl&&r
9218
not grep(($keyword eq $_), ("allOf", "anyOf", "if", "then", "else", "dependentSchemas", "contains", "propertyNames")) and $keyword ne "oneOf" || $error ne "no subschemas are valid" and $keyword ne "prefixItems" || $error eq "item not permitted" and $keyword ne "items" || $error eq "item not permitted" || $error eq "additional item not permitted" and $keyword ne "additionalItems" || $error eq "additional item not permitted"
!ll&&!rl&&r
9020
not grep(($keyword eq $_), ("allOf", "anyOf", "if", "then", "else", "dependentSchemas", "contains", "propertyNames")) and $keyword ne "oneOf" || $error ne "no subschemas are valid" and $keyword ne "prefixItems" || $error eq "item not permitted" and $keyword ne "items" || $error eq "item not permitted" || $error eq "additional item not permitted"
!ll&&!rl&&r
7220
not grep(($keyword eq $_), ("allOf", "anyOf", "if", "then", "else", "dependentSchemas", "contains", "propertyNames")) and $keyword ne "oneOf" || $error ne "no subschemas are valid" and $keyword ne "prefixItems" || $error eq "item not permitted"
!ll&&!rl&&r
6122
not grep(($keyword eq $_), ("allOf", "anyOf", "if", "then", "else", "dependentSchemas", "contains", "propertyNames")) and $keyword ne "oneOf" || $error ne "no subschemas are valid"
!ll&&!rl&&r
5123
$keyword ne "oneOf" or $error ne "no subschemas are valid"
l!l&&r!l&&!r
2211
$keyword ne "prefixItems" or $error eq "item not permitted"
l!l&&r!l&&!r
2111
$keyword ne "items" or $error eq "item not permitted" or $error eq "additional item not permitted"
l!l&&r!l&&!r
1912
$keyword ne "items" or $error eq "item not permitted"
l!l&&r!l&&!r
1813
$keyword ne "additionalItems" or $error eq "additional item not permitted"
l!l&&r!l&&!r
2000
not grep(($keyword eq $_), ("properties", "patternProperties")) or $error eq "property not permitted"
l!l&&r!l&&!r
1622
$keyword ne "additionalProperties" or $error eq "additional property not permitted"
l!l&&r!l&&!r
1611
$keyword ne "dependentRequired" or $error ne "not all dependencies are satisfied"
l!l&&r!l&&!r
1700
MC/DC0%0/17
!$keyword || !grep(($keyword eq $_), ('allOf', 'anyOf', 'if', 'then', 'else', 'dependentSchemas', 'contains', 'propertyNames')) && ($keyword ne 'oneOf' || $error ne 'no subschemas are valid') && ($keyword ne 'prefixItems' || $error eq 'item not permitted') && ($keyword ne 'items' || $error eq 'item not permitted' || $error eq 'additional item not permitted') && ($keyword ne 'additionalItems' || $error eq 'additional item not permitted') && (!grep(($keyword eq $_), ('properties', 'patternProperties')) || $error eq 'property not permitted') && ($keyword ne 'additionalProperties' || $error eq 'additional property not permitted') && ($keyword ne 'dependentRequired' || $error ne 'not all dependencies are satisfied')
too many conditions
184 not $keyword
185 or (
186 not grep $keyword eq $_, qw(allOf anyOf if then else dependentSchemas contains propertyNames)
187 and ($keyword ne 'oneOf' or $error ne 'no subschemas are valid')
188 and ($keyword ne 'prefixItems' or $error eq 'item not permitted')
189 and ($keyword ne 'items' or $error eq 'item not permitted' or $error eq 'additional item not permitted')
190 and ($keyword ne 'additionalItems' or $error eq 'additional item not permitted')
191 and (not grep $keyword eq $_, qw(properties patternProperties)
192 or $error eq 'property not permitted')
193 and ($keyword ne 'additionalProperties' or $error eq 'additional property not permitted'))
194 and ($keyword ne 'dependentRequired' or $error ne 'not all dependencies are satisfied')
195 );
196  
197 29 ▶ ++$instance_locations{$_->instance_location} if $keep;
Branch: 1 branch
BranchTrueFalseTotal
if $keep 17 12 29
198 29 ▶ ++$keyword_locations{$_->keyword_location} if $keep;
Branch: 1 branch
BranchTrueFalseTotal
if $keep 17 12 29
199  
200 29 $keep;
201 },
202 $self->errors;
203  
204 2 ▶ die 'uh oh, have no errors left to report' if not $self->valid and not @errors;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->valid or @errors 0 2 2
Condition33%1/3
$self->valid or @errors
l!l&&r!l&&!r
020
MC/DC0%0/2
$self->valid or @errors
$self->valid @errors
Truth table33%1/3
A or B
A= $self->validB= @errors
ABresult
1X1
011
000
205  
206 return +{
207 2 ▶ valid => $self->valid ? true : false,
Branch: 3 branches
BranchTrueFalseTotal
$self->valid ? : 0 2 2
$self->valid ? : 0 2 2
$formatted_annotations && $self->annotation_count ? : 0 0 0
Condition0%0/3
$formatted_annotations and $self->annotation_count
!ll&&!rl&&r
000
MC/DC0%0/2
$formatted_annotations and $self->annotation_count
$formatted_annotations $self->annotation_count
Truth table0%0/3
A and B
A= $formatted_annotationsB= $self->annotation_count
ABresult
0X0
100
111
208 $self->valid
209 ? ($formatted_annotations && $self->annotation_count ? (annotations => [ map $_->TO_JSON, $self->annotations ]) : ())
210 : (errors => [ map $_->TO_JSON, @errors ]),
211 };
212 }
213 elsif ($style eq 'data_only') {
214 2 ▶ return 'valid' if not $self->error_count;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->error_count 0 2 2
215 # Note: this output is going to be confusing when coming from a schema with a 'oneOf', 'not',
216 # etc. Perhaps generating the strings with indentation levels, as derived from a nested format,
217 # might be more readable.
218 2 return join("\n", uniqstr(map $_->stringify, $self->errors));
219 }
220  
221 # TODO: support detailed, verbose ?
222 0 croak 'unsupported output format';
223 }
224  
225 0 ▶sub count { $_[0]->valid ? $_[0]->annotation_count : $_[0]->error_count }
Subroutine count: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->valid ? : 0 0 0
226  
227 8 ▶sub combine ($self, $other, $swap) {
Subroutine combine: called CC=10 SCAR=25.0
Pod documented
228 8 ▶ croak 'wrong type for & operation' if not blessed($other) or not $other->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($other) and $other->isa(__PACKAGE__) 1 7 8
Condition66%2/3
builtin::blessed($other) and $other->isa(__PACKAGE__)
!ll&&!rl&&r
107
MC/DC50%1/2
builtin::blessed($other) and $other->isa(__PACKAGE__)
builtin::blessed($other) $other->isa(__PACKAGE__)
Truth table66%2/3
A and B
A= builtin::blessed($other)B= $other->isa(__PACKAGE__)
ABresult
0X0
100
111
229  
230 7 ▶ return $self if refaddr($other) == refaddr($self);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::refaddr($other) == builtin::refaddr($self) 1 6 7
231  
232 6 ▶ return ref($self)->new(
Branch: 1 branch
BranchTrueFalseTotal
$self->defaults || $other->defaults ? : 3 3 6
Condition53%7/13
$self->valid && $other->valid
!ll&&!rl&&r
204
$self->formatted_annotations || $other->formatted_annotations
l!l&&r!l&&!r
600
$self->defaults or $other->defaults
l!l&&r!l&&!r
303
$self->defaults // {}
l!l
30
$other->defaults // {}
l!l
30
MC/DC50%1/2
$self->valid && $other->valid
$self->valid $other->valid
MC/DC0%0/2
$self->formatted_annotations || $other->formatted_annotations
$self->formatted_annotations $other->formatted_annotations
MC/DC50%1/2
$self->defaults or $other->defaults
$self->defaults $other->defaults
MC/DC0%0/1
$self->defaults // {}
$self->defaults
MC/DC0%0/1
$other->defaults // {}
$other->defaults
Truth table66%2/3
A && B
A= $self->validB= $other->valid
ABresult
0X0
100
111
Truth table33%1/3
A || B
A= $self->formatted_annotationsB= $other->formatted_annotations
ABresult
1X1
011
000
Truth table66%2/3
A or B
A= $self->defaultsB= $other->defaults
ABresult
1X1
011
000
Truth table50%1/2
A
A= $self->defaults
Aresult
11
00
Truth table50%1/2
A
A= $other->defaults
Aresult
11
00
233 valid => $self->valid && $other->valid,
234 annotations => [
235 $self->annotations,
236 $other->annotations,
237 ],
238 errors => [
239 $self->errors,
240 $other->errors,
241 ],
242 output_format => $self->output_format,
243 formatted_annotations => $self->formatted_annotations || $other->formatted_annotations,
244 $self->defaults || $other->defaults
245 ? (defaults => +{ ($self->defaults//{})->%*, ($other->defaults//{})->%* })
246 : (),
247 );
248 }
249  
250 0 ▶sub stringify ($self) {
Subroutine stringify: not called CC=1 SCAR=6.9
Pod undocumented
251 0 return $self->format('data_only');
252 }
253  
254 25753 ▶sub TO_JSON ($self) {
Subroutine TO_JSON: called CC=2 SCAR=7.2
Pod documented
255 25753 ▶ croak 'cannot produce JSON output for data_only format' if $self->output_format eq 'data_only';
Branch: 1 branch
BranchTrueFalseTotal
if $self->output_format eq "data_only" 0 25753 25753
256 25753 $self->format($self->output_format);
257 }
258  
259 16870 ▶sub dump ($self) {
Subroutine dump: called CC=2 SCAR=7.1
Pod documented
260 16870 my $encoder = JSON::Schema::Modern::_JSON_BACKEND()->new
261 ->utf8(0)
262 ->convert_blessed(1)
263 ->canonical(1)
264 ->indent(1)
265 ->space_after(1);
266 16870 ▶ $encoder->indent_length(2) if $encoder->can('indent_length');
Branch: 1 branch
BranchTrueFalseTotal
if $encoder->can("indent_length") 16870 0 16870
267 16870 $encoder->encode($self);
268 }
269  
270 # turns the JSON pointers in instance_location, keyword_location into a URI fragments,
271 # for strict draft-201909 adherence
272 8 ▶sub _map_uris ($data) {
Subroutine _map_uris: called CC=1 SCAR=0.0
273 return +{
274 %$data,
275 8 map +($_ => Mojo::URL->new->fragment($data->{$_})->to_string),
276 qw(instanceLocation keywordLocation),
277 };
278 }
279  
280 46 1;
281  
282 __END__
« Modern/Vocabulary/FormatAssertion.pm ↑ Summary Modern/Utilities.pm »