CPAN/Meta/Validator.pm

filter: Statementstmt 68.9% 151 / 219 Branchbran 53.1% 67 / 126 Conditioncond 37.1% 23 / 62 MC/DCmcdc 10.5% 4 / 38 Subroutinesub 89.2% 25 / 28 Podpod 13.0% 3 / 23 totaltotal 55.0% 273 / 496 CC 90 SCAR 24.5
CC
90
Cov
59%
check_list
22.5
header
20.0
string_or_undef
20.0
CRAP 11.6
↑ Summary Parse/CPAN/Meta.pm »
1 22 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 22 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 package CPAN::Meta::Validator;
5  
6 22 our $VERSION = '2.150015';
7  
8 #pod =head1 SYNOPSIS
9 #pod
10 #pod my $struct = Parse::CPAN::Meta->load_file('META.json');
11 #pod my $cmv = CPAN::Meta::Validator->new( $struct );
12 #pod
13 #pod unless ( $cmv->is_valid ) {
14 #pod my $msg = "Invalid META structure. Errors found:\n";
15 #pod $msg .= join( "\n", $cmv->errors );
16 #pod die $msg;
17 #pod }
18 #pod
19 #pod =head1 DESCRIPTION
20 #pod
21 #pod This module validates a CPAN Meta structure against the version of the
22 #pod the specification claimed in the C<meta-spec> field of the structure.
23 #pod
24 #pod =cut
25  
26 #--------------------------------------------------------------------------#
27 # This code copied and adapted from Test::CPAN::Meta
28 # by Barbie, <barbie@cpan.org> for Miss Barbell Productions,
29 # L<http://www.missbarbell.co.uk>
30 #--------------------------------------------------------------------------#
31  
32 #--------------------------------------------------------------------------#
33 # Specification Definitions
34 #--------------------------------------------------------------------------#
35  
36 22 my %known_specs = (
37 '1.4' => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
38 '1.3' => 'http://module-build.sourceforge.net/META-spec-v1.3.html',
39 '1.2' => 'http://module-build.sourceforge.net/META-spec-v1.2.html',
40 '1.1' => 'http://module-build.sourceforge.net/META-spec-v1.1.html',
41 '1.0' => 'http://module-build.sourceforge.net/META-spec-v1.0.html'
42 );
43 22 my %known_urls = map {$known_specs{$_} => $_} keys %known_specs;
44  
45 22 my $module_map1 = { 'map' => { ':key' => { name => \&module, value => \&exversion } } };
46  
47 22 my $module_map2 = { 'map' => { ':key' => { name => \&module, value => \&version } } };
48  
49 22 my $no_index_2 = {
50 'map' => { file => { list => { value => \&string } },
51 directory => { list => { value => \&string } },
52 'package' => { list => { value => \&string } },
53 namespace => { list => { value => \&string } },
54 ':key' => { name => \&custom_2, value => \&anything },
55 }
56 };
57  
58 22 my $no_index_1_3 = {
59 'map' => { file => { list => { value => \&string } },
60 directory => { list => { value => \&string } },
61 'package' => { list => { value => \&string } },
62 namespace => { list => { value => \&string } },
63 ':key' => { name => \&string, value => \&anything },
64 }
65 };
66  
67 22 my $no_index_1_2 = {
68 'map' => { file => { list => { value => \&string } },
69 dir => { list => { value => \&string } },
70 'package' => { list => { value => \&string } },
71 namespace => { list => { value => \&string } },
72 ':key' => { name => \&string, value => \&anything },
73 }
74 };
75  
76 22 my $no_index_1_1 = {
77 'map' => { ':key' => { name => \&string, list => { value => \&string } },
78 }
79 };
80  
81 22 my $prereq_map = {
82 map => {
83 ':key' => {
84 name => \&phase,
85 'map' => {
86 ':key' => {
87 name => \&relation,
88 %$module_map1,
89 },
90 },
91 }
92 },
93 };
94  
95 22 my %definitions = (
96 '2' => {
97 # REQUIRED
98 'abstract' => { mandatory => 1, value => \&string },
99 'author' => { mandatory => 1, list => { value => \&string } },
100 'dynamic_config' => { mandatory => 1, value => \&boolean },
101 'generated_by' => { mandatory => 1, value => \&string },
102 'license' => { mandatory => 1, list => { value => \&license } },
103 'meta-spec' => {
104 mandatory => 1,
105 'map' => {
106 version => { mandatory => 1, value => \&version},
107 url => { value => \&url },
108 ':key' => { name => \&custom_2, value => \&anything },
109 }
110 },
111 'name' => { mandatory => 1, value => \&string },
112 'release_status' => { mandatory => 1, value => \&release_status },
113 'version' => { mandatory => 1, value => \&version },
114  
115 # OPTIONAL
116 'description' => { value => \&string },
117 'keywords' => { list => { value => \&string } },
118 'no_index' => $no_index_2,
119 'optional_features' => {
120 'map' => {
121 ':key' => {
122 name => \&string,
123 'map' => {
124 description => { value => \&string },
125 prereqs => $prereq_map,
126 ':key' => { name => \&custom_2, value => \&anything },
127 }
128 }
129 }
130 },
131 'prereqs' => $prereq_map,
132 'provides' => {
133 'map' => {
134 ':key' => {
135 name => \&module,
136 'map' => {
137 file => { mandatory => 1, value => \&file },
138 version => { value => \&version },
139 ':key' => { name => \&custom_2, value => \&anything },
140 }
141 }
142 }
143 },
144 'resources' => {
145 'map' => {
146 license => { list => { value => \&url } },
147 homepage => { value => \&url },
148 bugtracker => {
149 'map' => {
150 web => { value => \&url },
151 mailto => { value => \&string},
152 ':key' => { name => \&custom_2, value => \&anything },
153 }
154 },
155 repository => {
156 'map' => {
157 web => { value => \&url },
158 url => { value => \&url },
159 type => { value => \&string },
160 ':key' => { name => \&custom_2, value => \&anything },
161 }
162 },
163 ':key' => { value => \&string, name => \&custom_2 },
164 }
165 },
166  
167 # CUSTOM -- additional user defined key/value pairs
168 # note we can only validate the key name, as the structure is user defined
169 ':key' => { name => \&custom_2, value => \&anything },
170 },
171  
172 '1.4' => {
173 'meta-spec' => {
174 mandatory => 1,
175 'map' => {
176 version => { mandatory => 1, value => \&version},
177 url => { mandatory => 1, value => \&urlspec },
178 ':key' => { name => \&string, value => \&anything },
179 },
180 },
181  
182 'name' => { mandatory => 1, value => \&string },
183 'version' => { mandatory => 1, value => \&version },
184 'abstract' => { mandatory => 1, value => \&string },
185 'author' => { mandatory => 1, list => { value => \&string } },
186 'license' => { mandatory => 1, value => \&license },
187 'generated_by' => { mandatory => 1, value => \&string },
188  
189 'distribution_type' => { value => \&string },
190 'dynamic_config' => { value => \&boolean },
191  
192 'requires' => $module_map1,
193 'recommends' => $module_map1,
194 'build_requires' => $module_map1,
195 'configure_requires' => $module_map1,
196 'conflicts' => $module_map2,
197  
198 'optional_features' => {
199 'map' => {
200 ':key' => { name => \&string,
201 'map' => { description => { value => \&string },
202 requires => $module_map1,
203 recommends => $module_map1,
204 build_requires => $module_map1,
205 conflicts => $module_map2,
206 ':key' => { name => \&string, value => \&anything },
207 }
208 }
209 }
210 },
211  
212 'provides' => {
213 'map' => {
214 ':key' => { name => \&module,
215 'map' => {
216 file => { mandatory => 1, value => \&file },
217 version => { value => \&version },
218 ':key' => { name => \&string, value => \&anything },
219 }
220 }
221 }
222 },
223  
224 'no_index' => $no_index_1_3,
225 'private' => $no_index_1_3,
226  
227 'keywords' => { list => { value => \&string } },
228  
229 'resources' => {
230 'map' => { license => { value => \&url },
231 homepage => { value => \&url },
232 bugtracker => { value => \&url },
233 repository => { value => \&url },
234 ':key' => { value => \&string, name => \&custom_1 },
235 }
236 },
237  
238 # additional user defined key/value pairs
239 # note we can only validate the key name, as the structure is user defined
240 ':key' => { name => \&string, value => \&anything },
241 },
242  
243 '1.3' => {
244 'meta-spec' => {
245 mandatory => 1,
246 'map' => {
247 version => { mandatory => 1, value => \&version},
248 url => { mandatory => 1, value => \&urlspec },
249 ':key' => { name => \&string, value => \&anything },
250 },
251 },
252  
253 'name' => { mandatory => 1, value => \&string },
254 'version' => { mandatory => 1, value => \&version },
255 'abstract' => { mandatory => 1, value => \&string },
256 'author' => { mandatory => 1, list => { value => \&string } },
257 'license' => { mandatory => 1, value => \&license },
258 'generated_by' => { mandatory => 1, value => \&string },
259  
260 'distribution_type' => { value => \&string },
261 'dynamic_config' => { value => \&boolean },
262  
263 'requires' => $module_map1,
264 'recommends' => $module_map1,
265 'build_requires' => $module_map1,
266 'conflicts' => $module_map2,
267  
268 'optional_features' => {
269 'map' => {
270 ':key' => { name => \&string,
271 'map' => { description => { value => \&string },
272 requires => $module_map1,
273 recommends => $module_map1,
274 build_requires => $module_map1,
275 conflicts => $module_map2,
276 ':key' => { name => \&string, value => \&anything },
277 }
278 }
279 }
280 },
281  
282 'provides' => {
283 'map' => {
284 ':key' => { name => \&module,
285 'map' => {
286 file => { mandatory => 1, value => \&file },
287 version => { value => \&version },
288 ':key' => { name => \&string, value => \&anything },
289 }
290 }
291 }
292 },
293  
294  
295 'no_index' => $no_index_1_3,
296 'private' => $no_index_1_3,
297  
298 'keywords' => { list => { value => \&string } },
299  
300 'resources' => {
301 'map' => { license => { value => \&url },
302 homepage => { value => \&url },
303 bugtracker => { value => \&url },
304 repository => { value => \&url },
305 ':key' => { value => \&string, name => \&custom_1 },
306 }
307 },
308  
309 # additional user defined key/value pairs
310 # note we can only validate the key name, as the structure is user defined
311 ':key' => { name => \&string, value => \&anything },
312 },
313  
314 # v1.2 is misleading, it seems to assume that a number of fields where created
315 # within v1.1, when they were created within v1.2. This may have been an
316 # original mistake, and that a v1.1 was retro fitted into the timeline, when
317 # v1.2 was originally slated as v1.1. But I could be wrong ;)
318 '1.2' => {
319 'meta-spec' => {
320 mandatory => 1,
321 'map' => {
322 version => { mandatory => 1, value => \&version},
323 url => { mandatory => 1, value => \&urlspec },
324 ':key' => { name => \&string, value => \&anything },
325 },
326 },
327  
328  
329 'name' => { mandatory => 1, value => \&string },
330 'version' => { mandatory => 1, value => \&version },
331 'license' => { mandatory => 1, value => \&license },
332 'generated_by' => { mandatory => 1, value => \&string },
333 'author' => { mandatory => 1, list => { value => \&string } },
334 'abstract' => { mandatory => 1, value => \&string },
335  
336 'distribution_type' => { value => \&string },
337 'dynamic_config' => { value => \&boolean },
338  
339 'keywords' => { list => { value => \&string } },
340  
341 'private' => $no_index_1_2,
342 '$no_index' => $no_index_1_2,
343  
344 'requires' => $module_map1,
345 'recommends' => $module_map1,
346 'build_requires' => $module_map1,
347 'conflicts' => $module_map2,
348  
349 'optional_features' => {
350 'map' => {
351 ':key' => { name => \&string,
352 'map' => { description => { value => \&string },
353 requires => $module_map1,
354 recommends => $module_map1,
355 build_requires => $module_map1,
356 conflicts => $module_map2,
357 ':key' => { name => \&string, value => \&anything },
358 }
359 }
360 }
361 },
362  
363 'provides' => {
364 'map' => {
365 ':key' => { name => \&module,
366 'map' => {
367 file => { mandatory => 1, value => \&file },
368 version => { value => \&version },
369 ':key' => { name => \&string, value => \&anything },
370 }
371 }
372 }
373 },
374  
375 'resources' => {
376 'map' => { license => { value => \&url },
377 homepage => { value => \&url },
378 bugtracker => { value => \&url },
379 repository => { value => \&url },
380 ':key' => { value => \&string, name => \&custom_1 },
381 }
382 },
383  
384 # additional user defined key/value pairs
385 # note we can only validate the key name, as the structure is user defined
386 ':key' => { name => \&string, value => \&anything },
387 },
388  
389 # note that the 1.1 spec only specifies 'version' as mandatory
390 '1.1' => {
391 'name' => { value => \&string },
392 'version' => { mandatory => 1, value => \&version },
393 'license' => { value => \&license },
394 'generated_by' => { value => \&string },
395  
396 'license_uri' => { value => \&url },
397 'distribution_type' => { value => \&string },
398 'dynamic_config' => { value => \&boolean },
399  
400 'private' => $no_index_1_1,
401  
402 'requires' => $module_map1,
403 'recommends' => $module_map1,
404 'build_requires' => $module_map1,
405 'conflicts' => $module_map2,
406  
407 # additional user defined key/value pairs
408 # note we can only validate the key name, as the structure is user defined
409 ':key' => { name => \&string, value => \&anything },
410 },
411  
412 # note that the 1.0 spec doesn't specify optional or mandatory fields
413 # but we will treat version as mandatory since otherwise META 1.0 is
414 # completely arbitrary and pointless
415 '1.0' => {
416 'name' => { value => \&string },
417 'version' => { mandatory => 1, value => \&version },
418 'license' => { value => \&license },
419 'generated_by' => { value => \&string },
420  
421 'license_uri' => { value => \&url },
422 'distribution_type' => { value => \&string },
423 'dynamic_config' => { value => \&boolean },
424  
425 'requires' => $module_map1,
426 'recommends' => $module_map1,
427 'build_requires' => $module_map1,
428 'conflicts' => $module_map2,
429  
430 # additional user defined key/value pairs
431 # note we can only validate the key name, as the structure is user defined
432 ':key' => { name => \&string, value => \&anything },
433 },
434 );
435  
436 #--------------------------------------------------------------------------#
437 # Code
438 #--------------------------------------------------------------------------#
439  
440 #pod =method new
441 #pod
442 #pod my $cmv = CPAN::Meta::Validator->new( $struct )
443 #pod
444 #pod The constructor must be passed a metadata structure.
445 #pod
446 #pod =cut
447  
448 722 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
449 722 my ($class,$data) = @_;
450  
451 # create an attributes hash
452 my $self = {
453 'data' => $data,
454 722 ▶ 'spec' => eval { $data->{'meta-spec'}{'version'} } || "1.0",
Condition100%2/2
eval { do { $data->{'meta-spec'}{'version'} } } || '1.0'
l!l
68933
MC/DC100%1/1
eval { do { $data->{'meta-spec'}{'version'} } } || '1.0'
eval { do { $data->{'meta-spec'}{'version'} } }
Truth table100%2/2
A
A= eval { do { $data->{'meta-spec'}{'version'} } }
Aresult
11
00
455 'errors' => undef,
456 };
457  
458 # create the object
459 722 return bless $self, $class;
460 }
461  
462 #pod =method is_valid
463 #pod
464 #pod if ( $cmv->is_valid ) {
465 #pod ...
466 #pod }
467 #pod
468 #pod Returns a boolean value indicating whether the metadata provided
469 #pod is valid.
470 #pod
471 #pod =cut
472  
473 722 ▶sub is_valid {
Subroutine is_valid: called CC=1 SCAR=0.0
Pod documented
474 722 my $self = shift;
475 722 my $data = $self->{data};
476 722 my $spec_version = $self->{spec};
477 722 $self->check_map($definitions{$spec_version},$data);
478 722 return ! $self->errors;
479 }
480  
481 #pod =method errors
482 #pod
483 #pod warn( join "\n", $cmv->errors );
484 #pod
485 #pod Returns a list of errors seen during validation.
486 #pod
487 #pod =cut
488  
489 757 ▶sub errors {
Subroutine errors: called CC=2 SCAR=6.9
Pod documented
490 757 my $self = shift;
491 757 ▶ return () unless(defined $self->{errors});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"errors"} 687 70 757
492 70 return @{$self->{errors}};
493 }
494  
495 #pod =begin :internals
496 #pod
497 #pod =head2 Check Methods
498 #pod
499 #pod =over
500 #pod
501 #pod =item *
502 #pod
503 #pod check_map($spec,$data)
504 #pod
505 #pod Checks whether a map (or hash) part of the data structure conforms to the
506 #pod appropriate specification definition.
507 #pod
508 #pod =item *
509 #pod
510 #pod check_list($spec,$data)
511 #pod
512 #pod Checks whether a list (or array) part of the data structure conforms to
513 #pod the appropriate specification definition.
514 #pod
515 #pod =item *
516 #pod
517 #pod =back
518 #pod
519 #pod =cut
520  
521 22 my $spec_error = "Missing validation action in specification. "
522 . "Must be one of 'map', 'list', or 'value'";
523  
524 7382 ▶sub check_map {
Subroutine check_map: called CC=15 SCAR=27.7
Pod undocumented
525 7382 my ($self,$spec,$data) = @_;
526  
527 7382 ▶ if(ref($spec) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $spec ne "HASH") 4 7378 7382
528 4 $self->_error( "Unknown META specification, cannot validate." );
529 4 return;
530 }
531  
532 7378 ▶ if(ref($data) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data ne "HASH") 2 7376 7378
533 2 $self->_error( "Expected a map structure from string or file." );
534 2 return;
535 }
536  
537 7376 for my $key (keys %$spec) {
538 28419 ▶ next unless($spec->{$key}->{mandatory});
Branch: 1 branch
BranchTrueFalseTotal
unless $spec->{$key}{"mandatory"} 20413 8006 28419
539 8006 ▶ next if(defined $data->{$key});
Branch: 1 branch
BranchTrueFalseTotal
if defined $data->{$key} 7984 22 8006
540 22 push @{$self->{stack}}, $key;
541 22 $self->_error( "Missing mandatory field, '$key'" );
542 22 pop @{$self->{stack}};
543 }
544  
545 7376 for my $key (keys %$data) {
546 31025 push @{$self->{stack}}, $key;
547 31025 ▶ if($spec->{$key}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($spec->{$key}) { } 15273 15752 31025
elsif ($spec->{':key'}) { } 15752 0 15752
548 15273 ▶ if($spec->{$key}{value}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($spec->{$key}{'value'}) { } 11394 3879 15273
elsif ($spec->{$key}{'map'}) { } 2779 1100 3879
elsif ($spec->{$key}{'list'}) { } 1100 0 1100
549 11394 $spec->{$key}{value}->($self,$key,$data->{$key});
550 } elsif($spec->{$key}{'map'}) {
551 2779 $self->check_map($spec->{$key}{'map'},$data->{$key});
552 } elsif($spec->{$key}{'list'}) {
553 1100 $self->check_list($spec->{$key}{'list'},$data->{$key});
554 } else {
555 0 $self->_error( "$spec_error for '$key'" );
556 }
557  
558 } elsif ($spec->{':key'}) {
559 15752 $spec->{':key'}{name}->($self,$key,$key);
560 15752 ▶ if($spec->{':key'}{value}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($spec->{':key'}{'value'}) { } 11871 3881 15752
elsif ($spec->{':key'}{'map'}) { } 3881 0 3881
elsif ($spec->{':key'}{'list'}) { } 0 0 0
561 11871 $spec->{':key'}{value}->($self,$key,$data->{$key});
562 } elsif($spec->{':key'}{'map'}) {
563 3881 $self->check_map($spec->{':key'}{'map'},$data->{$key});
564 } elsif($spec->{':key'}{'list'}) {
565 0 $self->check_list($spec->{':key'}{'list'},$data->{$key});
566 } else {
567 0 $self->_error( "$spec_error for ':key'" );
568 }
569  
570  
571 } else {
572 0 $self->_error( "Unknown key, '$key', found in map structure" );
573 }
574 31025 pop @{$self->{stack}};
575 }
576 }
577  
578 1100 ▶sub check_list {
Subroutine check_list: called CC=10 SCAR=31.1
Pod undocumented
579 1100 my ($self,$spec,$data) = @_;
580  
581 1100 ▶ if(ref($data) ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data ne "ARRAY") 2 1098 1100
582 2 $self->_error( "Expected a list structure" );
583 2 return;
584 }
585  
586 1098 ▶ if(defined $spec->{mandatory}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $spec->{"mandatory"}) 0 1098 1098
587 0 ▶ if(!defined $data->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data->[0]) 0 0 0
588 0 $self->_error( "Missing entries from mandatory list" );
589 }
590 }
591  
592 1098 for my $value (@$data) {
593 1949 ▶ push @{$self->{stack}}, $value || "<undef>";
Condition50%1/2
$value || '<undef>'
l!l
19490
MC/DC0%0/1
$value || '<undef>'
$value
Truth table50%1/2
A
A= $value
Aresult
11
00
594 1949 ▶ if(defined $spec->{value}) {
Branch: 4 branches
BranchTrueFalseTotal
if (defined $spec->{'value'}) { } 1949 0 1949
elsif (defined $spec->{'map'}) { } 0 0 0
elsif (defined $spec->{'list'}) { } 0 0 0
elsif ($spec->{':key'}) { } 0 0 0
595 1949 $spec->{value}->($self,'list',$value);
596 } elsif(defined $spec->{'map'}) {
597 0 $self->check_map($spec->{'map'},$value);
598 } elsif(defined $spec->{'list'}) {
599 0 $self->check_list($spec->{'list'},$value);
600 } elsif ($spec->{':key'}) {
601 0 $self->check_map($spec,$value);
602 } else {
603 0 $self->_error( "$spec_error associated with '$self->{stack}[-2]'" );
604 }
605 1949 pop @{$self->{stack}};
606 }
607 }
608  
609 #pod =head2 Validator Methods
610 #pod
611 #pod =over
612 #pod
613 #pod =item *
614 #pod
615 #pod header($self,$key,$value)
616 #pod
617 #pod Validates that the header is valid.
618 #pod
619 #pod Note: No longer used as we now read the data structure, not the file.
620 #pod
621 #pod =item *
622 #pod
623 #pod url($self,$key,$value)
624 #pod
625 #pod Validates that a given value is in an acceptable URL format
626 #pod
627 #pod =item *
628 #pod
629 #pod urlspec($self,$key,$value)
630 #pod
631 #pod Validates that the URL to a META specification is a known one.
632 #pod
633 #pod =item *
634 #pod
635 #pod string_or_undef($self,$key,$value)
636 #pod
637 #pod Validates that the value is either a string or an undef value. Bit of a
638 #pod catchall function for parts of the data structure that are completely user
639 #pod defined.
640 #pod
641 #pod =item *
642 #pod
643 #pod string($self,$key,$value)
644 #pod
645 #pod Validates that a string exists for the given key.
646 #pod
647 #pod =item *
648 #pod
649 #pod file($self,$key,$value)
650 #pod
651 #pod Validate that a file is passed for the given key. This may be made more
652 #pod thorough in the future. For now it acts like \&string.
653 #pod
654 #pod =item *
655 #pod
656 #pod exversion($self,$key,$value)
657 #pod
658 #pod Validates a list of versions, e.g. '<= 5, >=2, ==3, !=4, >1, <6, 0'.
659 #pod
660 #pod =item *
661 #pod
662 #pod version($self,$key,$value)
663 #pod
664 #pod Validates a single version string. Versions of the type '5.8.8' and '0.00_00'
665 #pod are both valid. A leading 'v' like 'v1.2.3' is also valid.
666 #pod
667 #pod =item *
668 #pod
669 #pod boolean($self,$key,$value)
670 #pod
671 #pod Validates for a boolean value: a defined value that is either "1" or "0" or
672 #pod stringifies to those values.
673 #pod
674 #pod =item *
675 #pod
676 #pod license($self,$key,$value)
677 #pod
678 #pod Validates that a value is given for the license. Returns 1 if an known license
679 #pod type, or 2 if a value is given but the license type is not a recommended one.
680 #pod
681 #pod =item *
682 #pod
683 #pod custom_1($self,$key,$value)
684 #pod
685 #pod Validates that the given key is in CamelCase, to indicate a user defined
686 #pod keyword and only has characters in the class [-_a-zA-Z]. In version 1.X
687 #pod of the spec, this was only explicitly stated for 'resources'.
688 #pod
689 #pod =item *
690 #pod
691 #pod custom_2($self,$key,$value)
692 #pod
693 #pod Validates that the given key begins with 'x_' or 'X_', to indicate a user
694 #pod defined keyword and only has characters in the class [-_a-zA-Z]
695 #pod
696 #pod =item *
697 #pod
698 #pod identifier($self,$key,$value)
699 #pod
700 #pod Validates that key is in an acceptable format for the META specification,
701 #pod for an identifier, i.e. any that matches the regular expression
702 #pod qr/[a-z][a-z_]/i.
703 #pod
704 #pod =item *
705 #pod
706 #pod module($self,$key,$value)
707 #pod
708 #pod Validates that a given key is in an acceptable module name format, e.g.
709 #pod 'Test::CPAN::Meta::Version'.
710 #pod
711 #pod =back
712 #pod
713 #pod =end :internals
714 #pod
715 #pod =cut
716  
717 0 ▶sub header {
Subroutine header: not called CC=4 SCAR=30.0
Pod undocumented
718 0 my ($self,$key,$value) = @_;
719 0 ▶ if(defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 0 0
720 0 ▶ return 1 if($value && $value =~ /^--- #YAML:1.0/);
Branch: 1 branch
BranchTrueFalseTotal
if $value and $value =~ /^--- #YAML:1.0/ 0 0 0
Condition0%0/3
$value and $value =~ /^--- #YAML:1.0/
!ll&&!rl&&r
000
MC/DC0%0/2
$value and $value =~ /^--- #YAML:1.0/
$value $value =~ /^--- #YAML:1.0/
Truth table0%0/3
A and B
A= $valueB= $value =~ /^--- #YAML:1.0/
ABresult
0X0
100
111
721 }
722 0 $self->_error( "file does not have a valid YAML header." );
723 0 return 0;
724 }
725  
726 181 ▶sub release_status {
Subroutine release_status: called CC=6 SCAR=20.2
Pod undocumented
727 181 my ($self,$key,$value) = @_;
728 181 ▶ if(defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 181 0 181
729 181 ▶ my $version = $self->{data}{version} || '';
Condition100%2/2
$self->{'data'}{'version'} || ''
l!l
1792
MC/DC100%1/1
$self->{'data'}{'version'} || ''
$self->{'data'}{'version'}
Truth table100%2/2
A
A= $self->{'data'}{'version'}
Aresult
11
00
730 181 ▶ if ( $version =~ /_/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version =~ /_/) { } 22 159 181
731 22 ▶ return 1 if ( $value =~ /\A(?:testing|unstable)\z/ );
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /\A(?:testing|unstable)\z/ 22 0 22
732 0 $self->_error( "'$value' for '$key' is invalid for version '$version'" );
733 }
734 else {
735 159 ▶ return 1 if ( $value =~ /\A(?:stable|testing|unstable)\z/ );
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /\A(?:stable|testing|unstable)\z/ 159 0 159
736 0 $self->_error( "'$value' for '$key' is invalid" );
737 }
738 }
739 else {
740 0 $self->_error( "'$key' is not defined" );
741 }
742 0 return 0;
743 }
744  
745 # _uri_split taken from URI::Split by Gisle Aas, Copyright 2003
746 824 ▶sub _uri_split {
Subroutine _uri_split: called CC=1 SCAR=0.0
747 824 return $_[0] =~ m,(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?,;
748 }
749  
750 824 ▶sub url {
Subroutine url: called CC=7 SCAR=28.4
Pod undocumented
751 824 my ($self,$key,$value) = @_;
752 824 ▶ if(defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 824 0 824
753 824 my ($scheme, $auth, $path, $query, $frag) = _uri_split($value);
754 824 ▶ unless ( defined $scheme && length $scheme ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $scheme and length $scheme) 0 824 824
Condition33%1/3
defined $scheme and length $scheme
!ll&&!rl&&r
00824
MC/DC0%0/2
defined $scheme and length $scheme
defined $scheme length $scheme
Truth table33%1/3
A and B
A= defined $schemeB= length $scheme
ABresult
0X0
100
111
755 0 $self->_error( "'$value' for '$key' does not have a URL scheme" );
756 0 return 0;
757 }
758 824 ▶ unless ( defined $auth && length $auth ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $auth and length $auth) 0 824 824
Condition33%1/3
defined $auth and length $auth
!ll&&!rl&&r
00824
MC/DC0%0/2
defined $auth and length $auth
defined $auth length $auth
Truth table33%1/3
A and B
A= defined $authB= length $auth
ABresult
0X0
100
111
759 0 $self->_error( "'$value' for '$key' does not have a URL authority" );
760 0 return 0;
761 }
762 824 return 1;
763 }
764 0 ▶ $value ||= '';
Condition0%0/2
$value ||= ""
l!l
00
MC/DC0%0/1
$value ||= ""
$value
Truth table0%0/2
A
A= $value
Aresult
11
00
765 0 $self->_error( "'$value' for '$key' is not a valid URL." );
766 0 return 0;
767 }
768  
769 380 ▶sub urlspec {
Subroutine urlspec: called CC=6 SCAR=29.1
Pod undocumented
770 380 my ($self,$key,$value) = @_;
771 380 ▶ if(defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 380 0 380
772 380 ▶ return 1 if($value && $known_specs{$self->{spec}} eq $value);
Branch: 1 branch
BranchTrueFalseTotal
if $value and $known_specs{$self->{"spec"}} eq $value 380 0 380
Condition33%1/3
$value and $known_specs{$self->{"spec"}} eq $value
!ll&&!rl&&r
00380
MC/DC0%0/2
$value and $known_specs{$self->{"spec"}} eq $value
$value $known_specs{$self->{"spec"}} eq $value
Truth table33%1/3
A and B
A= $valueB= $known_specs{$self->{"spec"}} eq $value
ABresult
0X0
100
111
773 0 ▶ if($value && $known_urls{$value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value and $known_urls{$value}) 0 0 0
Condition0%0/3
$value and $known_urls{$value}
!ll&&!rl&&r
000
MC/DC0%0/2
$value and $known_urls{$value}
$value $known_urls{$value}
Truth table0%0/3
A and B
A= $valueB= $known_urls{$value}
ABresult
0X0
100
111
774 0 $self->_error( 'META specification URL does not match version' );
775 0 return 0;
776 }
777 }
778 0 $self->_error( 'Unknown META specification' );
779 0 return 0;
780 }
781  
782 1149 ▶sub anything { return 1 }
Subroutine anything: called CC=1 SCAR=0.0
Pod undocumented
783  
784 5280 ▶sub string {
Subroutine string: called CC=4 SCAR=13.9
Pod undocumented
785 5280 my ($self,$key,$value) = @_;
786 5280 ▶ if(defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 5279 1 5280
787 5279 ▶ return 1 if($value || $value =~ /^0$/);
Branch: 1 branch
BranchTrueFalseTotal
if $value or $value =~ /^0$/ 5278 1 5279
Condition66%2/3
$value or $value =~ /^0$/
l!l&&r!l&&!r
527801
MC/DC50%1/2
$value or $value =~ /^0$/
$value $value =~ /^0$/
Truth table66%2/3
A or B
A= $valueB= $value =~ /^0$/
ABresult
1X1
011
000
788 }
789 2 $self->_error( "value is an undefined string" );
790 2 return 0;
791 }
792  
793 0 ▶sub string_or_undef {
Subroutine string_or_undef: not called CC=4 SCAR=30.0
Pod undocumented
794 0 my ($self,$key,$value) = @_;
795 0 ▶ return 1 unless(defined $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
796 0 ▶ return 1 if($value || $value =~ /^0$/);
Branch: 1 branch
BranchTrueFalseTotal
if $value or $value =~ /^0$/ 0 0 0
Condition0%0/3
$value or $value =~ /^0$/
l!l&&r!l&&!r
000
MC/DC0%0/2
$value or $value =~ /^0$/
$value $value =~ /^0$/
Truth table0%0/3
A or B
A= $valueB= $value =~ /^0$/
ABresult
1X1
011
000
797 0 $self->_error( "No string defined for '$key'" );
798 0 return 0;
799 }
800  
801 2619 ▶sub file {
Subroutine file: called CC=2 SCAR=9.2
Pod undocumented
802 2619 my ($self,$key,$value) = @_;
803 2619 ▶ return 1 if(defined $value);
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 2619 0 2619
804 0 $self->_error( "No file defined for '$key'" );
805 0 return 0;
806 }
807  
808 10580 ▶sub exversion {
Subroutine exversion: called CC=7 SCAR=23.8
Pod undocumented
809 10580 my ($self,$key,$value) = @_;
810 10580 ▶ if(defined $value && ($value || $value =~ /0/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and $value || $value =~ /0/) 10580 0 10580
Condition50%3/6
defined $value and $value || $value =~ /0/
!ll&&!rl&&r
0010580
$value or $value =~ /0/
l!l&&r!l&&!r
413964410
MC/DC0%0/3
defined $value and $value || $value =~ /0/
defined $value $value $value =~ /0/
Truth table50%2/4
A and B or C
A= defined $valueB= $valueC= $value =~ /0/
ABCresult
0XX0
1000
11X1
1011
811 10580 my $pass = 1;
812 10580 ▶ for(split(",",$value)) { $self->version($key,$_) or ($pass = 0); }
Branch: 1 branch
BranchTrueFalseTotal
$self->version($key, $_) or $pass = 0 10638 12 10650
813 10580 return $pass;
814 }
815 0 ▶ $value = '<undef>' unless(defined $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
816 0 $self->_error( "'$value' for '$key' is not a valid version." );
817 0 return 0;
818 }
819  
820 14468 ▶sub version {
Subroutine version: called CC=5 SCAR=16.8
Pod undocumented
821 14468 my ($self,$key,$value) = @_;
822 14468 ▶ if(defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 14468 0 14468
823 14468 ▶ return 0 unless($value || $value =~ /0/);
Branch: 1 branch
BranchTrueFalseTotal
unless $value or $value =~ /0/ 0 14468 14468
Condition66%2/3
$value or $value =~ /0/
l!l&&r!l&&!r
776667020
MC/DC0%0/2
$value or $value =~ /0/
$value $value =~ /0/
Truth table66%2/3
A or B
A= $valueB= $value =~ /0/
ABresult
1X1
011
000
824 14468 ▶ return 1 if($value =~ /^\s*((<|<=|>=|>|!=|==)\s*)?v?\d+((\.\d+((_|\.)\d+)?)?)/);
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /^\s*((<|<=|>=|>|!=|==)\s*)?v?\d+((\.\d+((_|\.)\d+)?)?)/ 14456 12 14468
825 } else {
826 0 $value = '<undef>';
827 }
828 12 $self->_error( "'$value' for '$key' is not a valid version." );
829 12 return 0;
830 }
831  
832 685 ▶sub boolean {
Subroutine boolean: called CC=3 SCAR=14.2
Pod undocumented
833 685 my ($self,$key,$value) = @_;
834 685 ▶ if(defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 685 0 685
835 685 ▶ return 1 if($value =~ /^(0|1)$/);
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /^(0|1)$/ 685 0 685
836 } else {
837 0 $value = '<undef>';
838 }
839 0 $self->_error( "'$value' for '$key' is not a boolean value." );
840 0 return 0;
841 }
842  
843 22 my %v1_licenses = (
844 'perl' => 'http://dev.perl.org/licenses/',
845 'gpl' => 'http://www.opensource.org/licenses/gpl-license.php',
846 'apache' => 'http://apache.org/licenses/LICENSE-2.0',
847 'artistic' => 'http://opensource.org/licenses/artistic-license.php',
848 'artistic_2' => 'http://opensource.org/licenses/artistic-license-2.0.php',
849 'lgpl' => 'http://www.opensource.org/licenses/lgpl-license.php',
850 'bsd' => 'http://www.opensource.org/licenses/bsd-license.php',
851 'gpl' => 'http://www.opensource.org/licenses/gpl-license.php',
852 'mit' => 'http://opensource.org/licenses/mit-license.php',
853 'mozilla' => 'http://opensource.org/licenses/mozilla1.1.php',
854 'open_source' => undef,
855 'unrestricted' => undef,
856 'restrictive' => undef,
857 'unknown' => undef,
858 );
859  
860 22 my %v2_licenses = map { $_ => 1 } qw(
861 agpl_3
862 apache_1_1
863 apache_2_0
864 artistic_1
865 artistic_2
866 bsd
867 freebsd
868 gfdl_1_2
869 gfdl_1_3
870 gpl_1
871 gpl_2
872 gpl_3
873 lgpl_2_1
874 lgpl_3_0
875 mit
876 mozilla_1_0
877 mozilla_1_1
878 openssl
879 perl_5
880 qpl_1_0
881 ssleay
882 sun
883 zlib
884 open_source
885 restricted
886 unrestricted
887 unknown
888 );
889  
890 722 ▶sub license {
Subroutine license: called CC=5 SCAR=16.1
Pod undocumented
891 722 my ($self,$key,$value) = @_;
892 722 ▶ my $licenses = $self->{spec} < 2 ? \%v1_licenses : \%v2_licenses;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'spec'} < 2 ? : 532 190 722
893 722 ▶ if(defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 721 1 722
894 721 ▶ return 1 if($value && exists $licenses->{$value});
Branch: 1 branch
BranchTrueFalseTotal
if $value and exists $licenses->{$value} 719 2 721
Condition66%2/3
$value and exists $licenses->{$value}
!ll&&!rl&&r
02719
MC/DC50%1/2
$value and exists $licenses->{$value}
$value exists $licenses->{$value}
Truth table66%2/3
A and B
A= $valueB= exists $licenses->{$value}
ABresult
0X0
100
111
895 } else {
896 1 $value = '<undef>';
897 }
898 3 $self->_error( "License '$value' is invalid" );
899 3 return 0;
900 }
901  
902 98 ▶sub custom_1 {
Subroutine custom_1: called CC=5 SCAR=22.5
Pod undocumented
903 98 my ($self,$key) = @_;
904 98 ▶ if(defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 98 0 98
905 # a valid user defined key should be alphabetic
906 # and contain at least one capital case letter.
907 98 ▶ 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]/ 98 0 98
Condition33%2/6
$key and $key =~ /^[_a-z]+$/i and $key =~ /[A-Z]/
!ll&&!rl&&r
0098
$key and $key =~ /^[_a-z]+$/i
!ll&&!rl&&r
0098
MC/DC0%0/3
$key and $key =~ /^[_a-z]+$/i and $key =~ /[A-Z]/
$key $key =~ /^[_a-z]+$/i $key =~ /[A-Z]/
Truth table25%1/4
A and B and C
A= $keyB= $key =~ /^[_a-z]+$/iC= $key =~ /[A-Z]/
ABCresult
0XX0
10X0
1100
1111
908 } else {
909 0 $key = '<undef>';
910 }
911 0 $self->_error( "Custom resource '$key' must be in CamelCase." );
912 0 return 0;
913 }
914  
915 315 ▶sub custom_2 {
Subroutine custom_2: called CC=4 SCAR=18.7
Pod undocumented
916 315 my ($self,$key) = @_;
917 315 ▶ if(defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 315 0 315
918 315 ▶ return 1 if($key && $key =~ /^x_/i); # user defined
Branch: 1 branch
BranchTrueFalseTotal
if $key and $key =~ /^x_/i 315 0 315
Condition33%1/3
$key and $key =~ /^x_/i
!ll&&!rl&&r
00315
MC/DC0%0/2
$key and $key =~ /^x_/i
$key $key =~ /^x_/i
Truth table33%1/3
A and B
A= $keyB= $key =~ /^x_/i
ABresult
0X0
100
111
919 } else {
920 0 $key = '<undef>';
921 }
922 0 $self->_error( "Custom key '$key' must begin with 'x_' or 'X_'." );
923 0 return 0;
924 }
925  
926 0 ▶sub identifier {
Subroutine identifier: not called CC=4 SCAR=30.0
Pod undocumented
927 0 my ($self,$key) = @_;
928 0 ▶ if(defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 0 0 0
929 0 ▶ 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 0 0 0
Condition0%0/3
$key and $key =~ /^([a-z][_a-z]+)$/i
!ll&&!rl&&r
000
MC/DC0%0/2
$key and $key =~ /^([a-z][_a-z]+)$/i
$key $key =~ /^([a-z][_a-z]+)$/i
Truth table0%0/3
A and B
A= $keyB= $key =~ /^([a-z][_a-z]+)$/i
ABresult
0X0
100
111
930 } else {
931 0 $key = '<undef>';
932 }
933 0 $self->_error( "Key '$key' is not a legal identifier." );
934 0 return 0;
935 }
936  
937 13199 ▶sub module {
Subroutine module: called CC=4 SCAR=18.7
Pod undocumented
938 13199 my ($self,$key) = @_;
939 13199 ▶ if(defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 13199 0 13199
940 13199 ▶ 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_]+)*$/ 13199 0 13199
Condition33%1/3
$key and $key =~ /^[A-Za-z0-9_]+(::[A-Za-z0-9_]+)*$/
!ll&&!rl&&r
0013199
MC/DC0%0/2
$key and $key =~ /^[A-Za-z0-9_]+(::[A-Za-z0-9_]+)*$/
$key $key =~ /^[A-Za-z0-9_]+(::[A-Za-z0-9_]+)*$/
Truth table33%1/3
A and B
A= $keyB= $key =~ /^[A-Za-z0-9_]+(::[A-Za-z0-9_]+)*$/
ABresult
0X0
100
111
941 } else {
942 0 $key = '<undef>';
943 }
944 0 $self->_error( "Key '$key' is not a legal module name." );
945 0 return 0;
946 }
947  
948 22 my @valid_phases = qw/ configure build test runtime develop /;
949 492 ▶sub phase {
Subroutine phase: called CC=5 SCAR=23.1
Pod undocumented
950 492 my ($self,$key) = @_;
951 492 ▶ if(defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 492 0 492
952 492 ▶ return 1 if( length $key && grep { $key eq $_ } @valid_phases );
Branch: 1 branch
BranchTrueFalseTotal
if length $key and grep {$key eq $_;} @valid_phases 492 0 492
Condition33%1/3
length $key and grep {$key eq $_;} @valid_phases
!ll&&!rl&&r
00492
MC/DC0%0/2
length $key and grep {$key eq $_;} @valid_phases
length $key grep {$key eq $_;} @valid_phases
Truth table33%1/3
A and B
A= length $keyB= grep {$key eq $_;} @valid_phases
ABresult
0X0
100
111
953 0 ▶ return 1 if $key =~ /x_/i;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /x_/i 0 0 0
954 } else {
955 0 $key = '<undef>';
956 }
957 0 $self->_error( "Key '$key' is not a legal phase." );
958 0 return 0;
959 }
960  
961 22 my @valid_relations = qw/ requires recommends suggests conflicts /;
962 624 ▶sub relation {
Subroutine relation: called CC=5 SCAR=23.1
Pod undocumented
963 624 my ($self,$key) = @_;
964 624 ▶ if(defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 624 0 624
965 624 ▶ return 1 if( length $key && grep { $key eq $_ } @valid_relations );
Branch: 1 branch
BranchTrueFalseTotal
if length $key and grep {$key eq $_;} @valid_relations 624 0 624
Condition33%1/3
length $key and grep {$key eq $_;} @valid_relations
!ll&&!rl&&r
00624
MC/DC0%0/2
length $key and grep {$key eq $_;} @valid_relations
length $key grep {$key eq $_;} @valid_relations
Truth table33%1/3
A and B
A= length $keyB= grep {$key eq $_;} @valid_relations
ABresult
0X0
100
111
966 0 ▶ return 1 if $key =~ /x_/i;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /x_/i 0 0 0
967 } else {
968 0 $key = '<undef>';
969 }
970 0 $self->_error( "Key '$key' is not a legal prereq relationship." );
971 0 return 0;
972 }
973  
974 47 ▶sub _error {
Subroutine _error: called CC=2 SCAR=6.9
975 47 my $self = shift;
976 47 my $mess = shift;
977  
978 47 ▶ $mess .= ' ('.join(' -> ',@{$self->{stack}}).')' if($self->{stack});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"stack"} 43 4 47
979 47 $mess .= " [Validation: $self->{spec}]";
980  
981 47 push @{$self->{errors}}, $mess;
982 }
983  
984 22 1;
985  
986 # ABSTRACT: validate CPAN distribution metadata structures
987  
988 =pod
989  
990 =encoding UTF-8
991  
992 =head1 NAME
993  
994 CPAN::Meta::Validator - validate CPAN distribution metadata structures
995  
996 =head1 VERSION
997  
998 version 2.150015
999  
1000 =head1 SYNOPSIS
1001  
1002 my $struct = Parse::CPAN::Meta->load_file('META.json');
1003 my $cmv = CPAN::Meta::Validator->new( $struct );
1004  
1005 unless ( $cmv->is_valid ) {
1006 my $msg = "Invalid META structure. Errors found:\n";
1007 $msg .= join( "\n", $cmv->errors );
1008 die $msg;
1009 }
1010  
1011 =head1 DESCRIPTION
1012  
1013 This module validates a CPAN Meta structure against the version of the
1014 the specification claimed in the C<meta-spec> field of the structure.
1015  
1016 =head1 METHODS
1017  
1018 =head2 new
1019  
1020 my $cmv = CPAN::Meta::Validator->new( $struct )
1021  
1022 The constructor must be passed a metadata structure.
1023  
1024 =head2 is_valid
1025  
1026 if ( $cmv->is_valid ) {
1027 ...
1028 }
1029  
1030 Returns a boolean value indicating whether the metadata provided
1031 is valid.
1032  
1033 =head2 errors
1034  
1035 warn( join "\n", $cmv->errors );
1036  
1037 Returns a list of errors seen during validation.
1038  
1039 =begin :internals
1040  
1041 =head2 Check Methods
1042  
1043 =over
1044  
1045 =item *
1046  
1047 check_map($spec,$data)
1048  
1049 Checks whether a map (or hash) part of the data structure conforms to the
1050 appropriate specification definition.
1051  
1052 =item *
1053  
1054 check_list($spec,$data)
1055  
1056 Checks whether a list (or array) part of the data structure conforms to
1057 the appropriate specification definition.
1058  
1059 =item *
1060  
1061 =back
1062  
1063 =head2 Validator Methods
1064  
1065 =over
1066  
1067 =item *
1068  
1069 header($self,$key,$value)
1070  
1071 Validates that the header is valid.
1072  
1073 Note: No longer used as we now read the data structure, not the file.
1074  
1075 =item *
1076  
1077 url($self,$key,$value)
1078  
1079 Validates that a given value is in an acceptable URL format
1080  
1081 =item *
1082  
1083 urlspec($self,$key,$value)
1084  
1085 Validates that the URL to a META specification is a known one.
1086  
1087 =item *
1088  
1089 string_or_undef($self,$key,$value)
1090  
1091 Validates that the value is either a string or an undef value. Bit of a
1092 catchall function for parts of the data structure that are completely user
1093 defined.
1094  
1095 =item *
1096  
1097 string($self,$key,$value)
1098  
1099 Validates that a string exists for the given key.
1100  
1101 =item *
1102  
1103 file($self,$key,$value)
1104  
1105 Validate that a file is passed for the given key. This may be made more
1106 thorough in the future. For now it acts like \&string.
1107  
1108 =item *
1109  
1110 exversion($self,$key,$value)
1111  
1112 Validates a list of versions, e.g. '<= 5, >=2, ==3, !=4, >1, <6, 0'.
1113  
1114 =item *
1115  
1116 version($self,$key,$value)
1117  
1118 Validates a single version string. Versions of the type '5.8.8' and '0.00_00'
1119 are both valid. A leading 'v' like 'v1.2.3' is also valid.
1120  
1121 =item *
1122  
1123 boolean($self,$key,$value)
1124  
1125 Validates for a boolean value: a defined value that is either "1" or "0" or
1126 stringifies to those values.
1127  
1128 =item *
1129  
1130 license($self,$key,$value)
1131  
1132 Validates that a value is given for the license. Returns 1 if an known license
1133 type, or 2 if a value is given but the license type is not a recommended one.
1134  
1135 =item *
1136  
1137 custom_1($self,$key,$value)
1138  
1139 Validates that the given key is in CamelCase, to indicate a user defined
1140 keyword and only has characters in the class [-_a-zA-Z]. In version 1.X
1141 of the spec, this was only explicitly stated for 'resources'.
1142  
1143 =item *
1144  
1145 custom_2($self,$key,$value)
1146  
1147 Validates that the given key begins with 'x_' or 'X_', to indicate a user
1148 defined keyword and only has characters in the class [-_a-zA-Z]
1149  
1150 =item *
1151  
1152 identifier($self,$key,$value)
1153  
1154 Validates that key is in an acceptable format for the META specification,
1155 for an identifier, i.e. any that matches the regular expression
1156 qr/[a-z][a-z_]/i.
1157  
1158 =item *
1159  
1160 module($self,$key,$value)
1161  
1162 Validates that a given key is in an acceptable module name format, e.g.
1163 'Test::CPAN::Meta::Version'.
1164  
1165 =back
1166  
1167 =end :internals
1168  
1169 =for Pod::Coverage anything boolean check_list custom_1 custom_2 exversion file
1170 identifier license module phase relation release_status string string_or_undef
1171 url urlspec version header check_map
1172  
1173 =head1 BUGS
1174  
1175 Please report any bugs or feature using the CPAN Request Tracker.
1176 Bugs can be submitted through the web interface at
1177 L<http://rt.cpan.org/Dist/Display.html?Queue=CPAN-Meta>
1178  
1179 When submitting a bug or request, please include a test-file or a patch to an
1180 existing test-file that illustrates the bug or desired feature.
1181  
1182 =head1 AUTHORS
1183  
1184 =over 4
1185  
1186 =item *
1187  
1188 David Golden <dagolden@cpan.org>
1189  
1190 =item *
1191  
1192 Ricardo Signes <cpan@semiotic.systems>
1193  
1194 =item *
1195  
1196 Adam Kennedy <adamk@cpan.org>
1197  
1198 =back
1199  
1200 =head1 COPYRIGHT AND LICENSE
1201  
1202 This software is copyright (c) 2010 by David Golden, Ricardo Signes, Adam Kennedy and Contributors.
1203  
1204 This is free software; you can redistribute it and/or modify it under
1205 the same terms as the Perl 5 programming language system itself.
1206  
1207 =cut
1208  
1209 __END__
↑ Summary Parse/CPAN/Meta.pm »