diff options
Diffstat (limited to 'Master/tlpkg/tlperl/lib/CPAN/Meta.pm')
-rw-r--r-- | Master/tlpkg/tlperl/lib/CPAN/Meta.pm | 442 |
1 files changed, 416 insertions, 26 deletions
diff --git a/Master/tlpkg/tlperl/lib/CPAN/Meta.pm b/Master/tlpkg/tlperl/lib/CPAN/Meta.pm index 19980bd4fc8..3ab0111844a 100644 --- a/Master/tlpkg/tlperl/lib/CPAN/Meta.pm +++ b/Master/tlpkg/tlperl/lib/CPAN/Meta.pm @@ -2,18 +2,81 @@ use 5.006; use strict; use warnings; package CPAN::Meta; -our $VERSION = '2.120921'; # VERSION - +our $VERSION = '2.140640'; # VERSION + +# =head1 SYNOPSIS +# +# use v5.10; +# use strict; +# use warnings; +# use CPAN::Meta; +# use Module::Load; +# +# my $meta = CPAN::Meta->load_file('META.json'); +# +# printf "testing requirements for %s version %s\n", +# $meta->name, +# $meta->version; +# +# my $prereqs = $meta->effective_prereqs; +# +# for my $phase ( qw/configure runtime build test/ ) { +# say "Requirements for $phase:"; +# my $reqs = $prereqs->requirements_for($phase, "requires"); +# for my $module ( sort $reqs->required_modules ) { +# my $status; +# if ( eval { load $module unless $module eq 'perl'; 1 } ) { +# my $version = $module eq 'perl' ? $] : $module->VERSION; +# $status = $reqs->accepts_module($module, $version) +# ? "$version ok" : "$version not ok"; +# } else { +# $status = "missing" +# }; +# say " $module ($status)"; +# } +# } +# +# =head1 DESCRIPTION +# +# Software distributions released to the CPAN include a F<META.json> or, for +# older distributions, F<META.yml>, which describes the distribution, its +# contents, and the requirements for building and installing the distribution. +# The data structure stored in the F<META.json> file is described in +# L<CPAN::Meta::Spec>. +# +# CPAN::Meta provides a simple class to represent this distribution metadata (or +# I<distmeta>), along with some helpful methods for interrogating that data. +# +# The documentation below is only for the methods of the CPAN::Meta object. For +# information on the meaning of individual fields, consult the spec. +# +# =cut use Carp qw(carp croak); use CPAN::Meta::Feature; use CPAN::Meta::Prereqs; use CPAN::Meta::Converter; use CPAN::Meta::Validator; -use Parse::CPAN::Meta 1.4403 (); +use Parse::CPAN::Meta 1.4414 (); BEGIN { *_dclone = \&CPAN::Meta::Converter::_dclone } +# =head1 STRING DATA +# +# The following methods return a single value, which is the value for the +# corresponding entry in the distmeta structure. Values should be either undef +# or strings. +# +# =for :list +# * abstract +# * description +# * dynamic_config +# * generated_by +# * name +# * release_status +# * version +# +# =cut BEGIN { my @STRING_READERS = qw( @@ -32,6 +95,20 @@ BEGIN { } } +# =head1 LIST DATA +# +# These methods return lists of string values, which might be represented in the +# distmeta structure as arrayrefs or scalars: +# +# =for :list +# * authors +# * keywords +# * licenses +# +# The C<authors> and C<licenses> methods may also be called as C<author> and +# C<license>, respectively, to match the field name in the distmeta structure. +# +# =cut BEGIN { my @LIST_READERS = qw( @@ -55,6 +132,20 @@ BEGIN { sub authors { $_[0]->author } sub licenses { $_[0]->license } +# =head1 MAP DATA +# +# These readers return hashrefs of arbitrary unblessed data structures, each +# described more fully in the specification: +# +# =for :list +# * meta_spec +# * resources +# * provides +# * no_index +# * prereqs +# * optional_features +# +# =cut BEGIN { my @MAP_READERS = qw( @@ -78,6 +169,16 @@ BEGIN { } } +# =head1 CUSTOM DATA +# +# A list of custom keys are available from the C<custom_keys> method and +# particular keys may be retrieved with the C<custom> method. +# +# say $meta->custom($_) for $meta->custom_keys; +# +# If a custom key refers to a data structure, a deep clone is returned. +# +# =cut sub custom_keys { return grep { /^x_/i } keys %{$_[0]}; @@ -90,6 +191,29 @@ sub custom { return $value; } +# =method new +# +# my $meta = CPAN::Meta->new($distmeta_struct, \%options); +# +# Returns a valid CPAN::Meta object or dies if the supplied metadata hash +# reference fails to validate. Older-format metadata will be up-converted to +# version 2 if they validate against the original stated specification. +# +# It takes an optional hashref of options. Valid options include: +# +# =over +# +# =item * +# +# lazy_validation -- if true, new will attempt to convert the given metadata +# to version 2 before attempting to validate it. This means than any +# fixable errors will be handled by CPAN::Meta::Converter before validation. +# (Note that this might result in invalid optional data being silently +# dropped.) The default is false. +# +# =back +# +# =cut sub _new { my ($class, $struct, $options) = @_; @@ -130,6 +254,15 @@ sub new { return $self; } +# =method create +# +# my $meta = CPAN::Meta->create($distmeta_struct, \%options); +# +# This is same as C<new()>, except that C<generated_by> and C<meta-spec> fields +# will be generated if not provided. This means the metadata structure is +# assumed to otherwise follow the latest L<CPAN::Meta::Spec>. +# +# =cut sub create { my ($class, $struct, $options) = @_; @@ -141,6 +274,19 @@ sub create { return $self; } +# =method load_file +# +# my $meta = CPAN::Meta->load_file($distmeta_file, \%options); +# +# Given a pathname to a file containing metadata, this deserializes the file +# according to its file suffix and constructs a new C<CPAN::Meta> object, just +# like C<new()>. It will die if the deserialized version fails to validate +# against its stated specification version. +# +# It takes the same options as C<new()> but C<lazy_validation> defaults to +# true. +# +# =cut sub load_file { my ($class, $file, $options) = @_; @@ -158,6 +304,14 @@ sub load_file { return $self; } +# =method load_yaml_string +# +# my $meta = CPAN::Meta->load_yaml_string($yaml, \%options); +# +# This method returns a new CPAN::Meta object using the first document in the +# given YAML string. In other respects it is identical to C<load_file()>. +# +# =cut sub load_yaml_string { my ($class, $yaml, $options) = @_; @@ -172,6 +326,14 @@ sub load_yaml_string { return $self; } +# =method load_json_string +# +# my $meta = CPAN::Meta->load_json_string($json, \%options); +# +# This method returns a new CPAN::Meta object using the structure represented by +# the given JSON string. In other respects it is identical to C<load_file()>. +# +# =cut sub load_json_string { my ($class, $json, $options) = @_; @@ -186,6 +348,50 @@ sub load_json_string { return $self; } +# =method load_string +# +# my $meta = CPAN::Meta->load_string($string, \%options); +# +# If you don't know if a string contains YAML or JSON, this method will use +# L<Parse::CPAN::Meta> to guess. In other respects it is identical to +# C<load_file()>. +# +# =cut + +sub load_string { + my ($class, $string, $options) = @_; + $options->{lazy_validation} = 1 unless exists $options->{lazy_validation}; + + my $self; + eval { + my $struct = Parse::CPAN::Meta->load_string( $string ); + $self = $class->_new($struct, $options); + }; + croak($@) if $@; + return $self; +} + +# =method save +# +# $meta->save($distmeta_file, \%options); +# +# Serializes the object as JSON and writes it to the given file. The only valid +# option is C<version>, which defaults to '2'. On Perl 5.8.1 or later, the file +# is saved with UTF-8 encoding. +# +# For C<version> 2 (or higher), the filename should end in '.json'. L<JSON::PP> +# is the default JSON backend. Using another JSON backend requires L<JSON> 2.5 or +# later and you must set the C<$ENV{PERL_JSON_BACKEND}> to a supported alternate +# backend like L<JSON::XS>. +# +# For C<version> less than 2, the filename should end in '.yml'. +# L<CPAN::Meta::Converter> is used to generate an older metadata structure, which +# is serialized to YAML. CPAN::Meta::YAML is the default YAML backend. You may +# set the C<$ENV{PERL_YAML_BACKEND}> to a supported alternative backend, though +# this is not recommended due to subtle incompatibilities between YAML parsers on +# CPAN. +# +# =cut sub save { my ($self, $file, $options) = @_; @@ -213,12 +419,32 @@ sub save { return 1; } +# =method meta_spec_version +# +# This method returns the version part of the C<meta_spec> entry in the distmeta +# structure. It is equivalent to: +# +# $meta->meta_spec->{version}; +# +# =cut sub meta_spec_version { my ($self) = @_; return $self->meta_spec->{version}; } +# =method effective_prereqs +# +# my $prereqs = $meta->effective_prereqs; +# +# my $prereqs = $meta->effective_prereqs( \@feature_identifiers ); +# +# This method returns a L<CPAN::Meta::Prereqs> object describing all the +# prereqs for the distribution. If an arrayref of feature identifiers is given, +# the prereqs for the identified features are merged together with the +# distribution's core prereqs before the CPAN::Meta::Prereqs object is returned. +# +# =cut sub effective_prereqs { my ($self, $features) = @_; @@ -233,6 +459,17 @@ sub effective_prereqs { return $prereq->with_merged_prereqs(\@other); } +# =method should_index_file +# +# ... if $meta->should_index_file( $filename ); +# +# This method returns true if the given file should be indexed. It decides this +# by checking the C<file> and C<directory> keys in the C<no_index> property of +# the distmeta structure. +# +# C<$filename> should be given in unix format. +# +# =cut sub should_index_file { my ($self, $filename) = @_; @@ -249,6 +486,15 @@ sub should_index_file { return 1; } +# =method should_index_package +# +# ... if $meta->should_index_package( $package ); +# +# This method returns true if the given package should be indexed. It decides +# this by checking the C<package> and C<namespace> keys in the C<no_index> +# property of the distmeta structure. +# +# =cut sub should_index_package { my ($self, $package) = @_; @@ -264,6 +510,14 @@ sub should_index_package { return 1; } +# =method features +# +# my @feature_objects = $meta->features; +# +# This method returns a list of L<CPAN::Meta::Feature> objects, one for each +# optional feature described by the distribution's metadata. +# +# =cut sub features { my ($self) = @_; @@ -275,6 +529,15 @@ sub features { return @features; } +# =method feature +# +# my $feature_object = $meta->feature( $identifier ); +# +# This method returns a L<CPAN::Meta::Feature> object for the optional feature +# with the given identifier. If no feature with that identifier exists, an +# exception will be raised. +# +# =cut sub feature { my ($self, $ident) = @_; @@ -285,6 +548,18 @@ sub feature { return CPAN::Meta::Feature->new($ident, $f); } +# =method as_struct +# +# my $copy = $meta->as_struct( \%options ); +# +# This method returns a deep copy of the object's metadata as an unblessed hash +# reference. It takes an optional hashref of options. If the hashref contains +# a C<version> argument, the copied metadata will be converted to the version +# of the specification and returned. For example: +# +# my $old_spec = $meta->as_struct( {version => "1.4"} ); +# +# =cut sub as_struct { my ($self, $options) = @_; @@ -296,6 +571,24 @@ sub as_struct { return $struct; } +# =method as_string +# +# my $string = $meta->as_string( \%options ); +# +# This method returns a serialized copy of the object's metadata as a character +# string. (The strings are B<not> UTF-8 encoded.) It takes an optional hashref +# of options. If the hashref contains a C<version> argument, the copied metadata +# will be converted to the version of the specification and returned. For +# example: +# +# my $string = $meta->as_string( {version => "1.4"} ); +# +# For C<version> greater than or equal to 2, the string will be serialized as +# JSON. For C<version> less than 2, the string will be serialized as YAML. In +# both cases, the same rules are followed as in the C<save()> method for choosing +# a serialization backend. +# +# =cut sub as_string { my ($self, $options) = @_; @@ -336,35 +629,51 @@ sub TO_JSON { # ABSTRACT: the distribution metadata for a CPAN dist - +__END__ =pod +=encoding UTF-8 + =head1 NAME CPAN::Meta - the distribution metadata for a CPAN dist =head1 VERSION -version 2.120921 +version 2.140640 =head1 SYNOPSIS - my $meta = CPAN::Meta->load_file('META.json'); + use v5.10; + use strict; + use warnings; + use CPAN::Meta; + use Module::Load; - printf "testing requirements for %s version %s\n", + my $meta = CPAN::Meta->load_file('META.json'); + + printf "testing requirements for %s version %s\n", $meta->name, $meta->version; - my $prereqs = $meta->requirements_for('configure'); - - for my $module ($prereqs->required_modules) { - my $version = get_local_version($module); - - die "missing required module $module" unless defined $version; - die "version for $module not in range" - unless $prereqs->accepts_module($module, $version); - } + my $prereqs = $meta->effective_prereqs; + + for my $phase ( qw/configure runtime build test/ ) { + say "Requirements for $phase:"; + my $reqs = $prereqs->requirements_for($phase, "requires"); + for my $module ( sort $reqs->required_modules ) { + my $status; + if ( eval { load $module unless $module eq 'perl'; 1 } ) { + my $version = $module eq 'perl' ? $] : $module->VERSION; + $status = $reqs->accepts_module($module, $version) + ? "$version ok" : "$version not ok"; + } else { + $status = "missing" + }; + say " $module ($status)"; + } + } =head1 DESCRIPTION @@ -438,6 +747,14 @@ given YAML string. In other respects it is identical to C<load_file()>. This method returns a new CPAN::Meta object using the structure represented by the given JSON string. In other respects it is identical to C<load_file()>. +=head2 load_string + + my $meta = CPAN::Meta->load_string($string, \%options); + +If you don't know if a string contains YAML or JSON, this method will use +L<Parse::CPAN::Meta> to guess. In other respects it is identical to +C<load_file()>. + =head2 save $meta->save($distmeta_file, \%options); @@ -513,7 +830,7 @@ exception will be raised. my $copy = $meta->as_struct( \%options ); -This method returns a deep copy of the object's metadata as an unblessed has +This method returns a deep copy of the object's metadata as an unblessed hash reference. It takes an optional hashref of options. If the hashref contains a C<version> argument, the copied metadata will be converted to the version of the specification and returned. For example: @@ -530,7 +847,7 @@ of options. If the hashref contains a C<version> argument, the copied metadata will be converted to the version of the specification and returned. For example: - my $string = $meta->as_struct( {version => "1.4"} ); + my $string = $meta->as_string( {version => "1.4"} ); For C<version> greater than or equal to 2, the string will be serialized as JSON. For C<version> less than 2, the string will be serialized as YAML. In @@ -675,7 +992,7 @@ L<CPAN::Meta::Validator> =head2 Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker -at L<http://rt.cpan.org/Public/Dist/Display.html?Name=CPAN-Meta>. +at L<https://github.com/Perl-Toolchain-Gang/CPAN-Meta/issues>. You will be notified automatically of any progress on your issue. =head2 Source Code @@ -683,9 +1000,9 @@ You will be notified automatically of any progress on your issue. This is open source software. The code repository is available for public review and contribution under the terms of the license. -L<http://github.com/dagolden/cpan-meta> +L<https://github.com/Perl-Toolchain-Gang/CPAN-Meta> - git clone git://github.com/dagolden/cpan-meta.git + git clone https://github.com/Perl-Toolchain-Gang/CPAN-Meta.git =head1 AUTHORS @@ -701,6 +1018,84 @@ Ricardo Signes <rjbs@cpan.org> =back +=head1 CONTRIBUTORS + +=over 4 + +=item * + +Ansgar Burchardt <ansgar@cpan.org> + +=item * + +Avar Arnfjord Bjarmason <avar@cpan.org> + +=item * + +Christopher J. Madsen <cjm@cpan.org> + +=item * + +Chuck Adams <cja987@gmail.com> + +=item * + +Cory G Watson <gphat@cpan.org> + +=item * + +Damyan Ivanov <dam@cpan.org> + +=item * + +Eric Wilhelm <ewilhelm@cpan.org> + +=item * + +Gregor Hermann <gregoa@debian.org> + +=item * + +Karen Etheridge <ether@cpan.org> + +=item * + +Ken Williams <kwilliams@cpan.org> + +=item * + +Kenichi Ishigaki <ishigaki@cpan.org> + +=item * + +Lars Dieckow <daxim@cpan.org> + +=item * + +Leon Timmermans <leont@cpan.org> + +=item * + +Mark Fowler <markf@cpan.org> + +=item * + +Michael G. Schwern <mschwern@cpan.org> + +=item * + +Olaf Alders <olaf@wundersolutions.com> + +=item * + +Olivier Mengue <dolmen@cpan.org> + +=item * + +Randy Sims <randys@thepierianspring.org> + +=back + =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2010 by David Golden and Ricardo Signes. @@ -709,8 +1104,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__ - - |