summaryrefslogtreecommitdiff
path: root/Master/tlpkg/tlperl/lib/CPAN/Meta/Validator.pm
diff options
context:
space:
mode:
Diffstat (limited to 'Master/tlpkg/tlperl/lib/CPAN/Meta/Validator.pm')
-rw-r--r--Master/tlpkg/tlperl/lib/CPAN/Meta/Validator.pm225
1 files changed, 187 insertions, 38 deletions
diff --git a/Master/tlpkg/tlperl/lib/CPAN/Meta/Validator.pm b/Master/tlpkg/tlperl/lib/CPAN/Meta/Validator.pm
index e35f4c04ec7..f8b2fcaf303 100644
--- a/Master/tlpkg/tlperl/lib/CPAN/Meta/Validator.pm
+++ b/Master/tlpkg/tlperl/lib/CPAN/Meta/Validator.pm
@@ -2,8 +2,26 @@ use 5.006;
use strict;
use warnings;
package CPAN::Meta::Validator;
-our $VERSION = '2.120921'; # VERSION
-
+our $VERSION = '2.140640'; # VERSION
+
+# =head1 SYNOPSIS
+#
+# my $struct = decode_json_file('META.json');
+#
+# my $cmv = CPAN::Meta::Validator->new( $struct );
+#
+# unless ( $cmv->is_valid ) {
+# my $msg = "Invalid META structure. Errors found:\n";
+# $msg .= join( "\n", $cmv->errors );
+# die $msg;
+# }
+#
+# =head1 DESCRIPTION
+#
+# This module validates a CPAN Meta structure against the version of the
+# the specification claimed in the C<meta-spec> field of the structure.
+#
+# =cut
#--------------------------------------------------------------------------#
# This code copied and adapted from Test::CPAN::Meta
@@ -78,10 +96,10 @@ my %definitions = (
'2' => {
# REQUIRED
'abstract' => { mandatory => 1, value => \&string },
- 'author' => { mandatory => 1, lazylist => { value => \&string } },
+ 'author' => { mandatory => 1, list => { value => \&string } },
'dynamic_config' => { mandatory => 1, value => \&boolean },
'generated_by' => { mandatory => 1, value => \&string },
- 'license' => { mandatory => 1, lazylist => { value => \&license } },
+ 'license' => { mandatory => 1, list => { value => \&license } },
'meta-spec' => {
mandatory => 1,
'map' => {
@@ -96,7 +114,7 @@ my %definitions = (
# OPTIONAL
'description' => { value => \&string },
- 'keywords' => { lazylist => { value => \&string } },
+ 'keywords' => { list => { value => \&string } },
'no_index' => $no_index_2,
'optional_features' => {
'map' => {
@@ -125,7 +143,7 @@ my %definitions = (
},
'resources' => {
'map' => {
- license => { lazylist => { value => \&url } },
+ license => { list => { value => \&url } },
homepage => { value => \&url },
bugtracker => {
'map' => {
@@ -419,6 +437,13 @@ my %definitions = (
# Code
#--------------------------------------------------------------------------#
+# =method new
+#
+# my $cmv = CPAN::Meta::Validator->new( $struct )
+#
+# The constructor must be passed a metadata structure.
+#
+# =cut
sub new {
my ($class,$data) = @_;
@@ -426,7 +451,7 @@ sub new {
# create an attributes hash
my $self = {
'data' => $data,
- 'spec' => $data->{'meta-spec'}{'version'} || "1.0",
+ 'spec' => eval { $data->{'meta-spec'}{'version'} } || "1.0",
'errors' => undef,
};
@@ -434,6 +459,16 @@ sub new {
return bless $self, $class;
}
+# =method is_valid
+#
+# if ( $cmv->is_valid ) {
+# ...
+# }
+#
+# Returns a boolean value indicating whether the metadata provided
+# is valid.
+#
+# =cut
sub is_valid {
my $self = shift;
@@ -443,6 +478,13 @@ sub is_valid {
return ! $self->errors;
}
+# =method errors
+#
+# warn( join "\n", $cmv->errors );
+#
+# Returns a list of errors seen during validation.
+#
+# =cut
sub errors {
my $self = shift;
@@ -450,9 +492,34 @@ sub errors {
return @{$self->{errors}};
}
+# =begin :internals
+#
+# =head2 Check Methods
+#
+# =over
+#
+# =item *
+#
+# check_map($spec,$data)
+#
+# Checks whether a map (or hash) part of the data structure conforms to the
+# appropriate specification definition.
+#
+# =item *
+#
+# check_list($spec,$data)
+#
+# Checks whether a list (or array) part of the data structure conforms to
+# the appropriate specification definition.
+#
+# =item *
+#
+# =back
+#
+# =cut
my $spec_error = "Missing validation action in specification. "
- . "Must be one of 'map', 'list', 'lazylist', or 'value'";
+ . "Must be one of 'map', 'list', or 'value'";
sub check_map {
my ($self,$spec,$data) = @_;
@@ -484,8 +551,6 @@ sub check_map {
$self->check_map($spec->{$key}{'map'},$data->{$key});
} elsif($spec->{$key}{'list'}) {
$self->check_list($spec->{$key}{'list'},$data->{$key});
- } elsif($spec->{$key}{'lazylist'}) {
- $self->check_lazylist($spec->{$key}{'lazylist'},$data->{$key});
} else {
$self->_error( "$spec_error for '$key'" );
}
@@ -498,8 +563,6 @@ sub check_map {
$self->check_map($spec->{':key'}{'map'},$data->{$key});
} elsif($spec->{':key'}{'list'}) {
$self->check_list($spec->{':key'}{'list'},$data->{$key});
- } elsif($spec->{':key'}{'lazylist'}) {
- $self->check_lazylist($spec->{':key'}{'lazylist'},$data->{$key});
} else {
$self->_error( "$spec_error for ':key'" );
}
@@ -512,17 +575,6 @@ sub check_map {
}
}
-# if it's a string, make it into a list and check the list
-sub check_lazylist {
- my ($self,$spec,$data) = @_;
-
- if ( defined $data && ! ref($data) ) {
- $data = [ $data ];
- }
-
- $self->check_list($spec,$data);
-}
-
sub check_list {
my ($self,$spec,$data) = @_;
@@ -545,8 +597,6 @@ sub check_list {
$self->check_map($spec->{'map'},$value);
} elsif(defined $spec->{'list'}) {
$self->check_list($spec->{'list'},$value);
- } elsif(defined $spec->{'lazylist'}) {
- $self->check_lazylist($spec->{'lazylist'},$value);
} elsif ($spec->{':key'}) {
$self->check_map($spec,$value);
} else {
@@ -556,6 +606,113 @@ sub check_list {
}
}
+# =head2 Validator Methods
+#
+# =over
+#
+# =item *
+#
+# header($self,$key,$value)
+#
+# Validates that the header is valid.
+#
+# Note: No longer used as we now read the data structure, not the file.
+#
+# =item *
+#
+# url($self,$key,$value)
+#
+# Validates that a given value is in an acceptable URL format
+#
+# =item *
+#
+# urlspec($self,$key,$value)
+#
+# Validates that the URL to a META specification is a known one.
+#
+# =item *
+#
+# string_or_undef($self,$key,$value)
+#
+# Validates that the value is either a string or an undef value. Bit of a
+# catchall function for parts of the data structure that are completely user
+# defined.
+#
+# =item *
+#
+# string($self,$key,$value)
+#
+# Validates that a string exists for the given key.
+#
+# =item *
+#
+# file($self,$key,$value)
+#
+# Validate that a file is passed for the given key. This may be made more
+# thorough in the future. For now it acts like \&string.
+#
+# =item *
+#
+# exversion($self,$key,$value)
+#
+# Validates a list of versions, e.g. '<= 5, >=2, ==3, !=4, >1, <6, 0'.
+#
+# =item *
+#
+# version($self,$key,$value)
+#
+# Validates a single version string. Versions of the type '5.8.8' and '0.00_00'
+# are both valid. A leading 'v' like 'v1.2.3' is also valid.
+#
+# =item *
+#
+# boolean($self,$key,$value)
+#
+# Validates for a boolean value. Currently these values are '1', '0', 'true',
+# 'false', however the latter 2 may be removed.
+#
+# =item *
+#
+# license($self,$key,$value)
+#
+# Validates that a value is given for the license. Returns 1 if an known license
+# type, or 2 if a value is given but the license type is not a recommended one.
+#
+# =item *
+#
+# custom_1($self,$key,$value)
+#
+# Validates that the given key is in CamelCase, to indicate a user defined
+# keyword and only has characters in the class [-_a-zA-Z]. In version 1.X
+# of the spec, this was only explicitly stated for 'resources'.
+#
+# =item *
+#
+# custom_2($self,$key,$value)
+#
+# Validates that the given key begins with 'x_' or 'X_', to indicate a user
+# defined keyword and only has characters in the class [-_a-zA-Z]
+#
+# =item *
+#
+# identifier($self,$key,$value)
+#
+# Validates that key is in an acceptable format for the META specification,
+# for an identifier, i.e. any that matches the regular expression
+# qr/[a-z][a-z_]/i.
+#
+# =item *
+#
+# module($self,$key,$value)
+#
+# Validates that a given key is in an acceptable module name format, e.g.
+# 'Test::CPAN::Meta::Version'.
+#
+# =back
+#
+# =end :internals
+#
+# =cut
sub header {
my ($self,$key,$value) = @_;
@@ -828,17 +985,19 @@ sub _error {
# ABSTRACT: validate CPAN distribution metadata structures
-
+__END__
=pod
+=encoding UTF-8
+
=head1 NAME
CPAN::Meta::Validator - validate CPAN distribution metadata structures
=head1 VERSION
-version 2.120921
+version 2.140640
=head1 SYNOPSIS
@@ -902,10 +1061,6 @@ the appropriate specification definition.
=item *
-check_lazylist($spec,$data)
-
-Checks whether a list conforms, but converts strings to a single-element list
-
=back
=head2 Validator Methods
@@ -1014,7 +1169,7 @@ Validates that a given key is in an acceptable module name format, e.g.
=end :internals
-=for Pod::Coverage anything boolean check_lazylist check_list custom_1 custom_2 exversion file
+=for Pod::Coverage anything boolean check_list custom_1 custom_2 exversion file
identifier license module phase relation release_status string string_or_undef
url urlspec version header check_map
@@ -1049,9 +1204,3 @@ This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
-
-
-__END__
-
-
-