The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Parse::CPAN::Meta - Parse META.yml and other similar CPAN metadata files

SYNOPSIS

    #############################################
    # 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

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.

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.

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 will read the named file and deserialize it to a data structure, determining whether it should be JSON or YAML based on the filename.

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.)

load_json_string

  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.

FUNCTIONS

For maintenance clarity, no functions are exported. These functions are available for backwards compatibility only and are best avoided in favor of load_file.

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.

SUPPORT

Bugs should be reported via the CPAN bug tracker at

http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Parse-CPAN-Meta

AUTHOR

Adam Kennedy <adamk@cpan.org>

COPYRIGHT

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.