JSON/Version.pm

filter: Statementstmt 94.4% 221 / 234 Branchbran 84.9% 124 / 146 Conditioncond 97.0% 66 / 68 MC/DCmcdc 95.2% 40 / 42 Subroutinesub 100% 30 / 30 Podpod 100% 25 / 25 totaltotal 92.8% 506 / 545 CC 101 SCAR 21.5
CC
101
Cov
92%
check_list
26.0
check_map
21.2
exversion
7.0
CRAP 8.6
↑ Summary JSON.pm »
1 package Test::CPAN::Meta::JSON::Version;
2  
3 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 15 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 $VERSION = '0.16';
8  
9 #----------------------------------------------------------------------------
10  
11 =head1 NAME
12  
13 Test::CPAN::Meta::JSON::Version - Validate CPAN META data against the specification
14  
15 =head1 SYNOPSIS
16  
17 use Test::CPAN::Meta::JSON::Version;
18  
19 =head1 DESCRIPTION
20  
21 This module was written to ensure that a META.json file, provided with a
22 standard distribution uploaded to CPAN, meets the specifications that are
23 slowly being introduced to module uploads, via the use of
24 L<ExtUtils::MakeMaker>, L<Module::Build> and L<Module::Install>.
25  
26 This module is meant to be used together with L<Test::CPAN::Meta::JSON>, however
27 the code is self contained enough that you can access it directly.
28  
29 See L<CPAN::Meta> for further details of the CPAN Meta Specification.
30  
31 =head1 ABSTRACT
32  
33 Validation of META.json data against the CPAN Meta Specification.
34  
35 =cut
36  
37 #----------------------------------------------------------------------------
38  
39 #############################################################################
40 #Specification Definitions #
41 #############################################################################
42  
43 15 my $spec_error = "Missing validation action in specification. "
44 . "Must be one of 'map', 'list', 'lazylist' or 'value'";
45  
46 15 my %known_specs = (
47 '1.4' => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
48 '1.3' => 'http://module-build.sourceforge.net/META-spec-v1.3.html',
49 '1.2' => 'http://module-build.sourceforge.net/META-spec-v1.2.html',
50 '1.1' => 'http://module-build.sourceforge.net/META-spec-v1.1.html',
51 '1.0' => 'http://module-build.sourceforge.net/META-spec-v1.0.html'
52 );
53 15 my %known_urls = map {$known_specs{$_} => $_} keys %known_specs;
54  
55 15 my $module_map1 = { 'map' => { ':key' => { name => \&module, value => \&exversion } } };
56 15 my $module_map2 = { 'map' => { ':key' => { name => \&module, value => \&version } } };
57 15 my $no_index_1_3 = {
58 'map' => { file => { list => { value => \&string } },
59 directory => { list => { value => \&string } },
60 'package' => { list => { value => \&string } },
61 namespace => { list => { value => \&string } },
62 }
63 };
64 15 my $no_index_1_2 = {
65 'map' => { file => { list => { value => \&string } },
66 dir => { list => { value => \&string } },
67 'package' => { list => { value => \&string } },
68 namespace => { list => { value => \&string } },
69 }
70 };
71 15 my $no_index_1_1 = {
72 'map' => { ':key' => { name => \&keyword, list => { value => \&string } },
73 }
74 };
75  
76 15 my $prereq_map = {
77 'map' => {
78 ':key' => {
79 name => \&phase,
80 'map' => {
81 ':key' => {
82 name => \&relation,
83 %$module_map1
84 }
85 }
86 }
87 }
88 };
89  
90 15 my %definitions = (
91 '2' => {
92 # REQUIRED
93 'abstract' => { mandatory => 1, value => \&string },
94 'author' => { mandatory => 1, lazylist => { value => \&string } },
95 'dynamic_config' => { mandatory => 1, value => \&boolean },
96 'generated_by' => { mandatory => 1, value => \&string },
97 'license' => { mandatory => 1, list => { value => \&license } },
98 'meta-spec' => {
99 mandatory => 1,
100 'map' => {
101 version => { mandatory => 1, value => \&version},
102 url => { value => \&url }
103 }
104 },
105 'name' => { mandatory => 1, value => \&string },
106 'release_status' => { mandatory => 1, value => \&release_status },
107 'version' => { mandatory => 1, value => \&version },
108  
109 # OPTIONAL
110 'description' => { value => \&string },
111 'keywords' => { lazylist => { value => \&string } },
112 'no_index' => $no_index_1_3,
113 'optional_features' => {
114 'map' => {
115 ':key' => {
116 name => \&identifier,
117 'map' => {
118 description => { value => \&string },
119 prereqs => $prereq_map,
120 }
121 }
122 }
123 },
124 'prereqs' => $prereq_map,
125 'provides' => {
126 'map' => {
127 ':key' => {
128 name => \&module,
129 'map' => {
130 file => { mandatory => 1, value => \&file },
131 version => { value => \&version } } } }
132 },
133 'resources' => {
134 'map' => {
135 license => { list => { value => \&url } },
136 homepage => { value => \&url },
137 bugtracker => {
138 'map' => {
139 web => { value => \&url },
140 mailto => { value => \&string},
141 }},
142 repository => {
143 'map' => {
144 web => { value => \&url },
145 url => { value => \&url },
146 type => { value => \&string },
147 }},
148 ':key' => { value => \&string, name => \&custom_2 },
149 }
150 },
151  
152 # CUSTOM -- additional user defined key/value pairs
153 # note we can only validate the key name, as the structure is user defined
154 ':key' => { name => \&custom_2, value => \&anything },
155 },
156  
157 '1.4' => {
158 'meta-spec' => { mandatory => 1, 'map' => { version => { mandatory => 1, value => \&version},
159 url => { mandatory => 1, value => \&urlspec } } },
160  
161 'name' => { mandatory => 1, value => \&string },
162 'version' => { mandatory => 1, value => \&version },
163 'abstract' => { mandatory => 1, value => \&string },
164 'author' => { mandatory => 1, list => { value => \&string } },
165 'license' => { mandatory => 1, value => \&license },
166 'generated_by' => { mandatory => 1, value => \&string },
167  
168 'distribution_type' => { value => \&string },
169 'dynamic_config' => { value => \&boolean },
170  
171 'requires' => $module_map1,
172 'recommends' => $module_map1,
173 'build_requires' => $module_map1,
174 'configure_requires' => $module_map1,
175 'conflicts' => $module_map2,
176  
177 'optional_features' => {
178 'map' => {
179 ':key' => { name => \&identifier,
180 'map' => { description => { value => \&string },
181 requires_packages => { value => \&string },
182 requires_os => { value => \&string },
183 excludes_os => { value => \&string },
184 requires => $module_map1,
185 recommends => $module_map1,
186 build_requires => $module_map1,
187 conflicts => $module_map2,
188 }
189 }
190 }
191 },
192  
193 'provides' => {
194 'map' => { ':key' => { name => \&module,
195 'map' => { file => { mandatory => 1, value => \&file },
196 version => { value => \&version } } } }
197 },
198  
199 'no_index' => $no_index_1_3,
200 'private' => $no_index_1_3,
201  
202 'keywords' => { list => { value => \&string } },
203  
204 'resources' => {
205 'map' => { license => { value => \&url },
206 homepage => { value => \&url },
207 bugtracker => { value => \&url },
208 repository => { value => \&url },
209 ':key' => { value => \&string, name => \&resource },
210 }
211 },
212  
213 # additional user defined key/value pairs
214 # note we can only validate the key name, as the structure is user defined
215 ':key' => { name => \&keyword, value => \&anything },
216 },
217  
218 '1.3' => {
219 'meta-spec' => { mandatory => 1, 'map' => { version => { mandatory => 1, value => \&version},
220 url => { mandatory => 1, value => \&urlspec } } },
221  
222 'name' => { mandatory => 1, value => \&string },
223 'version' => { mandatory => 1, value => \&version },
224 'abstract' => { mandatory => 1, value => \&string },
225 'author' => { mandatory => 1, list => { value => \&string } },
226 'license' => { mandatory => 1, value => \&license },
227 'generated_by' => { mandatory => 1, value => \&string },
228  
229 'distribution_type' => { value => \&string },
230 'dynamic_config' => { value => \&boolean },
231  
232 'requires' => $module_map1,
233 'recommends' => $module_map1,
234 'build_requires' => $module_map1,
235 'conflicts' => $module_map2,
236  
237 'optional_features' => {
238 'map' => {
239 ':key' => { name => \&identifier,
240 'map' => { description => { value => \&string },
241 requires_packages => { value => \&string },
242 requires_os => { value => \&string },
243 excludes_os => { value => \&string },
244 requires => $module_map1,
245 recommends => $module_map1,
246 build_requires => $module_map1,
247 conflicts => $module_map2,
248 }
249 }
250 }
251 },
252  
253 'provides' => {
254 'map' => { ':key' => { name => \&module,
255 'map' => { file => { mandatory => 1, value => \&file },
256 version => { value => \&version } } } }
257 },
258  
259 'no_index' => $no_index_1_3,
260 'private' => $no_index_1_3,
261  
262 'keywords' => { list => { value => \&string } },
263  
264 'resources' => {
265 'map' => { license => { value => \&url },
266 homepage => { value => \&url },
267 bugtracker => { value => \&url },
268 repository => { value => \&url },
269 ':key' => { value => \&string, name => \&resource },
270 }
271 },
272  
273 # additional user defined key/value pairs
274 # note we can only validate the key name, as the structure is user defined
275 ':key' => { name => \&keyword, value => \&anything },
276 },
277  
278 # v1.2 is misleading, it seems to assume that a number of fields where created
279 # within v1.1, when they were created within v1.2. This may have been an
280 # original mistake, and that a v1.1 was retro fitted into the timeline, when
281 # v1.2 was originally slated as v1.1. But I could be wrong ;)
282 '1.2' => {
283 'meta-spec' => { mandatory => 1, 'map' => { version => { mandatory => 1, value => \&version},
284 url => { mandatory => 1, value => \&urlspec } } },
285  
286 'name' => { mandatory => 1, value => \&string },
287 'version' => { mandatory => 1, value => \&version },
288 'license' => { mandatory => 1, value => \&license },
289 'generated_by' => { mandatory => 1, value => \&string },
290 'author' => { mandatory => 1, list => { value => \&string } },
291 'abstract' => { mandatory => 1, value => \&string },
292  
293 'distribution_type' => { value => \&string },
294 'dynamic_config' => { value => \&boolean },
295  
296 'keywords' => { list => { value => \&string } },
297  
298 'private' => $no_index_1_2,
299 '$no_index' => $no_index_1_2,
300  
301 'requires' => $module_map1,
302 'recommends' => $module_map1,
303 'build_requires' => $module_map1,
304 'conflicts' => $module_map2,
305  
306 'optional_features' => {
307 'map' => {
308 ':key' => { name => \&identifier,
309 'map' => { description => { value => \&string },
310 requires_packages => { value => \&string },
311 requires_os => { value => \&string },
312 excludes_os => { value => \&string },
313 requires => $module_map1,
314 recommends => $module_map1,
315 build_requires => $module_map1,
316 conflicts => $module_map2,
317 }
318 }
319 }
320 },
321  
322 'provides' => {
323 'map' => { ':key' => { name => \&module,
324 'map' => { file => { mandatory => 1, value => \&file },
325 version => { value => \&version } } } }
326 },
327  
328 'resources' => {
329 'map' => { license => { value => \&url },
330 homepage => { value => \&url },
331 bugtracker => { value => \&url },
332 repository => { value => \&url },
333 ':key' => { value => \&string, name => \&resource },
334 }
335 },
336  
337 # additional user defined key/value pairs
338 # note we can only validate the key name, as the structure is user defined
339 ':key' => { name => \&keyword, value => \&anything },
340 },
341  
342 # note that the 1.1 spec doesn't specify optional or mandatory fields, what
343 # appears below is assumed from later specifications.
344 '1.1' => {
345 'name' => { mandatory => 1, value => \&string },
346 'version' => { mandatory => 1, value => \&version },
347 'license' => { mandatory => 1, value => \&license },
348 'license_uri' => { mandatory => 0, value => \&url },
349 'generated_by' => { mandatory => 1, value => \&string },
350  
351 'distribution_type' => { value => \&string },
352 'dynamic_config' => { value => \&boolean },
353  
354 'private' => $no_index_1_1,
355  
356 'requires' => $module_map1,
357 'recommends' => $module_map1,
358 'build_requires' => $module_map1,
359 'conflicts' => $module_map2,
360  
361 # additional user defined key/value pairs
362 # note we can only validate the key name, as the structure is user defined
363 ':key' => { name => \&keyword, value => \&anything },
364 },
365  
366 # note that the 1.0 spec doesn't specify optional or mandatory fields, what
367 # appears below is assumed from later specifications.
368 '1.0' => {
369 'name' => { mandatory => 1, value => \&string },
370 'version' => { mandatory => 1, value => \&version },
371 'license' => { mandatory => 1, value => \&license },
372 'generated_by' => { mandatory => 1, value => \&string },
373  
374 'distribution_type' => { value => \&string },
375 'dynamic_config' => { value => \&boolean },
376  
377 'requires' => $module_map1,
378 'recommends' => $module_map1,
379 'build_requires' => $module_map1,
380 'conflicts' => $module_map2,
381  
382 # additional user defined key/value pairs
383 # note we can only validate the key name, as the structure is user defined
384 ':key' => { name => \&keyword, value => \&anything },
385 },
386 );
387  
388 # aliases
389 15 $definitions{'2.0'} = $definitions{'2'};
390  
391 #############################################################################
392 #Code #
393 #############################################################################
394  
395 =head1 CLASS CONSTRUCTOR
396  
397 =over
398  
399 =item * new( data => $data [, spec => $version] )
400  
401 The constructor must be passed a valid data structure.
402  
403 Optionally you may also provide a specification version. This version is then
404 use to ensure that the given data structure meets the respective
405 specification definition. If no version is provided the module will attempt to
406 deduce the appropriate specification version from the data structure itself.
407  
408 =back
409  
410 =cut
411  
412 74 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
413 74 my ($class,%hash) = @_;
414  
415 # create an attributes hash
416 my $atts = {
417 'spec' => $hash{spec},
418 'data' => $hash{data},
419 74 };
420  
421 # create the object
422 74 my $self = bless $atts, $class;
423 }
424  
425 =head1 METHODS
426  
427 =head2 Main Methods
428  
429 =over
430  
431 =item * parse()
432  
433 Using the given data structure provided with the constructor, attempts to
434 parse and validate according to the appropriate specification definition.
435  
436 Returns 1 if any errors found, otherwise returns 0.
437  
438 =item * errors()
439  
440 Returns a list of the errors found during parsing.
441  
442 =back
443  
444 =cut
445  
446 68 ▶sub parse {
Subroutine parse: called CC=5 SCAR=16.1
Pod documented
447 68 my $self = shift;
448 68 my $data = $self->{data};
449  
450 68 ▶ unless($self->{spec}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"spec"}) 33 35 68
451 33 ▶ $self->{spec} = $data->{'meta-spec'} && $data->{'meta-spec'}{'version'} ? $data->{'meta-spec'}{'version'} : '2';
Branch: 1 branch
BranchTrueFalseTotal
$data->{'meta-spec'} && $data->{'meta-spec'}{'version'} ? : 29 4 33
Condition100%3/3
$data->{"meta-spec"} and $data->{"meta-spec"}{"version"}
!ll&&!rl&&r
2229
MC/DC100%2/2
$data->{"meta-spec"} and $data->{"meta-spec"}{"version"}
$data->{"meta-spec"} $data->{"meta-spec"}{"version"}
Truth table100%3/3
A and B
A= $data->{"meta-spec"}B= $data->{"meta-spec"}{"version"}
ABresult
0X0
100
111
452 }
453  
454 68 $self->check_map($definitions{$self->{spec}},$data);
455 68 ▶ return defined $self->{errors} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'errors'} ? : 31 37 68
456 }
457  
458 90 ▶sub errors {
Subroutine errors: called CC=2 SCAR=6.9
Pod documented
459 90 my $self = shift;
460 90 ▶ return () unless($self->{errors});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"errors"} 29 61 90
461 61 return @{$self->{errors}};
462 }
463  
464 =head2 Check Methods
465  
466 =over
467  
468 =item * check_map($spec,$data)
469  
470 Checks whether a map (or hash) part of the data structure conforms to the
471 appropriate specification definition.
472  
473 =item * check_lazylist($spec,$data)
474  
475 If it's a string, make it into a list and check the list
476  
477 =item * check_list($spec,$data)
478  
479 Checks whether a list (or array) part of the data structure conforms to
480 the appropriate specification definition.
481  
482 =back
483  
484 =cut
485  
486 710 ▶sub check_map {
Subroutine check_map: called CC=18 SCAR=30.6
Pod documented
487 710 my ($self,$spec,$data) = @_;
488  
489 710 ▶ if(ref($spec) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $spec ne "HASH") 1 709 710
490 1 $self->_error( "Unknown META.yml specification, cannot validate." );
491 1 return;
492 }
493  
494 709 ▶ if(ref($data) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data ne "HASH") 8 701 709
495 8 $self->_error( "Expected a map structure from data string or file." );
496 8 return;
497 }
498  
499 701 for my $key (keys %$spec) {
500 2272 ▶ next unless($spec->{$key}->{mandatory});
Branch: 1 branch
BranchTrueFalseTotal
unless $spec->{$key}{"mandatory"} 1601 671 2272
501 671 ▶ next if(defined $data->{$key});
Branch: 1 branch
BranchTrueFalseTotal
if defined $data->{$key} 653 18 671
502 18 push @{$self->{stack}}, $key;
503 18 $self->_error( "Missing mandatory field, '$key'" );
504 18 pop @{$self->{stack}};
505 }
506  
507 701 for my $key (keys %$data) {
508 2286 push @{$self->{stack}}, $key;
509 2286 ▶ if($spec->{$key}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($spec->{$key}) { } 1232 1054 2286
elsif ($spec->{':key'}) { } 1054 0 1054
510 1232 ▶ if($spec->{$key}{value}) {
Branch: 4 branches
BranchTrueFalseTotal
if ($spec->{$key}{'value'}) { } 712 520 1232
elsif ($spec->{$key}{'map'}) { } 346 174 520
elsif ($spec->{$key}{'list'}) { } 128 46 174
elsif ($spec->{$key}{'lazylist'}) { } 46 0 46
511 712 $spec->{$key}{value}->($self,$key,$data->{$key});
512 } elsif($spec->{$key}{'map'}) {
513 346 $self->check_map($spec->{$key}{'map'},$data->{$key});
514 } elsif($spec->{$key}{'list'}) {
515 128 $self->check_list($spec->{$key}{'list'},$data->{$key});
516 } elsif($spec->{$key}{'lazylist'}) {
517 46 $self->check_lazylist($spec->{$key}{'lazylist'},$data->{$key});
518 } else {
519 0 $self->_error( "$spec_error for '$key'" );
520 }
521  
522 } elsif ($spec->{':key'}) {
523 1054 $spec->{':key'}{name}->($self,$key,$key);
524 1054 ▶ if($spec->{':key'}{value}) {
Branch: 5 branches
BranchTrueFalseTotal
if ($spec->{':key'}{'value'}) { } 770 284 1054
elsif ($spec->{':key'}{'map'}) { } 284 0 284
elsif ($spec->{':key'}{'list'}) { } 0 0 0
elsif ($spec->{':key'}{'lazylist'}) { } 0 0 0
elsif (not $spec->{':key'}{'name'}) { } 0 0 0
525 770 $spec->{':key'}{value}->($self,$key,$data->{$key});
526 } elsif($spec->{':key'}{'map'}) {
527 284 $self->check_map($spec->{':key'}{'map'},$data->{$key});
528 } elsif($spec->{':key'}{'list'}) {
529 0 $self->check_list($spec->{':key'}{'list'},$data->{$key});
530 } elsif($spec->{':key'}{'lazylist'}) {
531 0 $self->check_list($spec->{':key'}{'lazylist'},$data->{$key});
532 } elsif(!$spec->{':key'}{name}) {
533 0 $self->_error( "$spec_error for ':key'" );
534 }
535  
536 } else {
537 0 $self->_error( "Unknown key, '$key', found in map structure" );
538 }
539 2280 pop @{$self->{stack}};
540 }
541 }
542  
543 46 ▶sub check_lazylist {
Subroutine check_lazylist: called CC=3 SCAR=13.3
Pod documented
544 46 my ($self,$spec,$data) = @_;
545  
546 46 ▶ if ( defined $data && ! ref($data) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data and not ref $data) 0 46 46
Condition33%1/3
defined $data and not ref $data
!ll&&!rl&&r
0460
MC/DC0%0/2
defined $data and not ref $data
defined $data not ref $data
Truth table33%1/3
A and not(B)
A= defined $dataB= not ref $data
ABresult
0X0
100
111
547 0 $data = [ $data ];
548 }
549  
550 46 $self->check_list($spec,$data);
551 }
552  
553 186 ▶sub check_list {
Subroutine check_list: called CC=10 SCAR=32.6
Pod documented
554 186 my ($self,$spec,$data) = @_;
555  
556 186 ▶ if(ref($data) ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data ne "ARRAY") 10 176 186
557 10 $self->_error( "Expected a list structure" );
558 10 return;
559 }
560  
561 176 ▶ if(defined $spec->{mandatory}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $spec->{"mandatory"}) 0 176 176
562 0 ▶ if(!defined $data->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data->[0]) 0 0 0
563 0 $self->_error( "Missing entries from mandatory list" );
564 }
565 }
566  
567 176 for my $value (@$data) {
568 281 push @{$self->{stack}}, $value;
569 281 ▶ if(defined $spec->{value}) {
Branch: 5 branches
BranchTrueFalseTotal
if (defined $spec->{'value'}) { } 281 0 281
elsif (defined $spec->{'map'}) { } 0 0 0
elsif (defined $spec->{'list'}) { } 0 0 0
elsif (defined $spec->{'lazylist'}) { } 0 0 0
elsif ($spec->{':key'}) { } 0 0 0
570 281 $spec->{value}->($self,'list',$value);
571 } elsif(defined $spec->{'map'}) {
572 0 $self->check_map($spec->{'map'},$value);
573 } elsif(defined $spec->{'list'}) {
574 0 $self->check_list($spec->{'list'},$value);
575 } elsif(defined $spec->{'lazylist'}) {
576 0 $self->check_lazylist($spec->{'lazylist'},$value);
577  
578 } elsif ($spec->{':key'}) {
579 0 $self->check_map($spec,$value);
580  
581 } else {
582 0 $self->_error( "$spec_error associated with '$self->{stack}[-2]'" );
583 }
584 269 pop @{$self->{stack}};
585 }
586 }
587  
588 =head2 Validator Methods
589  
590 =over
591  
592 =item * url($self,$key,$value)
593  
594 Validates that a given value is in an acceptable URL format
595  
596 =item * urlspec($self,$key,$value)
597  
598 Validates that the URL to a META.yml specification is a known one.
599  
600 =item * string_or_undef($self,$key,$value)
601  
602 Validates that the value is either a string or an undef value. Bit of a
603 catchall function for parts of the data structure that are completely user
604 defined.
605  
606 =item * string($self,$key,$value)
607  
608 Validates that a string exists for the given key.
609  
610 =item * file($self,$key,$value)
611  
612 Validate that a file is passed for the given key. This may be made more
613 thorough in the future. For now it acts like \&string.
614  
615 =item * exversion($self,$key,$value)
616  
617 Validates a list of versions, e.g. '<= 5, >=2, ==3, !=4, >1, <6, 0'.
618  
619 =item * version($self,$key,$value)
620  
621 Validates a single version string. Versions of the type '5.8.8' and '0.00_00'
622 are both valid. A leading 'v' like 'v1.2.3' is also valid.
623  
624 =item * boolean($self,$key,$value)
625  
626 Validates for a boolean value. Currently these values are '1', '0', 'true',
627 'false', however the latter 2 may be removed.
628  
629 =item * license($self,$key,$value)
630  
631 Validates that a value is given for the license. Returns 1 if an known license
632 type, or 2 if a value is given but the license type is not a recommended one.
633  
634 =item * resource($self,$key,$value)
635  
636 Validates that the given key is in CamelCase, to indicate a user defined
637 keyword.
638  
639 =item * keyword($self,$key,$value)
640  
641 Validates that key is in an acceptable format for the META.yml specification,
642 i.e. any in the character class [-_a-z].
643  
644 For user defined keys, although not explicitly stated in the specifications
645 (v1.0 - v1.4), the convention is to precede the key with a pattern matching
646 qr{\Ax_}i. Following this any character from the character class [-_a-zA-Z]
647 can be used. This clarification has been added to v2.0 of the specification.
648  
649 =item * identifier($self,$key,$value)
650  
651 Validates that key is in an acceptable format for the META.yml specification,
652 for an identifier, i.e. any that matches the regular expression
653 qr/[a-z][a-z_]/i.
654  
655 =item * module($self,$key,$value)
656  
657 Validates that a given key is in an acceptable module name format, e.g.
658 'Test::CPAN::Meta::JSON::Version'.
659  
660 =item * release_status($self,$key,$value)
661  
662 Validates that the value for 'release_status' is set appropriately for one of
663 'stable', 'testing' or 'unstable'.
664  
665 =item * custom_1($self,$key,$value)
666  
667 Validates custom keys based on camelcase only.
668  
669 =item * custom_2($self,$key,$value)
670  
671 Validates custom keys based on user defined (i.e. /^[xX]_/) only.
672  
673 =item * phase($self,$key,$value)
674  
675 Validates for a legal phase of a pre-requisite map.
676  
677 =item * relation($self,$key,$value)
678  
679 Validates for a legal relation, within a phase, of a pre-requisite map.
680  
681 =item * anything($self,$key,$value)
682  
683 Usually reserved for user defined structures, allowing them to be considered
684 valid without a need for a specification definition for the structure.
685  
686 =back
687  
688 =cut
689  
690 102 ▶sub _uri_split {
Subroutine _uri_split: called CC=1 SCAR=0.0
691 102 return $_[0] =~ m,(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?,;
692 }
693  
694 114 ▶sub url {
Subroutine url: called CC=4 SCAR=13.9
Pod documented
695 114 my ($self,$key,$value) = @_;
696 114 ▶ if($value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value) { } 102 12 114
697 102 my ($scheme, $auth, $path, $query, $frag) = _uri_split($value);
698  
699 102 ▶ unless ( $scheme ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($scheme) 12 90 102
700 12 $self->_error( "'$value' for '$key' does not have a URL scheme" );
701 12 return 0;
702 }
703 90 ▶ unless ( $auth ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($auth) 14 76 90
704 14 $self->_error( "'$value' for '$key' does not have a URL authority" );
705 14 return 0;
706 }
707 76 return 1;
708 } else {
709 12 $value = '<undef>';
710 }
711 12 $self->_error( "'$value' for '$key' is not a valid URL." );
712 12 return 0;
713 }
714  
715 62 ▶sub urlspec {
Subroutine urlspec: called CC=6 SCAR=17.9
Pod documented
716 62 my ($self,$key,$value) = @_;
717 62 ▶ if(defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 57 5 62
718 57 ▶ return 1 if($value && $known_specs{$self->{spec}} eq $value);
Branch: 1 branch
BranchTrueFalseTotal
if $value and $known_specs{$self->{"spec"}} eq $value 37 20 57
Condition100%3/3
$value and $known_specs{$self->{"spec"}} eq $value
!ll&&!rl&&r
51537
MC/DC100%2/2
$value and $known_specs{$self->{"spec"}} eq $value
$value $known_specs{$self->{"spec"}} eq $value
Truth table100%3/3
A and B
A= $valueB= $known_specs{$self->{"spec"}} eq $value
ABresult
0X0
100
111
719 20 ▶ if($value && $known_urls{$value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value and $known_urls{$value}) 10 10 20
Condition100%3/3
$value and $known_urls{$value}
!ll&&!rl&&r
5510
MC/DC100%2/2
$value and $known_urls{$value}
$value $known_urls{$value}
Truth table100%3/3
A and B
A= $valueB= $known_urls{$value}
ABresult
0X0
100
111
720 10 $self->_error( 'META.yml specification URL does not match version' );
721 10 return 0;
722 }
723 }
724 15 $self->_error( 'Unknown META.yml specification' );
725 15 return 0;
726 }
727  
728 531 ▶sub string {
Subroutine string: called CC=4 SCAR=13.9
Pod documented
729 531 my ($self,$key,$value) = @_;
730 531 ▶ if(defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 525 6 531
731 525 ▶ return 1 if($value || $value =~ /^0$/);
Branch: 1 branch
BranchTrueFalseTotal
if $value or $value =~ /^0$/ 519 6 525
Condition100%3/3
$value or $value =~ /^0$/
l!l&&r!l&&!r
51366
MC/DC100%2/2
$value or $value =~ /^0$/
$value $value =~ /^0$/
Truth table100%3/3
A or B
A= $valueB= $value =~ /^0$/
ABresult
1X1
011
000
732 }
733 12 $self->_error( "value is an undefined string" );
734 12 return 0;
735 }
736  
737 24 ▶sub string_or_undef {
Subroutine string_or_undef: called CC=4 SCAR=13.9
Pod documented
738 24 my ($self,$key,$value) = @_;
739 24 ▶ return 1 unless(defined $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 6 18 24
740 18 ▶ return 1 if($value || $value =~ /^0$/);
Branch: 1 branch
BranchTrueFalseTotal
if $value or $value =~ /^0$/ 12 6 18
Condition100%3/3
$value or $value =~ /^0$/
l!l&&r!l&&!r
666
MC/DC100%2/2
$value or $value =~ /^0$/
$value $value =~ /^0$/
Truth table100%3/3
A or B
A= $valueB= $value =~ /^0$/
ABresult
1X1
011
000
741 6 $self->_error( "No string defined for '$key'" );
742 6 return 0;
743 }
744  
745 88 ▶sub file {
Subroutine file: called CC=2 SCAR=6.9
Pod documented
746 88 my ($self,$key,$value) = @_;
747 88 ▶ return 1 if(defined $value);
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 82 6 88
748 6 $self->_error( "No file defined for '$key'" );
749 6 return 0;
750 }
751  
752 735 ▶sub exversion {
Subroutine exversion: called CC=7 SCAR=19.5
Pod documented
753 735 my ($self,$key,$value) = @_;
754 735 ▶ if(defined $value && ($value || $value =~ /0/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and $value || $value =~ /0/) 717 18 735
Condition100%6/6
defined $value and $value || $value =~ /0/
!ll&&!rl&&r
126717
$value or $value =~ /0/
l!l&&r!l&&!r
4003176
MC/DC100%3/3
defined $value and $value || $value =~ /0/
defined $value $value $value =~ /0/
Truth table100%4/4
A and B or C
A= defined $valueB= $valueC= $value =~ /0/
ABCresult
0XX0
1000
11X1
1011
755 717 my $pass = 1;
756 717 ▶ for(split(",",$value)) { $self->version($key,$_) or ($pass = 0); }
Branch: 1 branch
BranchTrueFalseTotal
$self->version($key, $_) or $pass = 0 741 6 747
757 717 return $pass;
758 }
759 18 ▶ $value = '<undef>' unless(defined $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 12 6 18
760 18 $self->_error( "'$value' for '$key' is not a valid version." );
761 18 return 0;
762 }
763  
764 1001 ▶sub version {
Subroutine version: called CC=5 SCAR=16.1
Pod documented
765 1001 my ($self,$key,$value) = @_;
766 1001 ▶ if(defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 989 12 1001
767 989 ▶ return 0 unless($value || $value =~ /0/);
Branch: 1 branch
BranchTrueFalseTotal
unless $value or $value =~ /0/ 6 983 989
Condition100%3/3
$value or $value =~ /0/
l!l&&r!l&&!r
6603236
MC/DC100%2/2
$value or $value =~ /0/
$value $value =~ /0/
Truth table100%3/3
A or B
A= $valueB= $value =~ /0/
ABresult
1X1
011
000
768 983 ▶ return 1 if($value =~ /^\s*((<|<=|>=|>|!=|==)\s*)?v?\d+((\.\d+((_|\.)\d+)?)?)/);
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /^\s*((<|<=|>=|>|!=|==)\s*)?v?\d+((\.\d+((_|\.)\d+)?)?)/ 969 14 983
769 } else {
770 12 $value = '<undef>';
771 }
772 26 $self->_error( "'$value' for '$key' is not a valid version." );
773 26 return 0;
774 }
775  
776 70 ▶sub boolean {
Subroutine boolean: called CC=3 SCAR=11.0
Pod documented
777 70 my ($self,$key,$value) = @_;
778 70 ▶ if(defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 58 12 70
779 58 ▶ return 1 if($value =~ /^(0|1|true|false)$/);
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /^(0|1|true|false)$/ 46 12 58
780 } else {
781 12 $value = '<undef>';
782 }
783 24 $self->_error( "'$value' for '$key' is not a boolean value." );
784 24 return 0;
785 }
786  
787 15 my %v1_licenses = (
788 'perl' => 'http://dev.perl.org/licenses/',
789 'gpl' => 'http://www.opensource.org/licenses/gpl-license.php',
790 'apache' => 'http://apache.org/licenses/LICENSE-2.0',
791 'artistic' => 'http://opensource.org/licenses/artistic-license.php',
792 'artistic2' => 'http://opensource.org/licenses/artistic-license-2.0.php',
793 'artistic-2.0' => 'http://opensource.org/licenses/artistic-license-2.0.php',
794 'lgpl' => 'http://www.opensource.org/licenses/lgpl-license.phpt',
795 'bsd' => 'http://www.opensource.org/licenses/bsd-license.php',
796 'gpl' => 'http://www.opensource.org/licenses/gpl-license.php',
797 'mit' => 'http://opensource.org/licenses/mit-license.php',
798 'mozilla' => 'http://opensource.org/licenses/mozilla1.1.php',
799 'open_source' => undef,
800 'unrestricted' => undef,
801 'restrictive' => undef,
802 'unknown' => undef,
803 );
804  
805 15 my %v2_licenses = map { $_ => 1 } qw(
806 agpl_3
807 apache_1_1
808 apache_2_0
809 artistic_1
810 artistic_2
811 bsd
812 freebsd
813 gfdl_1_2
814 gfdl_1_3
815 gpl_1
816 gpl_2
817 gpl_3
818 lgpl_2_1
819 lgpl_3_0
820 mit
821 mozilla_1_0
822 mozilla_1_1
823 openssl
824 perl_5
825 qpl_1_0
826 ssleay
827 sun
828 zlib
829 open_source
830 restricted
831 unrestricted
832 unknown
833 );
834  
835 186 ▶sub license {
Subroutine license: called CC=7 SCAR=19.5
Pod documented
836 186 my ($self,$key,$value) = @_;
837 186 ▶ my $licenses = $self->{spec} < 2 ? \%v1_licenses : \%v2_licenses;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'spec'} < 2 ? : 133 53 186
838 186 ▶ if(defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 180 6 186
839 180 ▶ return 1 if($value && exists $licenses->{$value});
Branch: 1 branch
BranchTrueFalseTotal
if $value and exists $licenses->{$value} 167 13 180
Condition100%3/3
$value and exists $licenses->{$value}
!ll&&!rl&&r
67167
MC/DC100%2/2
$value and exists $licenses->{$value}
$value exists $licenses->{$value}
Truth table100%3/3
A and B
A= $valueB= exists $licenses->{$value}
ABresult
0X0
100
111
840  
841 # v1 specs caused problems for some with this field,
842 # so this test is relaxed for v1 tests only.
843 13 ▶ return 2 if($value && $self->{spec} < 2);
Branch: 1 branch
BranchTrueFalseTotal
if $value and $self->{"spec"} < 2 5 8 13
Condition100%3/3
$value and $self->{"spec"} < 2
!ll&&!rl&&r
625
MC/DC100%2/2
$value and $self->{"spec"} < 2
$value $self->{"spec"} < 2
Truth table100%3/3
A and B
A= $valueB= $self->{"spec"} < 2
ABresult
0X0
100
111
844 } else {
845 6 $value = '<undef>';
846 }
847 14 $self->_error( "License '$value' is invalid" );
848 14 return 0;
849 }
850  
851 43 ▶sub resource {
Subroutine resource: called CC=5 SCAR=16.1
Pod documented
852 43 my ($self,$key) = @_;
853 43 ▶ if(defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 37 6 43
854 # a valid user defined key should be alphabetic
855 # and contain at least one capital case letter.
856 37 ▶ return 1 if($key && $key =~ /^[a-z]+$/i && $key =~ /[A-Z]/);
Branch: 1 branch
BranchTrueFalseTotal
if $key and $key =~ /^[a-z]+$/i and $key =~ /[A-Z]/ 24 13 37
Condition100%6/6
$key and $key =~ /^[a-z]+$/i and $key =~ /[A-Z]/
!ll&&!rl&&r
7624
$key and $key =~ /^[a-z]+$/i
!ll&&!rl&&r
6130
MC/DC100%3/3
$key and $key =~ /^[a-z]+$/i and $key =~ /[A-Z]/
$key $key =~ /^[a-z]+$/i $key =~ /[A-Z]/
Truth table100%4/4
A and B and C
A= $keyB= $key =~ /^[a-z]+$/iC= $key =~ /[A-Z]/
ABCresult
0XX0
10X0
1100
1111
857 } else {
858 6 $key = '<undef>';
859 }
860 19 $self->_error( "Resource '$key' must be in CamelCase." );
861 19 return 0;
862 }
863  
864 125 ▶sub keyword {
Subroutine keyword: called CC=6 SCAR=17.9
Pod documented
865 125 my ($self,$key) = @_;
866 125 ▶ if(defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 119 6 125
867 119 ▶ return 1 if($key && $key =~ /^([a-z][-_a-z]*)$/); # spec defined
Branch: 1 branch
BranchTrueFalseTotal
if $key and $key =~ /^([a-z][-_a-z]*)$/ 83 36 119
Condition100%3/3
$key and $key =~ /^([a-z][-_a-z]*)$/
!ll&&!rl&&r
63083
MC/DC100%2/2
$key and $key =~ /^([a-z][-_a-z]*)$/
$key $key =~ /^([a-z][-_a-z]*)$/
Truth table100%3/3
A and B
A= $keyB= $key =~ /^([a-z][-_a-z]*)$/
ABresult
0X0
100
111
868 36 ▶ return 1 if($key && $key =~ /^x_([a-z][-_a-z]*)$/i); # user defined
Branch: 1 branch
BranchTrueFalseTotal
if $key and $key =~ /^x_([a-z][-_a-z]*)$/i 6 30 36
Condition100%3/3
$key and $key =~ /^x_([a-z][-_a-z]*)$/i
!ll&&!rl&&r
6246
MC/DC100%2/2
$key and $key =~ /^x_([a-z][-_a-z]*)$/i
$key $key =~ /^x_([a-z][-_a-z]*)$/i
Truth table100%3/3
A and B
A= $keyB= $key =~ /^x_([a-z][-_a-z]*)$/i
ABresult
0X0
100
111
869 } else {
870 6 $key = '<undef>';
871 }
872 36 $self->_error( "Key '$key' is not a legal keyword." );
873 36 return 0;
874 }
875  
876 88 ▶sub identifier {
Subroutine identifier: called CC=4 SCAR=13.9
Pod documented
877 88 my ($self,$key) = @_;
878 88 ▶ if(defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 82 6 88
879 82 ▶ return 1 if($key && $key =~ /^([a-z][_a-z]+)$/i); # spec 2.0 defined
Branch: 1 branch
BranchTrueFalseTotal
if $key and $key =~ /^([a-z][_a-z]+)$/i 58 24 82
Condition100%3/3
$key and $key =~ /^([a-z][_a-z]+)$/i
!ll&&!rl&&r
61858
MC/DC100%2/2
$key and $key =~ /^([a-z][_a-z]+)$/i
$key $key =~ /^([a-z][_a-z]+)$/i
Truth table100%3/3
A and B
A= $keyB= $key =~ /^([a-z][_a-z]+)$/i
ABresult
0X0
100
111
880 } else {
881 6 $key = '<undef>';
882 }
883 30 $self->_error( "Key '$key' is not a legal identifier." );
884 30 return 0;
885 }
886  
887 803 ▶sub module {
Subroutine module: called CC=4 SCAR=13.9
Pod documented
888 803 my ($self,$key) = @_;
889 803 ▶ if(defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 797 6 803
890 797 ▶ return 1 if($key && $key =~ /^[A-Za-z0-9_]+(::[A-Za-z0-9_]+)*$/);
Branch: 1 branch
BranchTrueFalseTotal
if $key and $key =~ /^[A-Za-z0-9_]+(::[A-Za-z0-9_]+)*$/ 779 18 797
Condition100%3/3
$key and $key =~ /^[A-Za-z0-9_]+(::[A-Za-z0-9_]+)*$/
!ll&&!rl&&r
612779
MC/DC100%2/2
$key and $key =~ /^[A-Za-z0-9_]+(::[A-Za-z0-9_]+)*$/
$key $key =~ /^[A-Za-z0-9_]+(::[A-Za-z0-9_]+)*$/
Truth table100%3/3
A and B
A= $keyB= $key =~ /^[A-Za-z0-9_]+(::[A-Za-z0-9_]+)*$/
ABresult
0X0
100
111
891 } else {
892 6 $key = '<undef>';
893 }
894 24 $self->_error( "Key '$key' is not a legal module name." );
895 24 return 0;
896 }
897  
898 36 ▶sub release_status {
Subroutine release_status: called CC=6 SCAR=17.9
Pod documented
899 36 my ($self,$key,$value) = @_;
900 36 ▶ if(defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 35 1 36
901 35 ▶ my $version = $self->{data}{version} || '';
Condition100%2/2
$self->{'data'}{'version'} || ''
l!l
323
MC/DC100%1/1
$self->{'data'}{'version'} || ''
$self->{'data'}{'version'}
Truth table100%2/2
A
A= $self->{'data'}{'version'}
Aresult
11
00
902 35 ▶ if ( $version =~ /_/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version =~ /_/) { } 3 32 35
903 3 ▶ return 1 if ( $value =~ /\A(?:testing|unstable)\z/ );
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /\A(?:testing|unstable)\z/ 2 1 3
904 1 $self->_error( "'$value' for '$key' is invalid for version '$version'" );
905 } else {
906 32 ▶ return 1 if ( $value =~ /\A(?:stable|testing|unstable)\z/ );
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /\A(?:stable|testing|unstable)\z/ 28 4 32
907 4 $self->_error( "'$value' for '$key' is invalid" );
908 }
909 } else {
910 1 $self->_error( "'$key' is not defined" );
911 }
912 6 return 0;
913 }
914  
915 11 ▶sub custom_1 {
Subroutine custom_1: called CC=5 SCAR=16.1
Pod documented
916 11 my ($self,$key) = @_;
917 11 ▶ if(defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 10 1 11
918 # a valid user defined key should be alphabetic
919 # and contain at least one capital case letter.
920 10 ▶ return 1 if($key && $key =~ /^[a-z]+$/i && $key =~ /[A-Z]/);
Branch: 1 branch
BranchTrueFalseTotal
if $key and $key =~ /^[a-z]+$/i and $key =~ /[A-Z]/ 2 8 10
Condition100%6/6
$key and $key =~ /^[a-z]+$/i and $key =~ /[A-Z]/
!ll&&!rl&&r
712
$key and $key =~ /^[a-z]+$/i
!ll&&!rl&&r
163
MC/DC100%3/3
$key and $key =~ /^[a-z]+$/i and $key =~ /[A-Z]/
$key $key =~ /^[a-z]+$/i $key =~ /[A-Z]/
Truth table100%4/4
A and B and C
A= $keyB= $key =~ /^[a-z]+$/iC= $key =~ /[A-Z]/
ABCresult
0XX0
10X0
1100
1111
921 } else {
922 1 $key = '<undef>';
923 }
924 9 $self->_error( "Custom resource '$key' must be in CamelCase." );
925 9 return 0;
926 }
927  
928 20 ▶sub custom_2 {
Subroutine custom_2: called CC=4 SCAR=13.9
Pod documented
929 20 my ($self,$key) = @_;
930 20 ▶ if(defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 19 1 20
931 # a valid user defined key should be alphabetic
932 # and begin with x_ or X_
933 19 ▶ return 1 if($key && $key =~ /^x_([a-z][-_a-z]*)$/i); # user defined
Branch: 1 branch
BranchTrueFalseTotal
if $key and $key =~ /^x_([a-z][-_a-z]*)$/i 2 17 19
Condition100%3/3
$key and $key =~ /^x_([a-z][-_a-z]*)$/i
!ll&&!rl&&r
1162
MC/DC100%2/2
$key and $key =~ /^x_([a-z][-_a-z]*)$/i
$key $key =~ /^x_([a-z][-_a-z]*)$/i
Truth table100%3/3
A and B
A= $keyB= $key =~ /^x_([a-z][-_a-z]*)$/i
ABresult
0X0
100
111
934 } else {
935 1 $key = '<undef>';
936 }
937 18 $self->_error( "Custom resource '$key' must begin with 'x_' or 'X_'." );
938 18 return 0;
939 }
940  
941 15 my @valid_phases = qw/ configure build test runtime develop /;
942 94 ▶sub phase {
Subroutine phase: called CC=4 SCAR=13.9
Pod documented
943 94 my ($self,$key) = @_;
944 94 ▶ if(defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 93 1 94
945 93 ▶ return 1 if( length $key && grep { $key eq $_ } @valid_phases );
Branch: 1 branch
BranchTrueFalseTotal
if length $key and grep {$key eq $_;} @valid_phases 85 8 93
Condition100%3/3
length $key and grep {$key eq $_;} @valid_phases
!ll&&!rl&&r
1785
MC/DC100%2/2
length $key and grep {$key eq $_;} @valid_phases
length $key grep {$key eq $_;} @valid_phases
Truth table100%3/3
A and B
A= length $keyB= grep {$key eq $_;} @valid_phases
ABresult
0X0
100
111
946 } else {
947 1 $key = '<undef>';
948 }
949 9 $self->_error( "Key '$key' is not a legal phase." );
950 9 return 0;
951 }
952  
953 15 my @valid_relations = qw/ requires recommends suggests conflicts /;
954 115 ▶sub relation {
Subroutine relation: called CC=4 SCAR=13.9
Pod documented
955 115 my ($self,$key) = @_;
956 115 ▶ if(defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 114 1 115
957 114 ▶ return 1 if( length $key && grep { $key eq $_ } @valid_relations );
Branch: 1 branch
BranchTrueFalseTotal
if length $key and grep {$key eq $_;} @valid_relations 106 8 114
Condition100%3/3
length $key and grep {$key eq $_;} @valid_relations
!ll&&!rl&&r
17106
MC/DC100%2/2
length $key and grep {$key eq $_;} @valid_relations
length $key grep {$key eq $_;} @valid_relations
Truth table100%3/3
A and B
A= length $keyB= grep {$key eq $_;} @valid_relations
ABresult
0X0
100
111
958 } else {
959 1 $key = '<undef>';
960 }
961 9 $self->_error( "Key '$key' is not a legal prereq relationship." );
962 9 return 0;
963 }
964  
965 69 ▶sub anything { return 1 }
Subroutine anything: called CC=1 SCAR=0.0
Pod documented
966  
967 366 ▶sub _error {
Subroutine _error: called CC=2 SCAR=6.9
968 366 my $self = shift;
969 366 my $mess = shift;
970  
971 366 ▶ $mess .= ' ('.join(' -> ',@{$self->{stack}}).')' if($self->{stack});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"stack"} 69 297 366
972 366 $mess .= " [Validation: $self->{spec}]";
973  
974 366 push @{$self->{errors}}, $mess;
975 }
976  
977 15 q( Currently Listening To: Rainbow - "I Surrender" from 'Outrage - Live in London 1981');
978  
979 __END__
↑ Summary JSON.pm »