| CPAN::Meta - the distribution metadata for a CPAN dist |
CPAN::Meta - the distribution metadata for a CPAN dist
version 2.101091
my $meta = CPAN::Meta->load('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);
}
Software distributions released to the CPAN include a META.json or, for older distributions, META.yml, which describes the distribution, its contents, and the requirements for building and installing the distribution. The data structure stored in the META.json file is described in the CPAN::Meta::Spec manpage.
CPAN::Meta provides a simple class to represent this distribution metadata (or 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.
my $meta = CPAN::Meta->new($distmeta_struct);
Returns a valid CPAN::Meta object or dies if the supplied hash reference fails to validate. Older format metadata will be up-converted to version 2 if if validates against the original stated specification.
For a more liberal treatment, manually upcovert older metadata versions
using the CPAN::Meta::Converter manpage before calling new()
my $meta = CPAN::Meta->create($distmeta_struct);
This is same as new(), except that generated_by and meta-spec fields
will be generated if not provided.
my $meta = CPAN::Meta->load($distmeta_file);
Given a pathname to a file containing metadata, this deserializes the file
according to its file suffix and constructs a new CPAN::Meta object, just
like new(). It will die if the deserialized version fails to validate
against its stated specification version.
my $meta = CPAN::Meta->load_yaml_string($yaml);
This method returns a new CPAN::Meta object using the first document in the
given YAML string. In other respects it is identical to load_file().
my $meta = CPAN::Meta->load_json_string($json);
This method returns a new CPAN::Meta object using the structure represented by
the given JSON string. In other respects it is identical to load_file().
$meta->save($distmeta_file);
Serializes the object as JSON and writes it to the given file. The filename should end in '.json'.
This method returns the version part of the meta_spec entry in the distmeta
structure. It is equivalent to:
$meta->meta_spec->{version};
my $prereqs = $meta->effective_prereqs;
my $prereqs = $meta->effective_prereqs( \@feature_identifiers );
This method returns a the CPAN::Meta::Prereqs manpage 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.
... if $meta->should_index_file( $filename );
This method returns true if the given file should be indexed. It decides this
by checking the file and directory keys in the no_index property of
the distmeta structure.
$filename should be given in unix format.
... if $meta->should_index_package( $package );
This method returns true if the given package should be indexed. It decides
this by checking the package and namespace keys in the no_index
property of the distmeta structure.
my @feature_objects = $meta->features;
This method returns a list of the CPAN::Meta::Feature manpage objects, one for each optional feature described by the distribution's metadata.
my $feature_object = $meta->feature( $identifier );
This method returns a the CPAN::Meta::Feature manpage object for the optional feature with the given identifier. If no feature with that identifier exists, an exception will be raised.
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.
abstract
description
dynamic_config
generated_by
name
release_status
version
These methods return lists of string values, which might be represented in the distmeta structure as arrayrefs or scalars:
authors
keywords
licenses
The authors and licenses methods may also be called as author and
license, respectively, to match the field name in the distmeta structure.
These readers return hashrefs of arbitrary unblessed data structures, each described more fully in the specification:
meta_spec
resources
provides
no_index
prereqs
optional_features
Please report any bugs or feature using the CPAN Request Tracker. Bugs can be submitted through the web interface at http://rt.cpan.org/Dist/Display.html
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
David Golden <dagolden@cpan.org> Ricardo Signes <rjbs@cpan.org>
This software is copyright (c) 2010 by David Golden and Ricardo Signes.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
| CPAN::Meta - the distribution metadata for a CPAN dist |