Parse::CPAN::Meta(3pm)
π Parse::CPAN::Meta π
okay bestie, this is the Parse::CPAN::Meta(3pm) page from the Perl Programmers Reference Guide, and it's literally here to handle your CPAN metadata so you don't have to π
πΈ NAME πΈ
Parse::CPAN::Meta parses META.yml and META.json CPAN metadata files β and yes, it ate β¨
β¨ VERSION β¨
version 2.150010 β that's the one, bestie π«Ά
π¦ SYNOPSIS π¦
here's the whole vibe: first your file, then your program. metadata main-character energy π
#############################################
# In your file
---
name: My-Distribution
version: 1.23
resources:
homepage: "http://example.com/dist/My-Distribution"
#############################################
# In your program
use Parse::CPAN::Meta;
my $distmeta = Parse::CPAN::Meta->load_file('META.yml');
# Reading properties
my $name = $distmeta->{name};
my $version = $distmeta->{version};
my $homepage = $distmeta->{resources}{homepage};
πΈ DESCRIPTION πΈ
okay so Parse::CPAN::Meta is a parser for META.json and META.yml files, using JSON::PP and/or CPAN::Meta::YAML. it's giving βI speak both JSON and YAMLβ and we love that for it π
Parse::CPAN::Meta provides three methods: load_file, load_json_string, and load_yaml_string. these read and deserialize CPAN metafiles, and they're described below in detail β no gatekeeping π
it also provides a legacy API of only two functions, based on the YAML functions of the same name. wherever possible, identical calling semantics are used. these may only be used with YAML sources, noted π
all error reporting is done with exceptions (die'ing). so yeah, if something's wrong it throws β it does not quietly ghost you π
π¨ note that META files are expected to be in UTF-8 encoding, only. when converted string data, it must first be decoded from UTF-8. that's a real one, bestie.
π METHODS π
π load_file π
my $metadata_structure = Parse::CPAN::Meta->load_file('META.json');
my $metadata_structure = Parse::CPAN::Meta->load_file('META.yml');
this method reads the named file and deserializes it to a data structure, determining whether it should be JSON or YAML based on the filename. the file will be read using the :utf8 IO layer. slay π¦
π load_yaml_string π
my $metadata_structure = Parse::CPAN::Meta->load_yaml_string($yaml_string);
this method deserializes the given string of YAML and returns the first document in it. (CPAN metadata files should always have only one document.) if the source was UTF-8 encoded, the string must be decoded before calling load_yaml_string β¨
π load_json_string π
my $metadata_structure = Parse::CPAN::Meta->load_json_string($json_string);
this method deserializes the given string of JSON and gives you the result. if the source was UTF-8 encoded, the string must be decoded before calling load_json_string π«Ά
π load_string π
my $metadata_structure = Parse::CPAN::Meta->load_string($some_string);
if you don't know whether a string contains YAML or JSON data, this method will use some heuristics and guess. if it can't tell, it assumes YAML. mystery solved, bestie π₯
π yaml_backend π
my $backend = Parse::CPAN::Meta->yaml_backend;
returns the module name of the YAML serializer. see βENVIRONMENTβ for details π
π json_backend π
my $backend = Parse::CPAN::Meta->json_backend;
returns the module name of the JSON serializer. if CPAN_META_JSON_BACKEND is set, this will be whatever that's set to. if not, this will either be JSON::PP or JSON. if PERL_JSON_BACKEND is set, this will return JSON as further delegation is handled by the JSON module. see βENVIRONMENTβ for details π
π json_decoder π
my $decoder = Parse::CPAN::Meta->json_decoder;
returns the module name of the JSON decoder. unlike json_backend, this is not necessarily a full JSON-style module, but only something that will provide a decode_json subroutine. if CPAN_META_JSON_DECODER is set, this will be whatever that's set to. if not, this will be whatever has been selected as json_backend. see βENVIRONMENTβ for more notes β
π«Ά FUNCTIONS π«Ά
for maintenance clarity, no functions are exported by default. these functions are available for backwards compatibility only and are best avoided in favor of load_file β iconic advice, honestly π
β Load β
my @yaml = Parse::CPAN::Meta::Load( $string );
parses a string containing a valid YAML stream into a list of Perl data structures.
β LoadFile β
my @yaml = Parse::CPAN::Meta::LoadFile( 'META.yml' );
reads the YAML stream from a file instead of a string.
π₯ ENVIRONMENT π₯
π CPAN_META_JSON_DECODER π
by default, JSON::PP will be used for deserializing JSON data. if the CPAN_META_JSON_DECODER environment variable exists, this is expected to be the name of a loadable module that provides a decode_json subroutine, which will then be used for deserialization. relying only on the existence of said subroutine allows for maximum compatibility, since this API is provided by all of JSON::PP, JSON::XS, Cpanel::JSON::XS, JSON::MaybeXS, JSON::Tiny, and Mojo::JSON. periodt π
π CPAN_META_JSON_BACKEND π
by default, JSON::PP will be used for deserializing JSON data. if the CPAN_META_JSON_BACKEND environment variable exists, this is expected to be the name of a loadable module that provides the JSON API, since downstream code expects to be able to call new on this class. as such, while JSON::PP, JSON::XS, Cpanel::JSON::XS and JSON::MaybeXS will work for this, to use Mojo::JSON or JSON::Tiny for decoding requires setting CPAN_META_JSON_DECODER π§
π PERL_JSON_BACKEND π
if the CPAN_META_JSON_BACKEND environment variable does not exist, and if PERL_JSON_BACKEND environment variable exists, is true and is not JSON::PP, then the JSON module (version 2.5 or greater) will be loaded and used to interpret PERL_JSON_BACKEND. if JSON is not installed or is too old, an exception will be thrown. note that at the time of writing, the only useful values are 1, which will tell JSON to guess, or JSON::XS β if you want to use a newer JSON module, see CPAN_META_JSON_BACKEND π₯
π PERL_YAML_BACKEND π
by default, CPAN::Meta::YAML will be used for deserializing YAML data. if the PERL_YAML_BACKEND environment variable is defined, then it is interpreted as a module to use for deserialization. the given module must be installed, must load correctly and must implement the Load() function or an exception will be thrown. no cap π
π AUTHORS π
the icons behind this:
- David Golden β
dagolden@cpan.org - Ricardo Signes β
rjbs@cpan.org - Adam Kennedy β
adamk@cpan.org
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2010 by David Golden, Ricardo Signes, Adam Kennedy and Contributors.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the manual, bestie π«Ά this copy is perl v5.42.3, dated 2026-11-03, for Parse::CPAN::Meta(3pm) β slay, goodbye, and may your metadata always parse π
π¦ 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