Parse::CPAN::Meta - Parse META.yml and other similar CPAN metadata files
############################################# # 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};
Parse::CPAN::Meta is a parser for META.json and META.yml files, using JSON.pm and/or CPAN::Meta::YAML.
Parse::CPAN::Meta provides three methods: load_file, load_json_string, and load_yaml_string. These will read and deserialize CPAN metafiles, and are described below in detail.
load_file
load_json_string
load_yaml_string
Parse::CPAN::Meta provides a legacy API of only two functions, based on the YAML functions of the same name. Wherever possible, identical calling semantics are used.
All error reporting is done with exceptions (die'ing).
Note that META files are expected to be in UTF-8 encoding, only.
my $metadata_structure = Parse::CPAN::Meta->load_file('META.json'); my $metadata_structure = Parse::CPAN::Meta->load_file('META.yml');
This method will read the named file and deserialize it to a data structure, determining whether it should be JSON or YAML based on the filename.
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.)
my $metadata_structure = Parse::CPAN::Meta->load_json_string( $json_string);
This method deserializes the given string of JSON and the result. If the JSON module is loaded, it will be used, otherwise, JSON::PP will be loaded and used instead.
For maintenance clarity, no functions are exported. These functions are available for backwards compatibility only and are best avoided in favor of load_file.
my @yaml = Parse::CPAN::Meta::Load( $string );
Parses a string containing a valid YAML stream into a list of Perl data structures.
my @yaml = Parse::CPAN::Meta::LoadFile( 'META.yml' );
Reads the YAML stream from a file instead of a string.
Bugs should be reported via the CPAN bug tracker at
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Parse-CPAN-Meta
Adam Kennedy <adamk@cpan.org>
Copyright 2006 - 2010 Adam Kennedy.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
To install Parse::CPAN::Meta, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Parse::CPAN::Meta
CPAN shell
perl -MCPAN -e shell install Parse::CPAN::Meta
For more information on module installation, please visit the detailed CPAN module installation guide.