CPAN::Meta(3pm)
πΈ NAME: CPAN::Meta(3pm) β the distribution metadata for a CPAN dist πΈ
Bestie, meet CPAN::Meta: the class that holds and pokes at a CPAN distributionβs metadata. This page is the manual for CPAN::Meta(3pm), and weβre gonna get into it. π
π VERSION π
This is version 2.150010, periodt. β¨
π 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)";
}
}
π¦ DESCRIPTION π¦
So like, software distributions released to the CPAN include a META.json or, for older distributions, a META.yml. That file describes the distribution, whatβs inside it, and the requirements for building and installing it. 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 β aka distmeta β along with some helpful methods for interrogating that data. Itβs giving very useful, no cap.
The documentation below is only for the methods of the CPAN::Meta object. For info on the meaning of individual fields, consult the spec. π
π METHODS π
π 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:
lazy_validationβ if true,newwill attempt to convert the given metadata to version 2 before attempting to validate it. This means that any fixable errors will be handled byCPAN::Meta::Converterbefore validation.
Note that this might result in invalid optional data being silently dropped. The default is false. π
π create
my $meta = CPAN::Meta->create($distmeta_struct, \%options);
This is same as new(), except that generated_by and meta-spec fields will be generated if not provided. This means the metadata structure is assumed to otherwise follow the latest CPAN::Meta::Spec. Slay. β¨
π 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 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.
π 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 load_file(). π
π 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 load_file(). π¦
π 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 Parse::CPAN::Meta to guess. In other respects it is identical to load_file(). Iconic guessing behavior, honestly. π₯
π save
$meta->save($distmeta_file, \%options);
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. π«Ά
That YAML backend warning is fr fr important β subtle parser incompatibilities are not it. π
π meta_spec_version
This method returns the version part of the meta_spec entry in the distmeta structure. It is equivalent to:
$meta->meta_spec->{version};
π effective_prereqs
my $prereqs = $meta->effective_prereqs;
my $prereqs = $meta->effective_prereqs( \@feature_identifiers );
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. Merging vibes, but make it dependency resolution. β¨
π 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 file and directory keys in the no_index property of the distmeta structure. Note that neither the version format nor release_status are considered. π
$filename should be given in unix format.
π 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 package and namespace keys in the no_index property of the distmeta structure. Note that neither the version format nor release_status are considered. πΈ
π features
my @feature_objects = $meta->features;
This method returns a list of CPAN::Meta::Feature objects, one for each optional feature described by the distributionβs metadata. Cute optional-feature moment. π§
π feature
my $feature_object = $meta->feature( $identifier );
This method returns a CPAN::Meta::Feature object for the optional feature with the given identifier. If no feature with that identifier exists, an exception will be raised. No silent missing-feature behavior here, bestie. π
π 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 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"} );
π 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 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_string( {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. π₯
The serialized structure will include a x_serialization_backend entry giving the package and version used to serialize. Any existing key in the given $meta object will be clobbered. π
Clobbered means clobbered, bestie. Do not expect that key to survive. π
π 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. π
abstractdescriptiondynamic_configgenerated_bynamerelease_statusversion
π LIST DATA π
These methods return lists of string values, which might be represented in the distmeta structure as arrayrefs or scalars: β¨
authorskeywordslicenses
The authors and licenses methods may also be called as author and license, respectively, to match the field name in the distmeta structure. Nickname behavior, but make it API. π
π¦ MAP DATA π¦
These readers return hashrefs of arbitrary unblessed data structures, each described more fully in the specification: πΈ
meta_specresourcesprovidesno_indexprereqsoptional_features
π CUSTOM DATA π
A list of custom keys are available from the custom_keys method and particular keys may be retrieved with the custom method. π
say $meta->custom($_) for $meta->custom_keys;
If a custom key refers to a data structure, a deep clone is returned. No cap, thatβs the safe-copy behavior. π«Ά
π BUGS π
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?Queue=CPAN-Meta>. π
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. Thatβs the good group-chat behavior: receipts and reproducible examples. β¨
π SEE ALSO π
CPAN::Meta::ConverterCPAN::Meta::Validator
π«Ά SUPPORT π«Ά
π Bugs / Feature Requests
Please report any bugs or feature requests through the issue tracker at <https://github.com/Perl-Toolchain-Gang/CPAN-Meta/issues>. You will be notified automatically of any progress on your issue. π
π§ Source Code
This is open source software. The code repository is available for public review and contribution under the terms of the license. π
<https://github.com/Perl-Toolchain-Gang/CPAN-Meta>
git clone https://github.com/Perl-Toolchain-Gang/CPAN-Meta.git
π AUTHORS π
- David Golden
<dagolden@cpan.org> - Ricardo Signes
<rjbs@cpan.org> - Adam Kennedy
<adamk@cpan.org>
π«Ά CONTRIBUTORS π«Ά
okay so a manpage like this does NOT write itself, and honestly? the glow-up squad behind CPAN::Meta is stacked. every single one of these beautiful humans showed up and helped, and we are forever grateful. no cap. π
Ansgar Burchardt <ansgar@cpan.org>Avar Arnfjord Bjarmason <avar@cpan.org>Benjamin Noggle <agwind@users.noreply.github.com>Christopher J. Madsen <cjm@cpan.org>Chuck Adams <cja987@gmail.com>Cory G Watson <gphat@cpan.org>Damyan Ivanov <dam@cpan.org>David Golden <xdg@xdg.me>Eric Wilhelm <ewilhelm@cpan.org>Graham Knop <haarg@haarg.org>Gregor Hermann <gregoa@debian.org>Karen Etheridge <ether@cpan.org>Kenichi Ishigaki <ishigaki@cpan.org>Kent Fredric <kentfredric@gmail.com>Ken Williams <kwilliams@cpan.org>Lars Dieckow <daxim@cpan.org>Leon Timmermans <leont@cpan.org>majensen <maj@fortinbras.us>Mark Fowler <markf@cpan.org>Matt S Trout <mst@shadowcat.co.uk>Michael G. Schwern <mschwern@cpan.org>Mohammad S Anwar <mohammad.anwar@yahoo.com>mohawk2 <mohawk2@users.noreply.github.com>moznion <moznion@gmail.com>Niko Tyni <ntyni@debian.org>Olaf Alders <olaf@wundersolutions.com>Olivier MenguΓ© <dolmen@cpan.org>Randy Sims <randys@thepierianspring.org>Tomohiro Hosaka <bokutin@bokut.in>
like, look at that list. literal legends, every one of them. π β¨
π COPYRIGHT AND LICENSE π
the legal tea, bestie β and yes we're saying it plainly so nobody has to squint at fine print:
This software is copyright (c) 2010 by David Golden, Ricardo Signes, Adam Kennedy and Contributors.
and the licensing vibe? it's giving freedom. π¦ this is free software β you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. so go off, honestly. just keep those terms intact while you do it.
aaaand that's the whole page, bestie! π you just read CPAN::Meta(3pm) from the Perl v5.42.3 docs, dated 2026-11-03 β yes, that's the real date on this bad boy, go check, i'll wait. π now go build something iconic with your metadata. mwah! πβ¨π
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms