Corvus.pm

filter: Statementstmt 100% 228 / 228 Branchbran 82.8% 53 / 64 Conditioncond 60.0% 18 / 30 MC/DCmcdc 26.3% 5 / 19 Subroutinesub 100% 76 / 76 Podpod 66.6% 2 / 3 totaltotal 90.9% 382 / 420 CC 59 SCAR 18.3
CC
59
Cov
93%
_options
28.1
_v92
10.0
assemble
8.1
CRAP 6.2
« Corvus/Regex/Unicode.pm ↑ Summary Corvus/ResultsCollector.pm »
1 package JSON::Schema::Corvus;
2  
3 5 ▶use 5.026;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use JSON::Schema::Corvus::Collecting ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use JSON::Schema::Corvus::Compiler ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use JSON::Schema::Corvus::Dialect ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use JSON::Schema::Corvus::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use JSON::Schema::Corvus::Json ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use JSON::Schema::Corvus::ResultsCollector;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 our $VERSION = 'v0.1.1';
14  
15 5 my %OPTIONS = map { $_ => 1 } qw(
16 default_dialect assert_format assert_format_in_legacy_drafts assert_content formats resolve_document base_uri
17 entry_point max_depth pattern_match_limit
18 );
19  
20 5 ▶sub _usage { JSON::Schema::Corvus::Error->throw_usage($_[0]) }
Subroutine _usage: called CC=1 SCAR=0.0
21  
22 # The compile options, checked, with their defaults.
23 52 ▶sub _options {
Subroutine _options: called CC=27 SCAR=33.4
24 52 my (%given) = @_;
25 52 for my $name (sort keys %given) {
26 37 ▶ _usage("unknown option $name") unless $OPTIONS{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless $OPTIONS{$name} 1 35 36
27 }
28 51 my %options = (
29 default_dialect => JSON::Schema::Corvus::Dialect::DRAFT202012,
30 assert_format => undef,
31 assert_format_in_legacy_drafts => 0,
32 assert_content => 1,
33 formats => {},
34 resolve_document => undef,
35 base_uri => undef,
36 entry_point => undef,
37 max_depth => 128,
38 pattern_match_limit => 1.0,
39 );
40 51 ▶ if (defined $given{default_dialect}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $given{"default_dialect"}) 6 44 50
41 $options{default_dialect} = JSON::Schema::Corvus::Dialect::dialect_by_name($given{default_dialect})
42 7 ▶ // _usage('default_dialect is not one of draft2019-09, draft2020-12, draft4, draft6, draft7');
Condition66%2/3
JSON::Schema::Corvus::Dialect::dialect_by_name($given{"default_dialect"}) // _usage("default_dialect is not one of draft2019-09, draft2020-12, draft4, draft6, draft7")
l!l&&r!l&&!r
510
MC/DC0%0/2
JSON::Schema::Corvus::Dialect::dialect_by_name($given{"default_dialect"}) // _usage("default_dialect is not one of draft2019-09, draft2020-12, draft4, draft6, draft7")
JSON::Schema::Corvus::Dialect::dialect_by_name($given{"default_dialect"}) _usage("default_dialect is not one of draft2019-09, draft2020-12, draft4, draft6, draft7")
Truth table33%1/3
A // B
A= JSON::Schema::Corvus::Dialect::dialect_by_name($given{"default_dialect"})B= _usage("default_dialect is not one of draft2019-09, draft2020-12, draft4, draft6, draft7")
ABresult
1X1
011
000
43 }
44 50 ▶ $options{assert_format} = $given{assert_format} ? 1 : 0 if defined $given{assert_format};
Branch: 2 branches
BranchTrueFalseTotal
if defined $given{"assert_format"} 6 43 49
$given{'assert_format'} ? : 6 0 6
45 50 for my $flag (qw(assert_format_in_legacy_drafts assert_content)) {
46 99 ▶ $options{$flag} = $given{$flag} ? 1 : 0 if defined $given{$flag};
Branch: 2 branches
BranchTrueFalseTotal
if defined $given{$flag} 2 96 98
$given{$flag} ? : 1 1 2
47 }
48 50 for my $text (qw(base_uri entry_point)) {
49 99 ▶ $options{$text} = "$given{$text}" if defined $given{$text};
Branch: 1 branch
BranchTrueFalseTotal
if defined $given{$text} 2 96 98
50 }
51 50 ▶ if (defined $given{max_depth}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $given{"max_depth"}) 2 47 49
52 3 ▶ _usage('max_depth is not a whole number from 1') unless $given{max_depth} =~ /\A[0-9]+\z/ && $given{max_depth} > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $given{"max_depth"} =~ /\A[0-9]+\z/u and $given{"max_depth"} > 0 1 1 2
Condition66%2/3
$given{"max_depth"} =~ /\A[0-9]+\z/u and $given{"max_depth"} > 0
!ll&&!rl&&r
101
MC/DC50%1/2
$given{"max_depth"} =~ /\A[0-9]+\z/u and $given{"max_depth"} > 0
$given{"max_depth"} =~ /\A[0-9]+\z/u $given{"max_depth"} > 0
Truth table66%2/3
A and B
A= $given{"max_depth"} =~ /\A[0-9]+\z/uB= $given{"max_depth"} > 0
ABresult
0X0
100
111
53 2 $options{max_depth} = 0 + $given{max_depth};
54 }
55 49 ▶ if (exists $given{pattern_match_limit}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $given{"pattern_match_limit"}) 3 45 48
56 # Seconds, as the other packages have it; undef, 0 or less turns the limit off.
57 4 my $seconds = $given{pattern_match_limit};
58 4 ▶ _usage('pattern_match_limit is not a number of seconds')
Branch: 1 branch
BranchTrueFalseTotal
if defined $seconds and not JSON::Schema::Corvus::Json::is_number($seconds) and not $seconds =~ /\A[0-9.eE+-]+\z/u 0 3 3
Condition50%3/6
defined $seconds and not JSON::Schema::Corvus::Json::is_number($seconds) and not $seconds =~ /\A[0-9.eE+-]+\z/u
!ll&&!rl&&r
300
defined $seconds and not JSON::Schema::Corvus::Json::is_number($seconds)
!ll&&!rl&&r
120
MC/DC0%0/3
defined $seconds and not JSON::Schema::Corvus::Json::is_number($seconds) and not $seconds =~ /\A[0-9.eE+-]+\z/u
defined $seconds not JSON::Schema::Corvus::Json::is_number($seconds) not $seconds =~ /\A[0-9.eE+-]+\z/u
Truth table50%2/4
A and not(B) and not(C)
A= defined $secondsB= not JSON::Schema::Corvus::Json::is_number($seconds)C= not $seconds =~ /\A[0-9.eE+-]+\z/u
ABCresult
0XX0
10X0
1100
1111
59 if defined $seconds && !JSON::Schema::Corvus::Json::is_number($seconds) && $seconds !~ /\A[0-9.eE+-]+\z/;
60 4 ▶ $options{pattern_match_limit} = defined $seconds && $seconds > 0 ? 0 + $seconds : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $seconds && $seconds > 0 ? : 1 2 3
Condition100%3/3
defined $seconds and $seconds > 0
!ll&&!rl&&r
111
MC/DC100%2/2
defined $seconds and $seconds > 0
defined $seconds $seconds > 0
Truth table100%3/3
A and B
A= defined $secondsB= $seconds > 0
ABresult
0X0
100
111
61 }
62 49 ▶ if (defined $given{formats}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $given{"formats"}) 6 42 48
63 7 ▶ _usage('formats is not a hash of code references') unless ref $given{formats} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $given{"formats"} eq "HASH" 0 6 6
64 7 for my $name (keys %{ $given{formats} }) {
65 7 ▶ _usage("format $name is not a code reference") unless ref $given{formats}{$name} eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $given{"formats"}{$name} eq "CODE" 1 5 6
66 }
67 6 $options{formats} = { %{ $given{formats} } };
68 }
69 48 ▶ if (defined $given{resolve_document}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $given{"resolve_document"}) 7 40 47
70 8 ▶ _usage('resolve_document is not a code reference') unless ref $given{resolve_document} eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $given{"resolve_document"} eq "CODE" 0 7 7
71 8 $options{resolve_document} = $given{resolve_document};
72 }
73 48 return \%options;
74 }
75  
76 46 ▶sub _is_data {
Subroutine _is_data: called CC=4 SCAR=14.3
77 46 my ($value) = @_;
78 46 ▶ return 1 if ref $value;
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 7 38 45
79 5 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
80 39 ▶ return defined &builtin::is_bool && builtin::is_bool($value) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined &builtin::is_bool && builtin::is_bool($value) ? : 0 38 38
Condition33%1/3
defined &builtin::is_bool and builtin::is_bool($value)
!ll&&!rl&&r
0380
MC/DC0%0/2
defined &builtin::is_bool and builtin::is_bool($value)
defined &builtin::is_bool builtin::is_bool($value)
Truth table33%1/3
A and B
A= defined &builtin::is_boolB= builtin::is_bool($value)
ABresult
0X0
100
111
81 }
82  
83 # A schema as a JSON value: JSON text parsed (keeping the order of names), or Perl data converted.
84 46 ▶sub _schema_value {
Subroutine _schema_value: called CC=2 SCAR=6.9
85 46 my ($schema) = @_;
86 46 ▶ return JSON::Schema::Corvus::Json::from_data($schema) if _is_data($schema);
Branch: 1 branch
BranchTrueFalseTotal
if _is_data($schema) 7 38 45
87 39 return JSON::Schema::Corvus::Json::decode($schema, 1);
88 }
89  
90 50 ▶sub compile {
Subroutine compile: called CC=1 SCAR=0.0
Pod documented
91 50 my ($class, $schema, %options) = @_;
92 50 my $options = _options(%options);
93 46 my $program = JSON::Schema::Corvus::Compiler->compile(_schema_value($schema), $options);
94 39 return JSON::Schema::Corvus::Validator->_new($program);
95 }
96  
97 3 ▶sub compile_uri {
Subroutine compile_uri: called CC=2 SCAR=7.0
Pod documented
98 3 my ($class, $uri, %options) = @_;
99 3 ▶ _usage('the URI is undef') unless defined $uri;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uri 0 2 2
100 3 my $program = JSON::Schema::Corvus::Compiler->compile_from_uri("$uri", _options(%options));
101 3 return JSON::Schema::Corvus::Validator->_new($program);
102 }
103  
104 # The JSON text (UTF-8 bytes) that Perl data is validated as.
105 26 ▶sub encode_json {
Subroutine encode_json: called CC=1 SCAR=0.0
Pod undocumented
106 26 my ($data) = @_;
107 26 my $text = JSON::Schema::Corvus::Json::encode(JSON::Schema::Corvus::Json::from_data($data));
108 21 utf8::encode($text);
109 21 return $text;
110 }
111  
112 package JSON::Schema::Corvus::Validator;
113  
114 5 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
115 5 ▶use Symbol ();
Subroutine BEGIN: called CC=1 SCAR=0.0
116  
117 5 my $PACKAGES = 0;
118  
119 41 ▶sub _new {
Subroutine _new: called CC=1 SCAR=0.0
120 41 my ($class, $program) = @_;
121 41 my $self = bless { program => $program, collecting => undef }, $class;
122 41 $self->_generate;
123 41 return $self;
124 }
125  
126 # Generates the validator's Perl and compiles it into a package of its own, which DESTROY deletes.
127 41 ▶sub _generate {
Subroutine _generate: called CC=2 SCAR=6.9
128 41 my ($self) = @_;
129 41 require JSON::Schema::Corvus::CodeGen;
130 41 require JSON::Schema::Corvus::Runtime;
131 41 my $g = JSON::Schema::Corvus::CodeGen->new($self->{program})->generate;
132 41 my $package = 'JSON::Schema::Corvus::Generated::G' . ++$PACKAGES;
133 41 my $source = $self->{source} = assemble($g, $package);
134 41 my $validate = do {
135 5 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
136 5 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
137 41 local $@;
138 3 ▶ my $code = eval $source;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
139 41 ▶ die JSON::Schema::Corvus::Error::Compilation->_new("The schema produced invalid code: $@") unless $code;
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 40 40
140 41 $code;
141 };
142 {
143 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
144 41 ${"${package}::F"} = $g->{custom_formats};
145 }
146 41 $self->{package} = $package;
147 41 $self->{validate} = $validate;
148 }
149  
150 # The package's source: its subs, the constants (after the subs, as a dispatch table names them), and the sub that
151 # validates, which keeps the dynamic scope and the depth count of one evaluation when the program has them.
152 57 ▶sub assemble {
Subroutine assemble: called CC=8 SCAR=20.9
153 57 my ($g, $package) = @_;
154 57 my @s = ("package $package;", 'use strict;', 'no warnings;', 'our ($F, @DS, $depth, $MAXDEPTH);');
155 41 ▶ push @s, 'our (' . join(', ', map { $_->[0] } @{ $g->{constants} }) . ');' if @{ $g->{constants} };
Branch: 1 branch
BranchTrueFalseTotal
if @{$g->{"constants"};} 8 32 40
156 41 push @s, map { $_->[1] } @{ $g->{functions} };
157 42 push @s, "$_->[0] = $_->[1];" for @{ $g->{constants} };
158 41 ▶ push @s, "\$MAXDEPTH = $g->{max_depth};" if $g->{uses_depth};
Branch: 1 branch
BranchTrueFalseTotal
if $g->{"uses_depth"} 2 55 57
159 41 ▶ if ($g->{uses_dynamic_scope} || $g->{uses_depth}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($g->{'uses_dynamic_scope'} or $g->{'uses_depth'}) { } 2 39 41
Condition66%2/3
$g->{"uses_dynamic_scope"} or $g->{"uses_depth"}
l!l&&r!l&&!r
0139
MC/DC50%1/2
$g->{"uses_dynamic_scope"} or $g->{"uses_depth"}
$g->{"uses_dynamic_scope"} $g->{"uses_depth"}
Truth table66%2/3
A or B
A= $g->{"uses_dynamic_scope"}B= $g->{"uses_depth"}
ABresult
1X1
011
000
160 2 push @s, 'sub validate {';
161 2 ▶ push @s, " local \@DS = ($g->{root_resource});" if $g->{uses_dynamic_scope};
Branch: 1 branch
BranchTrueFalseTotal
if $g->{"uses_dynamic_scope"} 0 1 1
162 2 ▶ push @s, ' local $depth = 0;' if $g->{uses_depth};
Branch: 1 branch
BranchTrueFalseTotal
if $g->{"uses_depth"} 1 0 1
163 2 push @s, " return $g->{root}(\$_[0]);", '}', '\&validate;';
164 }
165 else {
166 40 push @s, "\\&$g->{root};";
167 }
168 41 return join "\n", @s, '';
169 }
170  
171 58 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=7.2
172 41 my ($self) = @_;
173 41 ▶ Symbol::delete_package($self->{package}) if $self->{package};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"package"} 40 0 40
174 }
175  
176 # The generated Perl of the validator.
177 1 ▶sub source { $_[0]{source} }
Subroutine source: called CC=1 SCAR=0.0
178  
179 # The program for evaluation with a collector, with its annotations (built on first use).
180 6 ▶sub _collecting {
Subroutine _collecting: called CC=2 SCAR=7.0
181 6 my ($self) = @_;
182 6 ▶ return $self->{collecting} //= do {
Condition66%2/3
$self->{"collecting"} //= do { JSON::Schema::Corvus::Compiler::resolve_annotations($self->{"program"}); my $p = $self->{"program"}; +{"nodes", $p->{"nodes"}, "root", $p->{"root"}, "uses_dynamic_scope", $p->{"uses_dynamic_scope"}, "max_depth", $p->{"options"}{"max_depth"}, "formats", $p->{"options"}{"formats"}, "pattern_match_limit", $p->{"options"}{"pattern_match_limit"}} }
l!l&&r!l&&!r
230
MC/DC0%0/2
$self->{"collecting"} //= do { JSON::Schema::Corvus::Compiler::resolve_annotations($self->{"program"}); my $p = $self->{"program"}; +{"nodes", $p->{"nodes"}, "root", $p->{"root"}, "uses_dynamic_scope", $p->{"uses_dynamic_scope"}, "max_depth", $p->{"options"}{"max_depth"}, "formats", $p->{"options"}{"formats"}, "pattern_match_limit", $p->{"options"}{"pattern_match_limit"}} }
$self->{"collecting"} do { JSON::Schema::Corvus::Compiler::resolve_annotations($self->{"program"}); my $p = $self->{"program"}; +{"nodes", $p->{"nodes"}, "root", $p->{"root"}, "uses_dynamic_scope", $p->{"uses_dynamic_scope"}, "max_depth", $p->{"options"}{"max_depth"}, "formats", $p->{"options"}{"formats"}, "pattern_match_limit", $p->{"options"}{"pattern_match_limit"}} }
Truth table66%2/3
A //= B
A= $self->{"collecting"}B= do { JSON::Schema::Corvus::Compiler::resolve_annotations($self->{"program"}); my $p = $self->{"program"}; +{"nodes", $p->{"nodes"}, "root", $p->{"root"}, "uses_dynamic_scope", $p->{"uses_dynamic_scope"}, "max_depth", $p->{"options"}{"max_depth"}, "formats", $p->{"options"}{"formats"}, "pattern_match_limit", $p->{"options"}{"pattern_match_limit"}} }
ABresult
1X1
011
000
183 4 JSON::Schema::Corvus::Compiler::resolve_annotations($self->{program});
184 4 my $p = $self->{program};
185 {
186 nodes => $p->{nodes},
187 root => $p->{root},
188 uses_dynamic_scope => $p->{uses_dynamic_scope},
189 max_depth => $p->{options}{max_depth},
190 formats => $p->{options}{formats},
191 pattern_match_limit => $p->{options}{pattern_match_limit},
192 4 };
193 };
194 }
195  
196 68 ▶sub _self {
Subroutine _self: called CC=3 SCAR=11.1
197 68 ▶ JSON::Schema::Corvus::Error->throw_usage('expected a JSON::Schema::Corvus::Validator')
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($_[0]) and $_[0]->isa("JSON::Schema::Corvus::Validator") 1 66 67
Condition66%2/3
builtin::blessed($_[0]) and $_[0]->isa("JSON::Schema::Corvus::Validator")
!ll&&!rl&&r
1066
MC/DC50%1/2
builtin::blessed($_[0]) and $_[0]->isa("JSON::Schema::Corvus::Validator")
builtin::blessed($_[0]) $_[0]->isa("JSON::Schema::Corvus::Validator")
Truth table66%2/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa("JSON::Schema::Corvus::Validator")
ABresult
0X0
100
111
198 unless Scalar::Util::blessed($_[0]) && $_[0]->isa('JSON::Schema::Corvus::Validator');
199 }
200  
201 64 ▶sub _validate {
Subroutine _validate: called CC=2 SCAR=6.9
202 64 my ($self, $value) = @_;
203 64 ▶ return $self->{validate}->($value) ? 1 : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'validate'}->($value) ? : 31 28 59
204 }
205  
206 60 ▶sub is_valid_json {
Subroutine is_valid_json: called CC=1 SCAR=0.0
207 60 my ($self, $json) = @_;
208 60 _self($self);
209 59 return $self->_validate(JSON::Schema::Corvus::Json::decode($json));
210 }
211  
212 7 ▶sub is_valid {
Subroutine is_valid: called CC=1 SCAR=0.0
213 7 my ($self, $data) = @_;
214 7 _self($self);
215 7 return $self->_validate(JSON::Schema::Corvus::Json::from_data($data));
216 }
217  
218 3 ▶sub is_valid_document {
Subroutine is_valid_document: called CC=1 SCAR=0.0
219 3 my ($self, $document) = @_;
220 3 _self($self);
221 3 return $self->_validate($document->{value});
222 }
223  
224 6 ▶sub _evaluate {
Subroutine _evaluate: called CC=4 SCAR=14.6
225 6 my ($self, $value, $collector) = @_;
226 6 ▶ JSON::Schema::Corvus::Error->throw_usage('expected a JSON::Schema::Corvus::ResultsCollector')
Branch: 1 branch
BranchTrueFalseTotal
unless ref $collector and $collector->isa("JSON::Schema::Corvus::ResultsCollector") 0 5 5
Condition33%1/3
ref $collector and $collector->isa("JSON::Schema::Corvus::ResultsCollector")
!ll&&!rl&&r
005
MC/DC0%0/2
ref $collector and $collector->isa("JSON::Schema::Corvus::ResultsCollector")
ref $collector $collector->isa("JSON::Schema::Corvus::ResultsCollector")
Truth table33%1/3
A and B
A= ref $collectorB= $collector->isa("JSON::Schema::Corvus::ResultsCollector")
ABresult
0X0
100
111
227 unless ref $collector && $collector->isa('JSON::Schema::Corvus::ResultsCollector');
228 6 $collector->_reset;
229 6 ▶ return JSON::Schema::Corvus::Collecting::evaluate_with_collector($self->_collecting, $value, $collector) ? 1 : '';
Branch: 1 branch
BranchTrueFalseTotal
JSON::Schema::Corvus::Collecting::evaluate_with_collector($self->_collecting, $value, $collector) ? : 3 2 5
230 }
231  
232 4 ▶sub evaluate_json {
Subroutine evaluate_json: called CC=1 SCAR=0.0
233 4 my ($self, $json, $collector) = @_;
234 4 return $self->_evaluate(JSON::Schema::Corvus::Json::decode($json, 1), $collector);
235 }
236  
237 2 ▶sub evaluate {
Subroutine evaluate: called CC=1 SCAR=0.0
238 2 my ($self, $data, $collector) = @_;
239 2 return $self->_evaluate(JSON::Schema::Corvus::Json::from_data($data), $collector);
240 }
241  
242 2 ▶sub evaluate_document {
Subroutine evaluate_document: called CC=1 SCAR=0.0
243 2 my ($self, $document, $collector) = @_;
244 2 return $self->_evaluate($document->{value}, $collector);
245 }
246  
247 package JSON::Schema::Corvus::Document;
248  
249 # JSON parsed once, for an instance validated more than once.
250 3 ▶sub parse {
Subroutine parse: called CC=1 SCAR=0.0
251 3 my ($class, $json) = @_;
252 3 return bless { value => JSON::Schema::Corvus::Json::decode($json, 1) }, $class;
253 }
254  
255 2 ▶sub from_data {
Subroutine from_data: called CC=1 SCAR=0.0
256 2 my ($class, $data) = @_;
257 2 return bless { value => JSON::Schema::Corvus::Json::from_data($data) }, $class;
258 }
259  
260 5 1;
261  
262 __END__
« Corvus/Regex/Unicode.pm ↑ Summary Corvus/ResultsCollector.pm »