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 CPAN::Meta::Spec.

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.

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:

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.

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.

It takes the same options as new() but lazy_validation defaults to true.

Serializes the object as JSON and writes it to the given file. The only valid option is version, which defaults to '2'. On Perl 5.8.1 or later, the file is saved with UTF-8 encoding.

For version 2 (or higher), the filename should end in '.json'. JSON::PP is the default JSON backend. Using another JSON backend requires JSON 2.5 or later and you must set the $ENV{PERL_JSON_BACKEND} to a supported alternate backend like JSON::XS.

For version less than 2, the filename should end in '.yml'. 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 $ENV{PERL_YAML_BACKEND} to a supported alternative backend, though this is not recommended due to subtle incompatibilities between YAML parsers on CPAN.

This method returns a 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.

This method returns a deep copy of the object's metadata as an unblessed has reference. It takes an optional hashref of options. If the hashref contains a version argument, the copied metadata will be converted to the version of the specification and returned. For example:

This method returns a serialized copy of the object's metadata as a character string. (The strings are not UTF-8 encoded.) It takes an optional hashref of options. If the hashref contains a 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"} );

For version greater than or equal to 2, the string will be serialized as JSON. For version less than 2, the string will be serialized as YAML. In both cases, the same rules are followed as in the save() method for choosing a serialization backend.