diff options
Diffstat (limited to 'Master/tlpkg/tlperl/lib/CPAN/Meta/Validator.pm')
-rw-r--r-- | Master/tlpkg/tlperl/lib/CPAN/Meta/Validator.pm | 355 |
1 files changed, 178 insertions, 177 deletions
diff --git a/Master/tlpkg/tlperl/lib/CPAN/Meta/Validator.pm b/Master/tlpkg/tlperl/lib/CPAN/Meta/Validator.pm index f8b2fcaf303..cc0409e6e48 100644 --- a/Master/tlpkg/tlperl/lib/CPAN/Meta/Validator.pm +++ b/Master/tlpkg/tlperl/lib/CPAN/Meta/Validator.pm @@ -2,26 +2,27 @@ use 5.006; use strict; use warnings; package CPAN::Meta::Validator; -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 + +our $VERSION = '2.150001'; + +#pod =head1 SYNOPSIS +#pod +#pod my $struct = decode_json_file('META.json'); +#pod +#pod my $cmv = CPAN::Meta::Validator->new( $struct ); +#pod +#pod unless ( $cmv->is_valid ) { +#pod my $msg = "Invalid META structure. Errors found:\n"; +#pod $msg .= join( "\n", $cmv->errors ); +#pod die $msg; +#pod } +#pod +#pod =head1 DESCRIPTION +#pod +#pod This module validates a CPAN Meta structure against the version of the +#pod the specification claimed in the C<meta-spec> field of the structure. +#pod +#pod =cut #--------------------------------------------------------------------------# # This code copied and adapted from Test::CPAN::Meta @@ -437,13 +438,13 @@ my %definitions = ( # Code #--------------------------------------------------------------------------# -# =method new -# -# my $cmv = CPAN::Meta::Validator->new( $struct ) -# -# The constructor must be passed a metadata structure. -# -# =cut +#pod =method new +#pod +#pod my $cmv = CPAN::Meta::Validator->new( $struct ) +#pod +#pod The constructor must be passed a metadata structure. +#pod +#pod =cut sub new { my ($class,$data) = @_; @@ -459,16 +460,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 +#pod =method is_valid +#pod +#pod if ( $cmv->is_valid ) { +#pod ... +#pod } +#pod +#pod Returns a boolean value indicating whether the metadata provided +#pod is valid. +#pod +#pod =cut sub is_valid { my $self = shift; @@ -478,13 +479,13 @@ sub is_valid { return ! $self->errors; } -# =method errors -# -# warn( join "\n", $cmv->errors ); -# -# Returns a list of errors seen during validation. -# -# =cut +#pod =method errors +#pod +#pod warn( join "\n", $cmv->errors ); +#pod +#pod Returns a list of errors seen during validation. +#pod +#pod =cut sub errors { my $self = shift; @@ -492,31 +493,31 @@ 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 +#pod =begin :internals +#pod +#pod =head2 Check Methods +#pod +#pod =over +#pod +#pod =item * +#pod +#pod check_map($spec,$data) +#pod +#pod Checks whether a map (or hash) part of the data structure conforms to the +#pod appropriate specification definition. +#pod +#pod =item * +#pod +#pod check_list($spec,$data) +#pod +#pod Checks whether a list (or array) part of the data structure conforms to +#pod the appropriate specification definition. +#pod +#pod =item * +#pod +#pod =back +#pod +#pod =cut my $spec_error = "Missing validation action in specification. " . "Must be one of 'map', 'list', or 'value'"; @@ -606,113 +607,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 +#pod =head2 Validator Methods +#pod +#pod =over +#pod +#pod =item * +#pod +#pod header($self,$key,$value) +#pod +#pod Validates that the header is valid. +#pod +#pod Note: No longer used as we now read the data structure, not the file. +#pod +#pod =item * +#pod +#pod url($self,$key,$value) +#pod +#pod Validates that a given value is in an acceptable URL format +#pod +#pod =item * +#pod +#pod urlspec($self,$key,$value) +#pod +#pod Validates that the URL to a META specification is a known one. +#pod +#pod =item * +#pod +#pod string_or_undef($self,$key,$value) +#pod +#pod Validates that the value is either a string or an undef value. Bit of a +#pod catchall function for parts of the data structure that are completely user +#pod defined. +#pod +#pod =item * +#pod +#pod string($self,$key,$value) +#pod +#pod Validates that a string exists for the given key. +#pod +#pod =item * +#pod +#pod file($self,$key,$value) +#pod +#pod Validate that a file is passed for the given key. This may be made more +#pod thorough in the future. For now it acts like \&string. +#pod +#pod =item * +#pod +#pod exversion($self,$key,$value) +#pod +#pod Validates a list of versions, e.g. '<= 5, >=2, ==3, !=4, >1, <6, 0'. +#pod +#pod =item * +#pod +#pod version($self,$key,$value) +#pod +#pod Validates a single version string. Versions of the type '5.8.8' and '0.00_00' +#pod are both valid. A leading 'v' like 'v1.2.3' is also valid. +#pod +#pod =item * +#pod +#pod boolean($self,$key,$value) +#pod +#pod Validates for a boolean value. Currently these values are '1', '0', 'true', +#pod 'false', however the latter 2 may be removed. +#pod +#pod =item * +#pod +#pod license($self,$key,$value) +#pod +#pod Validates that a value is given for the license. Returns 1 if an known license +#pod type, or 2 if a value is given but the license type is not a recommended one. +#pod +#pod =item * +#pod +#pod custom_1($self,$key,$value) +#pod +#pod Validates that the given key is in CamelCase, to indicate a user defined +#pod keyword and only has characters in the class [-_a-zA-Z]. In version 1.X +#pod of the spec, this was only explicitly stated for 'resources'. +#pod +#pod =item * +#pod +#pod custom_2($self,$key,$value) +#pod +#pod Validates that the given key begins with 'x_' or 'X_', to indicate a user +#pod defined keyword and only has characters in the class [-_a-zA-Z] +#pod +#pod =item * +#pod +#pod identifier($self,$key,$value) +#pod +#pod Validates that key is in an acceptable format for the META specification, +#pod for an identifier, i.e. any that matches the regular expression +#pod qr/[a-z][a-z_]/i. +#pod +#pod =item * +#pod +#pod module($self,$key,$value) +#pod +#pod Validates that a given key is in an acceptable module name format, e.g. +#pod 'Test::CPAN::Meta::Version'. +#pod +#pod =back +#pod +#pod =end :internals +#pod +#pod =cut sub header { my ($self,$key,$value) = @_; @@ -997,7 +998,7 @@ CPAN::Meta::Validator - validate CPAN distribution metadata structures =head1 VERSION -version 2.140640 +version 2.150001 =head1 SYNOPSIS |