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

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