YAML/Version.pm

filter: Statementstmt 95.7% 178 / 186 Branchbran 86.8% 99 / 114 Conditioncond 95.8% 46 / 48 MC/DCmcdc 93.3% 28 / 30 Subroutinesub 100% 25 / 25 Podpod 100% 20 / 20 totaltotal 93.6% 396 / 423 CC 78 SCAR 19.9
CC
78
Cov
93%
check_list
19.1
check_map
15.5
exversion
7.0
CRAP 7.3
↑ Summary YAML.pm »
1 package Test::CPAN::Meta::YAML::Version;
2  
3 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 10 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 $VERSION = '0.25';
8  
9 #----------------------------------------------------------------------------
10  
11 =head1 NAME
12  
13 Test::CPAN::Meta::YAML::Version - Validate CPAN META data against the specification
14  
15 =head1 SYNOPSIS
16  
17 use Test::CPAN::Meta::YAML::Version;
18  
19 =head1 DESCRIPTION
20  
21 This module was written to ensure that a META.yml 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::YAML>, 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.yml data against the CPAN Meta Specification.
34  
35 =cut
36  
37 #----------------------------------------------------------------------------
38  
39 #############################################################################
40 #Specification Definitions #
41 #############################################################################
42  
43 10 my %known_specs = (
44 '1.4' => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
45 '1.3' => 'http://module-build.sourceforge.net/META-spec-v1.3.html',
46 '1.2' => 'http://module-build.sourceforge.net/META-spec-v1.2.html',
47 '1.1' => 'http://module-build.sourceforge.net/META-spec-v1.1.html',
48 '1.0' => 'http://module-build.sourceforge.net/META-spec-v1.0.html'
49 );
50 10 my %known_urls = map {$known_specs{$_} => $_} keys %known_specs;
51  
52 10 my $module_map1 = { 'map' => { ':key' => { name => \&module, value => \&exversion } } };
53 10 my $module_map2 = { 'map' => { ':key' => { name => \&module, value => \&version } } };
54 10 my $no_index_1_3 = {
55 'map' => { file => { list => { value => \&string } },
56 directory => { list => { value => \&string } },
57 'package' => { list => { value => \&string } },
58 namespace => { list => { value => \&string } },
59 }
60 };
61 10 my $no_index_1_2 = {
62 'map' => { file => { list => { value => \&string } },
63 dir => { list => { value => \&string } },
64 'package' => { list => { value => \&string } },
65 namespace => { list => { value => \&string } },
66 }
67 };
68 10 my $no_index_1_1 = {
69 'map' => { ':key' => { name => \&keyword, list => { value => \&string } },
70 }
71 };
72  
73 10 my %definitions = (
74 '1.4' => {
75 # 'header' => { mandatory => 1, value => \&header },
76 'meta-spec' => { mandatory => 1, 'map' => { version => { mandatory => 1, value => \&version},
77 url => { mandatory => 1, value => \&urlspec } } },
78  
79 'name' => { mandatory => 1, value => \&string },
80 'version' => { mandatory => 1, value => \&version },
81 'abstract' => { mandatory => 1, value => \&string },
82 'author' => { mandatory => 1, list => { value => \&string } },
83 'license' => { mandatory => 1, value => \&license },
84 'generated_by' => { mandatory => 1, value => \&string },
85  
86 'distribution_type' => { value => \&string },
87 'dynamic_config' => { value => \&boolean },
88  
89 'requires' => $module_map1,
90 'recommends' => $module_map1,
91 'build_requires' => $module_map1,
92 'configure_requires' => $module_map1,
93 'conflicts' => $module_map2,
94  
95 'optional_features' => {
96 'map' => {
97 ':key' => { name => \&identifier,
98 'map' => { description => { value => \&string },
99 requires_packages => { value => \&string },
100 requires_os => { value => \&string },
101 excludes_os => { value => \&string },
102 requires => $module_map1,
103 recommends => $module_map1,
104 build_requires => $module_map1,
105 conflicts => $module_map2,
106 }
107 }
108 }
109 },
110  
111 'provides' => {
112 'map' => { ':key' => { name => \&module,
113 'map' => { file => { mandatory => 1, value => \&file },
114 version => { value => \&version } } } }
115 },
116  
117 'no_index' => $no_index_1_3,
118 'private' => $no_index_1_3,
119  
120 'keywords' => { list => { value => \&string } },
121  
122 'resources' => {
123 'map' => { license => { value => \&url },
124 homepage => { value => \&url },
125 bugtracker => { value => \&url },
126 repository => { value => \&url },
127 ':key' => { value => \&string, name => \&resource },
128 }
129 },
130  
131 # additional user defined key/value pairs
132 # note we can only validate the key name, as the structure is user defined
133 ':key' => { name => \&keyword, value => \&anything },
134 },
135  
136 '1.3' => {
137 # 'header' => { mandatory => 1, value => \&header },
138 'meta-spec' => { mandatory => 1, 'map' => { version => { mandatory => 1, value => \&version},
139 url => { mandatory => 1, value => \&urlspec } } },
140  
141 'name' => { mandatory => 1, value => \&string },
142 'version' => { mandatory => 1, value => \&version },
143 'abstract' => { mandatory => 1, value => \&string },
144 'author' => { mandatory => 1, list => { value => \&string } },
145 'license' => { mandatory => 1, value => \&license },
146 'generated_by' => { mandatory => 1, value => \&string },
147  
148 'distribution_type' => { value => \&string },
149 'dynamic_config' => { value => \&boolean },
150  
151 'requires' => $module_map1,
152 'recommends' => $module_map1,
153 'build_requires' => $module_map1,
154 'conflicts' => $module_map2,
155  
156 'optional_features' => {
157 'map' => {
158 ':key' => { name => \&identifier,
159 'map' => { description => { value => \&string },
160 requires_packages => { value => \&string },
161 requires_os => { value => \&string },
162 excludes_os => { value => \&string },
163 requires => $module_map1,
164 recommends => $module_map1,
165 build_requires => $module_map1,
166 conflicts => $module_map2,
167 }
168 }
169 }
170 },
171  
172 'provides' => {
173 'map' => { ':key' => { name => \&module,
174 'map' => { file => { mandatory => 1, value => \&file },
175 version => { value => \&version } } } }
176 },
177  
178 'no_index' => $no_index_1_3,
179 'private' => $no_index_1_3,
180  
181 'keywords' => { list => { value => \&string } },
182  
183 'resources' => {
184 'map' => { license => { value => \&url },
185 homepage => { value => \&url },
186 bugtracker => { value => \&url },
187 repository => { value => \&url },
188 ':key' => { value => \&string, name => \&resource },
189 }
190 },
191  
192 # additional user defined key/value pairs
193 # note we can only validate the key name, as the structure is user defined
194 ':key' => { name => \&keyword, value => \&anything },
195 },
196  
197 # v1.2 is misleading, it seems to assume that a number of fields where created
198 # within v1.1, when they were created within v1.2. This may have been an
199 # original mistake, and that a v1.1 was retro fitted into the timeline, when
200 # v1.2 was originally slated as v1.1. But I could be wrong ;)
201 '1.2' => {
202 # 'header' => { mandatory => 1, value => \&header },
203 'meta-spec' => { mandatory => 1, 'map' => { version => { mandatory => 1, value => \&version},
204 url => { mandatory => 1, value => \&urlspec } } },
205  
206 'name' => { mandatory => 1, value => \&string },
207 'version' => { mandatory => 1, value => \&version },
208 'license' => { mandatory => 1, value => \&license },
209 'generated_by' => { mandatory => 1, value => \&string },
210 'author' => { mandatory => 1, list => { value => \&string } },
211 'abstract' => { mandatory => 1, value => \&string },
212  
213 'distribution_type' => { value => \&string },
214 'dynamic_config' => { value => \&boolean },
215  
216 'keywords' => { list => { value => \&string } },
217  
218 'private' => $no_index_1_2,
219 '$no_index' => $no_index_1_2,
220  
221 'requires' => $module_map1,
222 'recommends' => $module_map1,
223 'build_requires' => $module_map1,
224 'conflicts' => $module_map2,
225  
226 'optional_features' => {
227 'map' => {
228 ':key' => { name => \&identifier,
229 'map' => { description => { value => \&string },
230 requires_packages => { value => \&string },
231 requires_os => { value => \&string },
232 excludes_os => { value => \&string },
233 requires => $module_map1,
234 recommends => $module_map1,
235 build_requires => $module_map1,
236 conflicts => $module_map2,
237 }
238 }
239 }
240 },
241  
242 'provides' => {
243 'map' => { ':key' => { name => \&module,
244 'map' => { file => { mandatory => 1, value => \&file },
245 version => { value => \&version } } } }
246 },
247  
248 'resources' => {
249 'map' => { license => { value => \&url },
250 homepage => { value => \&url },
251 bugtracker => { value => \&url },
252 repository => { value => \&url },
253 ':key' => { value => \&string, name => \&resource },
254 }
255 },
256  
257 # additional user defined key/value pairs
258 # note we can only validate the key name, as the structure is user defined
259 ':key' => { name => \&keyword, value => \&anything },
260 },
261  
262 # note that the 1.1 spec doesn't specify optional or mandatory fields, what
263 # appears below is assumed from later specifications.
264 '1.1' => {
265 # 'header' => { mandatory => 1, value => \&header },
266 'name' => { mandatory => 1, value => \&string },
267 'version' => { mandatory => 1, value => \&version },
268 'license' => { mandatory => 1, value => \&license },
269 'license_uri' => { mandatory => 0, value => \&url },
270 'generated_by' => { mandatory => 1, value => \&string },
271  
272 'distribution_type' => { value => \&string },
273 'dynamic_config' => { value => \&boolean },
274  
275 'private' => $no_index_1_1,
276  
277 'requires' => $module_map1,
278 'recommends' => $module_map1,
279 'build_requires' => $module_map1,
280 'conflicts' => $module_map2,
281  
282 # additional user defined key/value pairs
283 # note we can only validate the key name, as the structure is user defined
284 ':key' => { name => \&keyword, value => \&anything },
285 },
286  
287 # note that the 1.0 spec doesn't specify optional or mandatory fields, what
288 # appears below is assumed from later specifications.
289 '1.0' => {
290 # 'header' => { mandatory => 1, value => \&header },
291 'name' => { mandatory => 1, value => \&string },
292 'version' => { mandatory => 1, value => \&version },
293 'license' => { mandatory => 1, value => \&license },
294 'generated_by' => { mandatory => 1, value => \&string },
295  
296 'distribution_type' => { value => \&string },
297 'dynamic_config' => { value => \&boolean },
298  
299 'requires' => $module_map1,
300 'recommends' => $module_map1,
301 'build_requires' => $module_map1,
302 'conflicts' => $module_map2,
303  
304 # additional user defined key/value pairs
305 # note we can only validate the key name, as the structure is user defined
306 ':key' => { name => \&keyword, value => \&anything },
307 },
308 );
309  
310 #############################################################################
311 #Code #
312 #############################################################################
313  
314 =head1 CLASS CONSTRUCTOR
315  
316 =over
317  
318 =item * new( data => $data [, spec => $version] )
319  
320 The constructor must be passed a valid data structure.
321  
322 Optionally you may also provide a specification version. This version is then
323 use to ensure that the given data structure meets the respective
324 specification definition. If no version is provided the module will attempt to
325 deduce the appropriate specification version from the data structure itself.
326  
327 =back
328  
329 =cut
330  
331 45 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
332 45 my ($class,%hash) = @_;
333  
334 # create an attributes hash
335 my $atts = {
336 'spec' => $hash{spec},
337 'data' => $hash{data},
338 45 };
339  
340 # create the object
341 45 my $self = bless $atts, $class;
342 }
343  
344 =head1 METHODS
345  
346 =head2 Main Methods
347  
348 =over
349  
350 =item * parse()
351  
352 Using the given data structure provided with the constructor, attempts to
353 parse and validate according to the appropriate specification definition.
354  
355 Returns 1 if any errors found, otherwise returns 0.
356  
357 =item * errors()
358  
359 Returns a list of the errors found during parsing.
360  
361 =back
362  
363 =cut
364  
365 44 ▶sub parse {
Subroutine parse: called CC=5 SCAR=16.1
Pod documented
366 44 my $self = shift;
367 44 my $data = $self->{data};
368  
369 44 ▶ unless($self->{spec}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"spec"}) 21 23 44
370 21 ▶ $self->{spec} = $data->{'meta-spec'} && $data->{'meta-spec'}{'version'} ? $data->{'meta-spec'}{'version'} : '1.0';
Branch: 1 branch
BranchTrueFalseTotal
$data->{'meta-spec'} && $data->{'meta-spec'}{'version'} ? : 19 2 21
Condition66%2/3
$data->{"meta-spec"} and $data->{"meta-spec"}{"version"}
!ll&&!rl&&r
2019
MC/DC50%1/2
$data->{"meta-spec"} and $data->{"meta-spec"}{"version"}
$data->{"meta-spec"} $data->{"meta-spec"}{"version"}
Truth table66%2/3
A and B
A= $data->{"meta-spec"}B= $data->{"meta-spec"}{"version"}
ABresult
0X0
100
111
371 }
372  
373 44 $self->check_map($definitions{$self->{spec}},$data);
374 44 ▶ return defined $self->{errors} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'errors'} ? : 18 26 44
375 }
376  
377 41 ▶sub errors {
Subroutine errors: called CC=2 SCAR=6.9
Pod documented
378 41 my $self = shift;
379 41 ▶ return () unless($self->{errors});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"errors"} 18 23 41
380 23 return @{$self->{errors}};
381 }
382  
383 =head2 Check Methods
384  
385 =over
386  
387 =item * check_map($spec,$data)
388  
389 Checks whether a map (or hash) part of the data structure conforms to the
390 appropriate specification definition.
391  
392 =item * check_list($spec,$data)
393  
394 Checks whether a list (or array) part of the data structure conforms to
395 the appropriate specification definition.
396  
397 =back
398  
399 =cut
400  
401 350 ▶sub check_map {
Subroutine check_map: called CC=15 SCAR=27.4
Pod documented
402 350 my ($self,$spec,$data) = @_;
403  
404 350 ▶ if(ref($spec) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $spec ne "HASH") 1 349 350
405 1 $self->_error( "Unknown META.yml specification, cannot validate." );
406 1 return;
407 }
408  
409 349 ▶ if(ref($data) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data ne "HASH") 3 346 349
410 3 $self->_error( "Expected a map structure from data string or file." );
411 3 return;
412 }
413  
414 346 for my $key (keys %$spec) {
415 1350 ▶ next unless($spec->{$key}->{mandatory});
Branch: 1 branch
BranchTrueFalseTotal
unless $spec->{$key}{"mandatory"} 931 419 1350
416 419 ▶ next if(defined $data->{$key});
Branch: 1 branch
BranchTrueFalseTotal
if defined $data->{$key} 415 4 419
417 4 push @{$self->{stack}}, $key;
418 4 $self->_error( "Missing mandatory field, '$key'" );
419 4 pop @{$self->{stack}};
420 }
421  
422 346 for my $key (keys %$data) {
423 1219 push @{$self->{stack}}, $key;
424 1219 ▶ if($spec->{$key}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($spec->{$key}) { } 783 436 1219
elsif ($spec->{':key'}) { } 436 0 436
425 783 ▶ if($spec->{$key}{value}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($spec->{$key}{'value'}) { } 480 303 783
elsif ($spec->{$key}{'map'}) { } 234 69 303
elsif ($spec->{$key}{'list'}) { } 69 0 69
426 480 $spec->{$key}{value}->($self,$key,$data->{$key});
427 } elsif($spec->{$key}{'map'}) {
428 234 $self->check_map($spec->{$key}{'map'},$data->{$key});
429 } elsif($spec->{$key}{'list'}) {
430 69 $self->check_list($spec->{$key}{'list'},$data->{$key});
431 }
432  
433 } elsif ($spec->{':key'}) {
434 436 $spec->{':key'}{name}->($self,$key,$key);
435 436 ▶ if($spec->{':key'}{value}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($spec->{':key'}{'value'}) { } 366 70 436
elsif ($spec->{':key'}{'map'}) { } 70 0 70
elsif ($spec->{':key'}{'list'}) { } 0 0 0
436 366 $spec->{':key'}{value}->($self,$key,$data->{$key});
437 } elsif($spec->{':key'}{'map'}) {
438 70 $self->check_map($spec->{':key'}{'map'},$data->{$key});
439 } elsif($spec->{':key'}{'list'}) {
440 0 $self->check_list($spec->{':key'}{'list'},$data->{$key});
441 }
442  
443 } else {
444 0 $self->_error( "Unknown key, '$key', found in map structure" );
445 }
446 1218 pop @{$self->{stack}};
447 }
448 }
449  
450 71 ▶sub check_list {
Subroutine check_list: called CC=9 SCAR=29.5
Pod documented
451 71 my ($self,$spec,$data) = @_;
452  
453 71 ▶ if(ref($data) ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data ne "ARRAY") 3 68 71
454 3 $self->_error( "Expected a list structure" );
455 3 return;
456 }
457  
458 68 ▶ if(defined $spec->{mandatory}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $spec->{"mandatory"}) 0 68 68
459 0 ▶ if(!defined $data->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data->[0]) 0 0 0
460 0 $self->_error( "Missing entries from mandatory list" );
461 }
462 }
463  
464 68 for my $value (@$data) {
465 99 push @{$self->{stack}}, $value;
466 99 ▶ if(defined $spec->{value}) {
Branch: 4 branches
BranchTrueFalseTotal
if (defined $spec->{'value'}) { } 99 0 99
elsif (defined $spec->{'map'}) { } 0 0 0
elsif (defined $spec->{'list'}) { } 0 0 0
elsif ($spec->{':key'}) { } 0 0 0
467 99 $spec->{value}->($self,'list',$value);
468 } elsif(defined $spec->{'map'}) {
469 0 $self->check_map($spec->{'map'},$value);
470 } elsif(defined $spec->{'list'}) {
471 0 $self->check_list($spec->{'list'},$value);
472  
473 } elsif ($spec->{':key'}) {
474 0 $self->check_map($spec,$value);
475  
476 } else {
477 0 $self->_error( "Unknown value type, '$value', found in list structure" );
478 }
479 97 pop @{$self->{stack}};
480 }
481 }
482  
483 =head2 Validator Methods
484  
485 =over
486  
487 =item * header($self,$key,$value)
488  
489 Validates that the YAML header is valid.
490  
491 Note: No longer used as we now read the YAML data structure, not the file.
492  
493 =item * url($self,$key,$value)
494  
495 Validates that a given value is in an acceptable URL format
496  
497 =item * urlspec($self,$key,$value)
498  
499 Validates that the URL to a META.yml specification is a known one.
500  
501 =item * string_or_undef($self,$key,$value)
502  
503 Validates that the value is either a string or an undef value. Bit of a
504 catchall function for parts of the data structure that are completely user
505 defined.
506  
507 =item * string($self,$key,$value)
508  
509 Validates that a string exists for the given key.
510  
511 =item * file($self,$key,$value)
512  
513 Validate that a file is passed for the given key. This may be made more
514 thorough in the future. For now it acts like \&string.
515  
516 =item * exversion($self,$key,$value)
517  
518 Validates a list of versions, e.g. '<= 5, >=2, ==3, !=4, >1, <6, 0'.
519  
520 =item * version($self,$key,$value)
521  
522 Validates a single version string. Versions of the type '5.8.8' and '0.00_00'
523 are both valid. A leading 'v' like 'v1.2.3' is also valid.
524  
525 =item * boolean($self,$key,$value)
526  
527 Validates for a boolean value. Currently these values are '1', '0', 'true',
528 'false', however the latter 2 may be removed.
529  
530 =item * license($self,$key,$value)
531  
532 Validates that a value is given for the license. Returns 1 if an known license
533 type, or 2 if a value is given but the license type is not a recommended one.
534  
535 =item * resource($self,$key,$value)
536  
537 Validates that the given key is in CamelCase, to indicate a user defined
538 keyword.
539  
540 =item * keyword($self,$key,$value)
541  
542 Validates that key is in an acceptable format for the META.yml specification,
543 i.e. any in the character class [-_a-z].
544  
545 For user defined keys, although not explicitly stated in the specifications
546 (v1.0 - v1.4), the convention is to precede the key with a pattern matching
547 qr{\Ax_}i. Following this any character from the character class [-_a-zA-Z]
548 can be used. This clarification has been added to v2.0 of the specification.
549  
550 =item * identifier($self,$key,$value)
551  
552 Validates that key is in an acceptable format for the META.yml specification,
553 for an identifier, i.e. any that matches the regular expression
554 qr/[a-z][a-z_]/i.
555  
556 =item * module($self,$key,$value)
557  
558 Validates that a given key is in an acceptable module name format, e.g.
559 'Test::CPAN::Meta::YAML::Version'.
560  
561 =item * anything($self,$key,$value)
562  
563 Usually reserved for user defined structures, allowing them to be considered
564 valid without a need for a specification definition for the structure.
565  
566 =back
567  
568 =cut
569  
570 4 ▶sub header {
Subroutine header: called CC=4 SCAR=13.9
Pod documented
571 4 my ($self,$key,$value) = @_;
572 4 ▶ if(defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 3 1 4
573 3 ▶ return 1 if($value && $value =~ /^--- #YAML:1.0/);
Branch: 1 branch
BranchTrueFalseTotal
if $value and $value =~ /^--- #YAML:1.0/ 1 2 3
Condition100%3/3
$value and $value =~ /^--- #YAML:1.0/
!ll&&!rl&&r
111
MC/DC100%2/2
$value and $value =~ /^--- #YAML:1.0/
$value $value =~ /^--- #YAML:1.0/
Truth table100%3/3
A and B
A= $valueB= $value =~ /^--- #YAML:1.0/
ABresult
0X0
100
111
574 }
575 3 $self->_error( "file does not have a valid YAML header." );
576 3 return 0;
577 }
578  
579 28 ▶sub _uri_split {
Subroutine _uri_split: called CC=1 SCAR=0.0
580 28 return $_[0] =~ m,(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?,;
581 }
582  
583 30 ▶sub url {
Subroutine url: called CC=4 SCAR=13.9
Pod documented
584 30 my ($self,$key,$value) = @_;
585 30 ▶ if($value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value) { } 28 2 30
586 28 my ($scheme, $auth, $path, $query, $frag) = _uri_split($value);
587  
588 28 ▶ unless ( $scheme ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($scheme) 2 26 28
589 2 $self->_error( "'$value' for '$key' does not have a URL scheme" );
590 2 return 0;
591 }
592 26 ▶ unless ( $auth ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($auth) 4 22 26
593 4 $self->_error( "'$value' for '$key' does not have a URL authority" );
594 4 return 0;
595 }
596 22 return 1;
597 } else {
598 2 $value = '<undef>';
599 }
600 2 $self->_error( "'$value' for '$key' is not a valid URL." );
601 2 return 0;
602 }
603  
604 40 ▶sub urlspec {
Subroutine urlspec: called CC=6 SCAR=17.9
Pod documented
605 40 my ($self,$key,$value) = @_;
606 40 ▶ if(defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 39 1 40
607 39 ▶ return 1 if($value && $known_specs{$self->{spec}} eq $value);
Branch: 1 branch
BranchTrueFalseTotal
if $value and $known_specs{$self->{"spec"}} eq $value 31 8 39
Condition100%3/3
$value and $known_specs{$self->{"spec"}} eq $value
!ll&&!rl&&r
1731
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
608 8 ▶ if($value && $known_urls{$value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value and $known_urls{$value}) 6 2 8
Condition100%3/3
$value and $known_urls{$value}
!ll&&!rl&&r
116
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
609 6 $self->_error( 'META.yml specification URL does not match version' );
610 6 return 0;
611 }
612 }
613 3 $self->_error( 'Unknown META.yml specification' );
614 3 return 0;
615 }
616  
617 271 ▶sub string {
Subroutine string: called CC=4 SCAR=13.9
Pod documented
618 271 my ($self,$key,$value) = @_;
619 271 ▶ if(defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 270 1 271
620 270 ▶ return 1 if($value || $value =~ /^0$/);
Branch: 1 branch
BranchTrueFalseTotal
if $value or $value =~ /^0$/ 269 1 270
Condition100%3/3
$value or $value =~ /^0$/
l!l&&r!l&&!r
26811
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
621 }
622 2 $self->_error( "value is an undefined string" );
623 2 return 0;
624 }
625  
626 4 ▶sub string_or_undef {
Subroutine string_or_undef: called CC=4 SCAR=13.9
Pod documented
627 4 my ($self,$key,$value) = @_;
628 4 ▶ return 1 unless(defined $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 1 3 4
629 3 ▶ return 1 if($value || $value =~ /^0$/);
Branch: 1 branch
BranchTrueFalseTotal
if $value or $value =~ /^0$/ 2 1 3
Condition100%3/3
$value or $value =~ /^0$/
l!l&&r!l&&!r
111
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
630 1 $self->_error( "No string defined for '$key'" );
631 1 return 0;
632 }
633  
634 69 ▶sub file {
Subroutine file: called CC=2 SCAR=6.9
Pod documented
635 69 my ($self,$key,$value) = @_;
636 69 ▶ return 1 if(defined $value);
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 68 1 69
637 1 $self->_error( "No file defined for '$key'" );
638 1 return 0;
639 }
640  
641 301 ▶sub exversion {
Subroutine exversion: called CC=7 SCAR=19.5
Pod documented
642 301 my ($self,$key,$value) = @_;
643 301 ▶ if(defined $value && ($value || $value =~ /0/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and $value || $value =~ /0/) 298 3 301
Condition100%6/6
defined $value and $value || $value =~ /0/
!ll&&!rl&&r
21298
$value or $value =~ /0/
l!l&&r!l&&!r
252461
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
644 298 my $pass = 1;
645 298 ▶ for(split(",",$value)) { $self->version($key,$_) or ($pass = 0); }
Branch: 1 branch
BranchTrueFalseTotal
$self->version($key, $_) or $pass = 0 302 1 303
646 298 return $pass;
647 }
648 3 ▶ $value = '<undef>' unless(defined $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 2 1 3
649 3 $self->_error( "'$value' for '$key' is not a valid version." );
650 3 return 0;
651 }
652  
653 459 ▶sub version {
Subroutine version: called CC=5 SCAR=16.1
Pod documented
654 459 my ($self,$key,$value) = @_;
655 459 ▶ if(defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 457 2 459
656 457 ▶ return 0 unless($value || $value =~ /0/);
Branch: 1 branch
BranchTrueFalseTotal
unless $value or $value =~ /0/ 1 456 457
Condition100%3/3
$value or $value =~ /0/
l!l&&r!l&&!r
409471
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
657 456 ▶ return 1 if($value =~ /^\s*((<|<=|>=|>|!=|==)\s*)?v?\d+((\.\d+((_|\.)\d+)?)?)/);
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /^\s*((<|<=|>=|>|!=|==)\s*)?v?\d+((\.\d+((_|\.)\d+)?)?)/ 452 4 456
658 } else {
659 2 $value = '<undef>';
660 }
661 6 $self->_error( "'$value' for '$key' is not a valid version." );
662 6 return 0;
663 }
664  
665 8 ▶sub boolean {
Subroutine boolean: called CC=3 SCAR=11.0
Pod documented
666 8 my ($self,$key,$value) = @_;
667 8 ▶ if(defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 6 2 8
668 6 ▶ return 1 if($value =~ /^(0|1|true|false)$/);
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /^(0|1|true|false)$/ 4 2 6
669 } else {
670 2 $value = '<undef>';
671 }
672 4 $self->_error( "'$value' for '$key' is not a boolean value." );
673 4 return 0;
674 }
675  
676 10 my %licenses = (
677 'perl' => 'http://dev.perl.org/licenses/',
678 'gpl' => 'http://www.opensource.org/licenses/gpl-license.php',
679 'apache' => 'http://apache.org/licenses/LICENSE-2.0',
680 'artistic' => 'http://opensource.org/licenses/artistic-license.php',
681 'artistic2' => 'http://opensource.org/licenses/artistic-license-2.0.php',
682 'artistic-2.0' => 'http://opensource.org/licenses/artistic-license-2.0.php',
683 'lgpl' => 'http://www.opensource.org/licenses/lgpl-license.phpt',
684 'bsd' => 'http://www.opensource.org/licenses/bsd-license.php',
685 'gpl' => 'http://www.opensource.org/licenses/gpl-license.php',
686 'mit' => 'http://opensource.org/licenses/mit-license.php',
687 'mozilla' => 'http://opensource.org/licenses/mozilla1.1.php',
688 'open_source' => undef,
689 'unrestricted' => undef,
690 'restrictive' => undef,
691 'unknown' => undef,
692 );
693  
694 61 ▶sub license {
Subroutine license: called CC=5 SCAR=16.1
Pod documented
695 61 my ($self,$key,$value) = @_;
696 61 ▶ if(defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 60 1 61
697 60 ▶ return 1 if($value && exists $licenses{$value});
Branch: 1 branch
BranchTrueFalseTotal
if $value and exists $licenses{$value} 56 4 60
Condition100%3/3
$value and exists $licenses{$value}
!ll&&!rl&&r
1356
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
698 4 ▶ return 2 if($value);
Branch: 1 branch
BranchTrueFalseTotal
if $value 3 1 4
699 } else {
700 1 $value = '<undef>';
701 }
702 2 $self->_error( "License '$value' is unknown" );
703 2 return 0;
704 }
705  
706 7 ▶sub resource {
Subroutine resource: called CC=5 SCAR=16.1
Pod documented
707 7 my ($self,$key) = @_;
708 7 ▶ if(defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 6 1 7
709 # a valid user defined key should be alphabetic
710 # and contain at least one capital case letter.
711 6 ▶ 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]/ 4 2 6
Condition83%5/6
$key and $key =~ /^[a-z]+$/i and $key =~ /[A-Z]/
!ll&&!rl&&r
114
$key and $key =~ /^[a-z]+$/i
!ll&&!rl&&r
105
MC/DC66%2/3
$key and $key =~ /^[a-z]+$/i and $key =~ /[A-Z]/
$key $key =~ /^[a-z]+$/i $key =~ /[A-Z]/
Truth table75%3/4
A and B and C
A= $keyB= $key =~ /^[a-z]+$/iC= $key =~ /[A-Z]/
ABCresult
0XX0
10X0
1100
1111
712 } else {
713 1 $key = '<undef>';
714 }
715 3 $self->_error( "Resource '$key' must be in CamelCase." );
716 3 return 0;
717 }
718  
719 80 ▶sub keyword {
Subroutine keyword: called CC=6 SCAR=17.9
Pod documented
720 80 my ($self,$key) = @_;
721 80 ▶ if(defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 79 1 80
722 79 ▶ return 1 if($key && $key =~ /^([a-z][-_a-z]*)$/); # spec defined
Branch: 1 branch
BranchTrueFalseTotal
if $key and $key =~ /^([a-z][-_a-z]*)$/ 73 6 79
Condition100%3/3
$key and $key =~ /^([a-z][-_a-z]*)$/
!ll&&!rl&&r
1573
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
723 6 ▶ 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 1 5 6
Condition100%3/3
$key and $key =~ /^x_([a-z][-_a-z]*)$/i
!ll&&!rl&&r
141
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
724 } else {
725 1 $key = '<undef>';
726 }
727 6 $self->_error( "Key '$key' is not a legal keyword." );
728 6 return 0;
729 }
730  
731 13 ▶sub identifier {
Subroutine identifier: called CC=4 SCAR=13.9
Pod documented
732 13 my ($self,$key) = @_;
733 13 ▶ if(defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 12 1 13
734 12 ▶ 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 8 4 12
Condition100%3/3
$key and $key =~ /^([a-z][_a-z]+)$/i
!ll&&!rl&&r
138
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
735 } else {
736 1 $key = '<undef>';
737 }
738 5 $self->_error( "Key '$key' is not a legal identifier." );
739 5 return 0;
740 }
741  
742 370 ▶sub module {
Subroutine module: called CC=4 SCAR=13.9
Pod documented
743 370 my ($self,$key) = @_;
744 370 ▶ if(defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 369 1 370
745 369 ▶ 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_]+)*$/ 361 8 369
Condition100%3/3
$key and $key =~ /^[A-Za-z0-9_]+(::[A-Za-z0-9_]+)*$/
!ll&&!rl&&r
17361
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
746 } else {
747 1 $key = '<undef>';
748 }
749 9 $self->_error( "Key '$key' is not a legal module name." );
750 9 return 0;
751 }
752  
753 69 ▶sub anything { return 1 }
Subroutine anything: called CC=1 SCAR=0.0
Pod documented
754  
755 73 ▶sub _error {
Subroutine _error: called CC=2 SCAR=6.9
756 73 my $self = shift;
757 73 my $mess = shift;
758  
759 73 ▶ $mess .= ' ('.join(' -> ',@{$self->{stack}}).')' if($self->{stack});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"stack"} 25 48 73
760 73 $mess .= " [Validation: $self->{spec}]";
761  
762 73 push @{$self->{errors}}, $mess;
763 }
764  
765 10 q( This release is sponsored by Made In Love: Hand made gifts for your loved ones, friends or even a treat for your own home - http://madeinlove.co.uk );
766  
767 __END__
↑ Summary YAML.pm »