blib/lib/YAML/PP/Schema.pm

filter: Statementstmt 94.7% 254 / 268 Branchbran 88.1% 111 / 126 Conditioncond 69.7% 30 / 43 MC/DCmcdc 50.0% 12 / 24 Subroutinesub 94.1% 32 / 34 Podpod 0.0% 0 / 16 totaltotal 85.9% 439 / 511 CC 88 SCAR 24.5
CC
88
Cov
90%
new
25.8
load_scalar
16.0
add_representer
15.1
CRAP 11.6
« blib/lib/YAML/PP/Highlight.pm ↑ Summary blib/lib/YAML/PP/Schema/Perl.pm »
1 50 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 50 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package YAML::PP::Schema;
4  
5 50 our $VERSION = 'v0.43.0'; # VERSION
6  
7 50 ▶use YAML::PP::Common qw/ YAML_PLAIN_SCALAR_STYLE /;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 50 ▶use Carp qw/ croak /;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 50 ▶use Scalar::Util qw/ blessed /;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 772 ▶sub new {
Subroutine new: called CC=15 SCAR=32.5
Pod undocumented
13 772 my ($class, %args) = @_;
14  
15 772 my $yaml_version = delete $args{yaml_version};
16 772 my $bool = delete $args{boolean};
17 772 ▶ $bool = 'perl' unless defined $bool;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bool 0 772 772
18 772 ▶ if (keys %args) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %args) 0 772 772
19 0 die "Unexpected arguments: " . join ', ', sort keys %args;
20 }
21 772 my $true;
22 my $false;
23 772 my @bool_class;
24 772 my @bools = split m/,/, $bool;
25 772 for my $b (@bools) {
26 765 ▶ if ($b eq '*') {
Branch: 4 branches
BranchTrueFalseTotal
if ($b eq '*') { } 0 765 765
elsif ($b eq 'JSON::PP') { } 595 170 765
elsif ($b eq 'boolean') { } 0 170 170
elsif ($b eq 'perl' or $b eq 'perl_experimental') { } 170 0 170
27 0 push @bool_class, ('boolean', 'JSON::PP::Boolean');
28 0 last;
29 }
30 elsif ($b eq 'JSON::PP') {
31 595 require JSON::PP;
32 595 ▶ $true ||= \&_bool_jsonpp_true;
Condition50%1/2
$true ||= \&YAML::PP::Schema::_bool_jsonpp_true
l!l
0595
MC/DC0%0/1
$true ||= \&YAML::PP::Schema::_bool_jsonpp_true
$true
Truth table50%1/2
A
A= $true
Aresult
11
00
33 595 ▶ $false ||= \&_bool_jsonpp_false;
Condition50%1/2
$false ||= \&YAML::PP::Schema::_bool_jsonpp_false
l!l
0595
MC/DC0%0/1
$false ||= \&YAML::PP::Schema::_bool_jsonpp_false
$false
Truth table50%1/2
A
A= $false
Aresult
11
00
34 595 push @bool_class, 'JSON::PP::Boolean';
35 }
36 elsif ($b eq 'boolean') {
37 0 require boolean;
38 0 ▶ $true ||= \&_bool_booleanpm_true;
Condition0%0/2
$true ||= \&YAML::PP::Schema::_bool_booleanpm_true
l!l
00
MC/DC0%0/1
$true ||= \&YAML::PP::Schema::_bool_booleanpm_true
$true
Truth table0%0/2
A
A= $true
Aresult
11
00
39 0 ▶ $false ||= \&_bool_booleanpm_false;
Condition0%0/2
$false ||= \&YAML::PP::Schema::_bool_booleanpm_false
l!l
00
MC/DC0%0/1
$false ||= \&YAML::PP::Schema::_bool_booleanpm_false
$false
Truth table0%0/2
A
A= $false
Aresult
11
00
40 0 push @bool_class, 'boolean';
41 }
42 ▶ elsif ($b eq 'perl' or $b eq 'perl_experimental') {
Condition66%2/3
$b eq "perl" or $b eq "perl_experimental"
l!l&&r!l&&!r
16820
MC/DC0%0/2
$b eq "perl" or $b eq "perl_experimental"
$b eq "perl" $b eq "perl_experimental"
Truth table66%2/3
A or B
A= $b eq "perl"B= $b eq "perl_experimental"
ABresult
1X1
011
000
43 170 push @bool_class, 'perl';
44 }
45 else {
46 0 die "Invalid value for 'boolean': '$b'. Allowed: ('perl', 'boolean', 'JSON::PP')";
47 }
48 }
49 # Ensure booleans are resolved
50 772 ▶ $true ||= \&_bool_perl_true;
Condition100%2/2
$true ||= \&YAML::PP::Schema::_bool_perl_true
l!l
595177
MC/DC100%1/1
$true ||= \&YAML::PP::Schema::_bool_perl_true
$true
Truth table100%2/2
A
A= $true
Aresult
11
00
51 772 ▶ $false ||= \&_bool_perl_false;
Condition100%2/2
$false ||= \&YAML::PP::Schema::_bool_perl_false
l!l
595177
MC/DC100%1/1
$false ||= \&YAML::PP::Schema::_bool_perl_false
$false
Truth table100%2/2
A
A= $false
Aresult
11
00
52  
53 772 my %representers = (
54 'undef' => undef,
55 flags => [],
56 equals => {},
57 regex => [],
58 class_equals => {},
59 class_matches => [],
60 class_isa => [],
61 scalarref => undef,
62 refref => undef,
63 coderef => undef,
64 glob => undef,
65 tied_equals => {},
66 bool => undef,
67 );
68 772 my $self = bless {
69 yaml_version => $yaml_version,
70 resolvers => {},
71 representers => \%representers,
72 true => $true,
73 false => $false,
74 bool_class => \@bool_class,
75 }, $class;
76 772 return $self;
77 }
78  
79 52812 ▶sub resolvers { return $_[0]->{resolvers} }
Subroutine resolvers: called CC=1 SCAR=0.0
Pod undocumented
80 25077 ▶sub representers { return $_[0]->{representers} }
Subroutine representers: called CC=1 SCAR=0.0
Pod undocumented
81  
82 2293 ▶sub true { return $_[0]->{true} }
Subroutine true: called CC=1 SCAR=0.0
Pod undocumented
83 2293 ▶sub false { return $_[0]->{false} }
Subroutine false: called CC=1 SCAR=0.0
Pod undocumented
84 1604 ▶sub bool_class { return @{ $_[0]->{bool_class} } ? $_[0]->{bool_class} : undef }
Subroutine bool_class: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@{$_[0]{'bool_class'};} ? : 1597 7 1604
85 790 ▶sub yaml_version { return $_[0]->{yaml_version} }
Subroutine yaml_version: called CC=1 SCAR=0.0
Pod undocumented
86  
87 50 my %LOADED_SCHEMA = (
88 JSON => 1,
89 );
90 my %DEFAULT_SCHEMA = (
91 453 ▶ '1.2' => sub { require YAML::PP::Schema::Core; return 'YAML::PP::Schema::Core' },
Subroutine __ANON__: called CC=1 SCAR=0.0
92 4 ▶ '1.1' => sub { require YAML::PP::Schema::YAML1_1; return 'YAML::PP::Schema::YAML1_1' },
Subroutine __ANON__: called CC=1 SCAR=0.0
93 50 );
94 my %AVAILABLE_SCHEMAS = (
95 286 ▶ 'Core' => sub { require YAML::PP::Schema::Core; return 'YAML::PP::Schema::Core' },
Subroutine __ANON__: called CC=1 SCAR=0.0
96 22 ▶ 'JSON' => sub { require YAML::PP::Schema::JSON; return 'YAML::PP::Schema::JSON' },
Subroutine __ANON__: called CC=1 SCAR=0.0
97 3 ▶ 'Failsafe' => sub { require YAML::PP::Schema::Failsafe; return 'YAML::PP::Schema::Failsafe' },
Subroutine __ANON__: called CC=1 SCAR=0.0
98 1 ▶ 'Merge' => sub { require YAML::PP::Schema::Merge; return 'YAML::PP::Schema::Merge' },
Subroutine __ANON__: called CC=1 SCAR=0.0
99 18 ▶ 'Perl' => sub { require YAML::PP::Schema::Perl; return 'YAML::PP::Schema::Perl' },
Subroutine __ANON__: called CC=1 SCAR=0.0
100 50 );
101  
102 772 ▶sub load_subschemas {
Subroutine load_subschemas: called CC=13 SCAR=25.7
Pod undocumented
103 772 my ($self, @schemas) = @_;
104 772 my $yaml_version = $self->yaml_version;
105 772 my $i = 0;
106 772 ▶ while ($i < @schemas) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @schemas) 1391 769 2160
107 1391 my $item = $schemas[ $i ];
108 1391 $i++;
109 1391 my $class;
110 1391 ▶ if ($item eq '+') {
Branch: 3 branches
BranchTrueFalseTotal
if ($item eq '+') { } 457 934 1391
elsif ($AVAILABLE_SCHEMAS{$item}) { } 330 604 934
elsif (builtin::blessed($item)) { } 10 594 604
111 457 my $code = $DEFAULT_SCHEMA{ $yaml_version };
112 457 $class = $code->();
113 }
114 elsif ($AVAILABLE_SCHEMAS{ $item }) {
115 330 my $code = $AVAILABLE_SCHEMAS{ $item };
116 330 $class = $code->();
117 }
118 elsif (blessed($item)) {
119 10 $item->register(
120 schema => $self,
121 );
122 10 next;
123 }
124 1381 my @options;
125 1381 ▶ while ($i < @schemas
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @schemas and $schemas[$i] =~ /^[^A-Za-z]/ || $schemas[$i] =~ /^[a-zA-Z0-9]+=/) 14 1381 1395
Condition100%6/6
$i < @schemas and $schemas[$i] =~ /^[^A-Za-z]/ || $schemas[$i] =~ /^[a-zA-Z0-9]+=/
!ll&&!rl&&r
76261914
$schemas[$i] =~ /^[^A-Za-z]/ or $schemas[$i] =~ /^[a-zA-Z0-9]+=/
l!l&&r!l&&!r
59619
MC/DC100%3/3
$i < @schemas and $schemas[$i] =~ /^[^A-Za-z]/ || $schemas[$i] =~ /^[a-zA-Z0-9]+=/
$i < @schemas $schemas[$i] =~ /^[^A-Za-z]/ $schemas[$i] =~ /^[a-zA-Z0-9]+=/
Truth table100%4/4
A and B or C
A= $i < @schemasB= $schemas[$i] =~ /^[^A-Za-z]/C= $schemas[$i] =~ /^[a-zA-Z0-9]+=/
ABCresult
0XX0
1000
11X1
1011
126 and (
127 $schemas[ $i ] =~ m/^[^A-Za-z]/
128 or
129 $schemas[ $i ] =~ m/^[a-zA-Z0-9]+=/
130 )
131 ) {
132 14 push @options, $schemas[ $i ];
133 14 $i++;
134 }
135  
136 1381 ▶ unless ($class) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class) 594 787 1381
137 594 require Module::Load;
138 594 ▶ if ($item =~ m/^\:(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item =~ /^\:(.*)/) { } 2 592 594
139 2 $class = "$1";
140 2 ▶ unless ($class =~ m/\A[A-Za-z0-9_:]+\z/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class =~ /\A[A-Za-z0-9_:]+\z/) 1 1 2
141 1 die "Module name '$class' is invalid";
142 }
143 1 Module::Load::load $class;
144 }
145 else {
146 592 $class = "YAML::PP::Schema::$item";
147 592 ▶ unless ($class =~ m/\A[A-Za-z0-9_:]+\z/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class =~ /\A[A-Za-z0-9_:]+\z/) 1 591 592
148 1 die "Module name '$class' is invalid";
149 }
150 591 ▶ $LOADED_SCHEMA{ $item } ||= Module::Load::load $class;
Condition33%1/3
$LOADED_SCHEMA{$item} ||= $class->Module::Load::load
l!l&&r!l&&!r
00591
MC/DC0%0/2
$LOADED_SCHEMA{$item} ||= $class->Module::Load::load
$LOADED_SCHEMA{$item} $class->Module::Load::load
Truth table33%1/3
A ||= B
A= $LOADED_SCHEMA{$item}B= $class->Module::Load::load
ABresult
1X1
011
000
151 }
152 }
153 $class->register(
154 1379 schema => $self,
155 options => \@options,
156 );
157  
158 }
159 }
160  
161 21820 ▶sub add_resolver {
Subroutine add_resolver: called CC=13 SCAR=25.7
Pod undocumented
162 21820 my ($self, %args) = @_;
163 21820 my $tag = $args{tag};
164 21820 my $rule = $args{match};
165 21820 my $resolvers = $self->resolvers;
166 21820 my ($type, @rule) = @$rule;
167 21820 my $implicit = $args{implicit};
168 21820 ▶ $implicit = 1 unless defined $implicit;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $implicit 21052 768 21820
169 21820 my $resolver_list = [];
170 21820 ▶ if ($tag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag) 21820 0 21820
171 21820 ▶ if (ref $tag eq 'Regexp') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $tag eq 'Regexp') { } 681 21139 21820
172 681 ▶ my $res = $resolvers->{tags} ||= [];
Condition100%2/2
$resolvers->{"tags"} ||= []
l!l
68613
MC/DC100%1/1
$resolvers->{"tags"} ||= []
$resolvers->{"tags"}
Truth table100%2/2
A
A= $resolvers->{"tags"}
Aresult
11
00
173 681 push @$res, [ $tag, {} ];
174 681 push @$resolver_list, $res->[-1]->[1];
175 }
176 else {
177 21139 ▶ my $res = $resolvers->{tag}->{ $tag } ||= {};
Condition100%2/2
$resolvers->{"tag"}{$tag} ||= {}
l!l
172493890
MC/DC100%1/1
$resolvers->{"tag"}{$tag} ||= {}
$resolvers->{"tag"}{$tag}
Truth table100%2/2
A
A= $resolvers->{"tag"}{$tag}
Aresult
11
00
178 21139 push @$resolver_list, $res;
179 }
180 }
181 21820 ▶ if ($implicit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($implicit) 21073 747 21820
182 21073 ▶ push @$resolver_list, $resolvers->{value} ||= {};
Condition100%2/2
$resolvers->{"value"} ||= {}
l!l
20305768
MC/DC100%1/1
$resolvers->{"value"} ||= {}
$resolvers->{"value"}
Truth table100%2/2
A
A= $resolvers->{"value"}
Aresult
11
00
183 }
184 21820 for my $res (@$resolver_list) {
185 42893 ▶ if ($type eq 'equals') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'equals') { } 34554 8339 42893
elsif ($type eq 'regex') { } 6066 2273 8339
elsif ($type eq 'all') { } 2273 0 2273
186 34554 my ($match, $value) = @rule;
187 34554 ▶ unless (exists $res->{equals}->{ $match }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $res->{"equals"}{$match}) 34554 0 34554
188 34554 $res->{equals}->{ $match } = $value;
189 }
190 34554 next;
191 }
192 elsif ($type eq 'regex') {
193 6066 my ($match, $value) = @rule;
194 6066 push @{ $res->{regex} }, [ $match => $value ];
195 }
196 elsif ($type eq 'all') {
197 2273 my ($value) = @rule;
198 2273 $res->{all} = $value;
199 }
200 }
201 }
202  
203 669 ▶sub add_sequence_resolver {
Subroutine add_sequence_resolver: called CC=1 SCAR=0.0
Pod undocumented
204 669 my ($self, %args) = @_;
205 669 return $self->add_collection_resolver(sequence => %args);
206 }
207  
208 874 ▶sub add_mapping_resolver {
Subroutine add_mapping_resolver: called CC=1 SCAR=0.0
Pod undocumented
209 874 my ($self, %args) = @_;
210 874 return $self->add_collection_resolver(mapping => %args);
211 }
212  
213 1543 ▶sub add_collection_resolver {
Subroutine add_collection_resolver: called CC=6 SCAR=18.2
Pod undocumented
214 1543 my ($self, $type, %args) = @_;
215 1543 my $tag = $args{tag};
216 1543 my $implicit = $args{implicit};
217 1543 my $resolvers = $self->resolvers;
218  
219 1543 ▶ if ($tag and ref $tag eq 'Regexp') {
Branch: 2 branches
BranchTrueFalseTotal
if ($tag and ref $tag eq 'Regexp') { } 1394 149 1543
elsif ($tag) { } 149 0 149
Condition66%2/3
$tag and ref $tag eq "Regexp"
!ll&&!rl&&r
01491394
MC/DC50%1/2
$tag and ref $tag eq "Regexp"
$tag ref $tag eq "Regexp"
Truth table66%2/3
A and B
A= $tagB= ref $tag eq "Regexp"
ABresult
0X0
100
111
220 1394 ▶ my $res = $resolvers->{ $type }->{tags} ||= [];
Condition100%2/2
$resolvers->{$type}{"tags"} ||= []
l!l
1681226
MC/DC100%1/1
$resolvers->{$type}{"tags"} ||= []
$resolvers->{$type}{"tags"}
Truth table100%2/2
A
A= $resolvers->{$type}{"tags"}
Aresult
11
00
221 push @$res, [ $tag, {
222 on_create => $args{on_create},
223 on_data => $args{on_data},
224 1394 } ];
225 }
226 elsif ($tag) {
227 my $res = $resolvers->{ $type }->{tag}->{ $tag } ||= {
228 on_create => $args{on_create},
229 on_data => $args{on_data},
230 149 ▶ };
Condition50%1/2
$resolvers->{$type}{"tag"}{$tag} ||= {"on_create", $args{"on_create"}, "on_data", $args{"on_data"}}
l!l
0149
MC/DC0%0/1
$resolvers->{$type}{"tag"}{$tag} ||= {"on_create", $args{"on_create"}, "on_data", $args{"on_data"}}
$resolvers->{$type}{"tag"}{$tag}
Truth table50%1/2
A
A= $resolvers->{$type}{"tag"}{$tag}
Aresult
11
00
231 }
232 }
233  
234 21226 ▶sub add_representer {
Subroutine add_representer: called CC=15 SCAR=27.2
Pod undocumented
235 21226 my ($self, %args) = @_;
236  
237 21226 my $representers = $self->representers;
238 21226 ▶ if (my $flags = $args{flags}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $flags = $args{"flags"}) 1530 19696 21226
239 1530 my $rep = $representers->{flags};
240 1530 push @$rep, \%args;
241 1530 return;
242 }
243 19696 ▶ if (my $regex = $args{regex}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $regex = $args{"regex"}) 766 18930 19696
244 766 my $rep = $representers->{regex};
245 766 push @$rep, \%args;
246 766 return;
247 }
248 18930 ▶ if (my $regex = $args{class_matches}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $regex = $args{"class_matches"}) 26 18904 18930
249 26 my $rep = $representers->{class_matches};
250 26 push @$rep, [ $args{class_matches}, $args{code} ];
251 26 return;
252 }
253 18904 ▶ if (my $bool = $args{bool} and $] >= 5.036000) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $bool = $args{"bool"} and $] >= "5.036") 165 18739 18904
Condition66%2/3
my $bool = $args{"bool"} and $] >= "5.036"
!ll&&!rl&&r
187390165
MC/DC50%1/2
my $bool = $args{"bool"} and $] >= "5.036"
my $bool = $args{"bool"} $] >= "5.036"
Truth table66%2/3
A and B
A= my $bool = $args{"bool"}B= $] >= "5.036"
ABresult
0X0
100
111
254 $representers->{bool} = {
255 code => $args{code},
256 165 };
257 165 return;
258 }
259 18739 ▶ if (my $class_equals = $args{class_equals}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $class_equals = $args{"class_equals"}) 595 18144 18739
260 595 my $rep = $representers->{class_equals};
261 $rep->{ $class_equals } = {
262 code => $args{code},
263 595 };
264 595 return;
265 }
266 18144 ▶ if (my $class_isa = $args{class_isa}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $class_isa = $args{"class_isa"}) 2 18142 18144
267 2 my $rep = $representers->{class_isa};
268 2 push @$rep, [ $args{class_isa}, $args{code} ];
269 2 return;
270 }
271 18142 ▶ if (my $tied_equals = $args{tied_equals}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tied_equals = $args{"tied_equals"}) 0 18142 18142
272 0 my $rep = $representers->{tied_equals};
273 $rep->{ $tied_equals } = {
274 code => $args{code},
275 0 };
276 0 return;
277 }
278 18142 ▶ if (defined(my $equals = $args{equals})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $equals = $args{"equals"})) 17281 861 18142
279 17281 my $rep = $representers->{equals};
280 $rep->{ $equals } = {
281 code => $args{code},
282 17281 };
283 17281 return;
284 }
285 861 ▶ if (defined(my $scalarref = $args{scalarref})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $scalarref = $args{"scalarref"})) 24 837 861
286 $representers->{scalarref} = {
287 code => $args{code},
288 24 };
289 24 return;
290 }
291 837 ▶ if (defined(my $refref = $args{refref})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $refref = $args{"refref"})) 24 813 837
292 $representers->{refref} = {
293 code => $args{code},
294 24 };
295 24 return;
296 }
297 813 ▶ if (defined(my $coderef = $args{coderef})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $coderef = $args{"coderef"})) 24 789 813
298 $representers->{coderef} = {
299 code => $args{code},
300 24 };
301 24 return;
302 }
303 789 ▶ if (defined(my $glob = $args{glob})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $glob = $args{"glob"})) 24 765 789
304 $representers->{glob} = {
305 code => $args{code},
306 24 };
307 24 return;
308 }
309 765 ▶ if (my $undef = $args{undefined}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $undef = $args{"undefined"}) 765 0 765
310 765 $representers->{undef} = $undef;
311 765 return;
312 }
313 }
314  
315 26588 ▶sub load_scalar {
Subroutine load_scalar: called CC=16 SCAR=27.7
Pod undocumented
316 26588 my ($self, $constructor, $event) = @_;
317 26588 my $tag = $event->{tag};
318 26588 my $value = $event->{value};
319  
320 26588 my $resolvers = $self->resolvers;
321 26588 my $res;
322 26588 ▶ if ($tag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag) { } 697 25891 26588
323 697 ▶ if ($tag eq '!') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq "!") 7 690 697
324 7 return $value;
325 }
326 690 $res = $resolvers->{tag}->{ $tag };
327 690 ▶ if (not $res and my $matches = $resolvers->{tags}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $res and my $matches = $resolvers->{"tags"}) 56 634 690
Condition66%2/3
not $res and my $matches = $resolvers->{"tags"}
!ll&&!rl&&r
634056
MC/DC50%1/2
not $res and my $matches = $resolvers->{"tags"}
not $res my $matches = $resolvers->{"tags"}
Truth table66%2/3
not(A) and B
A= not $resB= my $matches = $resolvers->{"tags"}
ABresult
0X0
100
111
328 56 for my $match (@$matches) {
329 76 my ($re, $rule) = @$match;
330 76 ▶ if ($tag =~ $re) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ /$re/) 56 20 76
331 56 $res = $rule;
332 56 last;
333 }
334 }
335 }
336 #unless ($res) {
337 # croak "Unknown tag '$tag'. Use schema 'Catchall' to ignore unknown tags";
338 #}
339 }
340 else {
341 25891 $res = $resolvers->{value};
342 25891 ▶ if ($event->{style} ne YAML_PLAIN_SCALAR_STYLE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($event->{"style"} ne 1) 2658 23233 25891
343 2658 return $value;
344 }
345 }
346  
347 23923 ▶ if (my $equals = $res->{equals}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $equals = $res->{"equals"}) 23303 620 23923
348 23303 ▶ if (exists $equals->{ $value }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $equals->{$value}) 426 22877 23303
349 426 my $res = $equals->{ $value };
350 426 ▶ if (ref $res eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $res eq "CODE") 82 344 426
351 82 return $res->($constructor, $event);
352 }
353 344 return $res;
354 }
355 }
356 23497 ▶ if (my $regex = $res->{regex}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $regex = $res->{"regex"}) 22864 633 23497
357 22864 for my $item (@$regex) {
358 61704 my ($re, $sub) = @$item;
359 61704 my @matches = $value =~ $re;
360 61704 ▶ if (@matches) {
Branch: 1 branch
BranchTrueFalseTotal
if (@matches) 9875 51829 61704
361 9875 return $sub->($constructor, $event, \@matches);
362 }
363 }
364 }
365 13622 ▶ if (my $catch_all = $res->{all}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $catch_all = $res->{"all"}) 13595 27 13622
366 13595 ▶ if (ref $catch_all eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $catch_all eq "CODE") 13595 0 13595
367 13595 return $catch_all->($constructor, $event);
368 }
369 0 return $catch_all;
370 }
371 27 return $value;
372 }
373  
374 1230 ▶sub create_sequence {
Subroutine create_sequence: called CC=8 SCAR=20.8
Pod undocumented
375 1230 my ($self, $constructor, $event) = @_;
376 1230 my $tag = $event->{tag};
377 1230 my $data = [];
378 1230 my $on_data;
379  
380 1230 my $resolvers = $self->resolvers->{sequence};
381 1230 ▶ if ($tag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag) 35 1195 1230
382 35 ▶ if (my $equals = $resolvers->{tag}->{ $tag }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $equals = $resolvers->{"tag"}{$tag}) 6 29 35
383 6 my $on_create = $equals->{on_create};
384 6 $on_data = $equals->{on_data};
385 6 ▶ $on_create and $data = $on_create->($constructor, $event);
Branch: 1 branch
BranchTrueFalseTotal
$on_create and $data = &$on_create($constructor, $event) 6 0 6
386 6 return ($data, $on_data);
387 }
388 29 ▶ if (my $matches = $resolvers->{tags}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $matches = $resolvers->{"tags"}) 29 0 29
389 29 for my $match (@$matches) {
390 31 my ($re, $actions) = @$match;
391 31 my $on_create = $actions->{on_create};
392 31 ▶ if ($tag =~ $re) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ /$re/) 29 2 31
393 29 $on_data = $actions->{on_data};
394 29 ▶ $on_create and $data = $on_create->($constructor, $event);
Branch: 1 branch
BranchTrueFalseTotal
$on_create and $data = &$on_create($constructor, $event) 15 14 29
395 29 return ($data, $on_data);
396 }
397 }
398 }
399 #croak "Unknown tag '$tag'. Use schema 'Catchall' to ignore unknown tags";
400 }
401  
402 1195 return ($data, $on_data);
403 }
404  
405 1631 ▶sub create_mapping {
Subroutine create_mapping: called CC=8 SCAR=20.8
Pod undocumented
406 1631 my ($self, $constructor, $event) = @_;
407 1631 my $tag = $event->{tag};
408 1631 my $data = {};
409 1631 my $on_data;
410  
411 1631 my $resolvers = $self->resolvers->{mapping};
412 1631 ▶ if ($tag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag) 83 1548 1631
413 83 ▶ if (my $equals = $resolvers->{tag}->{ $tag }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $equals = $resolvers->{"tag"}{$tag}) 24 59 83
414 24 my $on_create = $equals->{on_create};
415 24 $on_data = $equals->{on_data};
416 24 ▶ $on_create and $data = $on_create->($constructor, $event);
Branch: 1 branch
BranchTrueFalseTotal
$on_create and $data = &$on_create($constructor, $event) 23 1 24
417 24 return ($data, $on_data);
418 }
419 59 ▶ if (my $matches = $resolvers->{tags}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $matches = $resolvers->{"tags"}) 59 0 59
420 59 for my $match (@$matches) {
421 146 my ($re, $actions) = @$match;
422 146 my $on_create = $actions->{on_create};
423 146 ▶ if ($tag =~ $re) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ /$re/) 59 87 146
424 59 $on_data = $actions->{on_data};
425 59 ▶ $on_create and $data = $on_create->($constructor, $event);
Branch: 1 branch
BranchTrueFalseTotal
$on_create and $data = &$on_create($constructor, $event) 31 28 59
426 59 return ($data, $on_data);
427 }
428 }
429 }
430 #croak "Unknown tag '$tag'. Use schema 'Catchall' to ignore unknown tags";
431 }
432  
433 1548 return ($data, $on_data);
434 }
435  
436 31 ▶sub _bool_jsonpp_true { JSON::PP::true() }
Subroutine _bool_jsonpp_true: called CC=1 SCAR=0.0
437  
438 0 ▶sub _bool_booleanpm_true { boolean::true() }
Subroutine _bool_booleanpm_true: not called CC=1 SCAR=6.9
439  
440 16 ▶sub _bool_perl_true { !!1 }
Subroutine _bool_perl_true: called CC=1 SCAR=0.0
441  
442 33 ▶sub _bool_jsonpp_false { JSON::PP::false() }
Subroutine _bool_jsonpp_false: called CC=1 SCAR=0.0
443  
444 0 ▶sub _bool_booleanpm_false { boolean::false() }
Subroutine _bool_booleanpm_false: not called CC=1 SCAR=6.9
445  
446 2 ▶sub _bool_perl_false { !!0 }
Subroutine _bool_perl_false: called CC=1 SCAR=0.0
447  
448 50 1;
449  
450 __END__
« blib/lib/YAML/PP/Highlight.pm ↑ Summary blib/lib/YAML/PP/Schema/Perl.pm »