Information about a perl module distribution
version 0.925
my $dist = Dist::Metadata->new(file => $path_to_archive); my $description = sprintf "Dist %s (%s)", $dist->name, $dist->version; my $provides = $dist->package_versions; while( my ($package, $version) = each %$provides ){ print "$description includes $package $version\n"; }
This module provides an easy interface for getting various metadata about a Perl module distribution.
It takes care of the common logic of:
reading a tar file (Archive::Tar)
finding and reading the correct \s-1META\s0 file if the distribution contains one (CPAN::Meta)
and determining some of the metadata if there is no \s-1META\s0 file (Module::Metadata, CPAN::DistnameInfo)
This is mostly a wrapper around CPAN::Meta providing an easy interface to find and load the meta file from a tar.gz file. A dist can also be represented by a directory or merely a structure of data.
If the dist does not contain a meta file the module will attempt to determine some of that data from the dist.
\s-1NOTE\s0: This interface is still being defined. Please submit any suggestions or concerns.
Dist::Metadata->new(file => $path);
A dist can be represented by a tar file, a directory, or a data structure.
The format will be determined by the presence of the following options (checked in this order):
\*(C`struct\*(C' - hash of data to build a mock dist; See Dist::Metadata::Struct.
\*(C`dir\*(C' - path to the root directory of a dist
\*(C`file\*(C' - the path to a .tar.gz file
You can also slyly pass in your own object as a \*(C`dist\*(C' parameter in which case this module will just use that. This can be useful if you need to use your own subclass (perhaps while developing a new format).
Other options that can be specified:
\*(C`name\*(C' - dist name
\*(C`version\*(C' - dist version
\*(C`determine_packages\*(C' - boolean to indicate whether dist should be searched for packages if no \s-1META\s0 file is found. Defaults to true.
\*(C`include_inner_packages\*(C' - When determining provided packages the default behavior is to only include packages that match the name of the file that defines them (like \*(C`Foo::Bar\*(C' matches \*(C`*/Bar.pm\*(C'). This way only modules that can be loaded (via \*(C`use\*(C' or \*(C`require\*(C') will be returned (and \*(L"inner\*(R" packages will be ignored). This mimics the behavior of \s-1PAUSE\s0. Set this to true to include any \*(L"inner\*(R" packages provided by the dist (that are not otherwise excluded by another mechanism (such as \*(C`no_index\*(C')).
Returns the dist object (subclass of Dist::Metadata::Dist).
Returns a hashref of default values used to initialize a CPAN::Meta object when a \s-1META\s0 file is not found. Called from \*(L"determine_metadata\*(R".
Examine the dist and try to determine metadata. Returns a hashref which can be passed to \*(L"new\*(R" in CPAN::Meta. This is used when the dist does not contain a \s-1META\s0 file.
my $provides = $dm->determine_packages($meta);
Attempt to determine packages provided by the dist. This is used when the \s-1META\s0 file does not include a \*(C`provides\*(C' section and \*(C`determine_packages\*(C' is not set to false in the constructor.
If a CPAN::Meta object is not provided a default one will be used. Files contained in the dist and packages found therein will be checked against the meta object's \*(C`no_index\*(C' attribute (see \*(L"should_index_file\*(R" in CPAN::Meta and \*(L"should_index_package\*(R" in CPAN::Meta). By default this ignores any files found in inc/, t/, or xt/ directories.
Loads the metadata from the \*(L"dist\*(R".
Returns the CPAN::Meta instance in use.
$meta = $dm->meta_from_struct(\%struct);
Passes the the provided \*(C`\%struct\*(C' to \*(L"create\*(R" in CPAN::Meta and returns the result.
$pv = $dm->package_versions(); # { 'Package::Name' => '1.0', 'Module::2' => '2.1' }
Returns a simplified version of \*(C`provides\*(C': a hashref with package names as keys and versions as values.
This can also be called as a class method which will operate on a passed in hashref.
$pv = Dist::Metadata->package_versions(\%provides);
Returns a hashref of meta data for each of the packages provided by this dist.
The hashref starts with the same data as \*(L"provides\*(R" but additional data can be added to the output by specifying options in a hashref: Use the specified algorithm to compute a hex digest of the file. The type you specify will be the key in the returned hashref. You can use an arrayref to specify more than one type. $dm->module_info({checksum => ['sha256', 'md5']}); # returns: { 'Mod::Name' => { file => 'lib/Mod/Name.pm', version => '0.1', md5 => '258e88dcbd3cd44d8e7ab43f6ecb6af0', sha256 => 'f22136124cd3e1d65a48487cecf310771b2fd1e83dc032e3d19724160ac0ff71', }, } See \*(L"file_checksum\*(R" in Dist::Metadata::Dist for more information. The default is to start with the hashref returned from \*(L"provides\*(R" but you can pass in an alternate hashref using this key.
Other options may be added in the future.
The following methods are available on this object and simply call the corresponding method on the CPAN::Meta object.
name
provides
version
More tests
\*(C`trust_meta\*(C' option (to allow setting it to false)
Guess main module from dist name if no packages can be found
Determine abstract?
Add change log info (CPAN::Changes)?
Subclass as \*(C`CPAN::Dist::Metadata\*(C' just so that it has \*(C`CPAN\*(C' in the name?
Use File::Find::Rule::Perl?
CPAN::Meta
Module::Metadata
CPAN::DistnameInfo
MyCPAN::Indexer
CPAN::ParseDistribution
You can find documentation for this module with the perldoc command.
perldoc Dist::Metadata
The following websites have more information about this module, and may be of help to you. As always, in addition to those websites please use your favorite search engine to discover more resources.
Search \s-1CPAN\s0 The default \s-1CPAN\s0 search engine, useful to view \s-1POD\s0 in \s-1HTML\s0 format. http://search.cpan.org/dist/Dist-Metadata <http://search.cpan.org/dist/Dist-Metadata>
\s-1RT:\s0 \s-1CPAN\s0's Bug Tracker The \s-1RT\s0 ( Request Tracker ) website is the default bug/issue tracking system for \s-1CPAN\s0. http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dist-Metadata <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dist-Metadata>
\s-1CPAN\s0 Ratings The \s-1CPAN\s0 Ratings is a website that allows community ratings and reviews of Perl modules. http://cpanratings.perl.org/d/Dist-Metadata <http://cpanratings.perl.org/d/Dist-Metadata>
\s-1CPAN\s0 Testers The \s-1CPAN\s0 Testers is a network of smokers who run automated tests on uploaded \s-1CPAN\s0 distributions. http://www.cpantesters.org/distro/D/Dist-Metadata <http://www.cpantesters.org/distro/D/Dist-Metadata>
\s-1CPAN\s0 Testers Matrix The \s-1CPAN\s0 Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms. http://matrix.cpantesters.org/?dist=Dist-Metadata <http://matrix.cpantesters.org/?dist=Dist-Metadata>
\s-1CPAN\s0 Testers Dependencies The \s-1CPAN\s0 Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution. <http://deps.cpantesters.org/?module=Dist::Metadata>
Please report any bugs or feature requests by email to \*(C`bug-dist-metadata at rt.cpan.org\*(C', or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dist-Metadata <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dist-Metadata>. You will be automatically notified of any progress on the request by the system.
https://github.com/rwstauner/Dist-Metadata <https://github.com/rwstauner/Dist-Metadata>
git clone https://github.com/rwstauner/Dist-Metadata.git
Randy Stauner <[email protected]>
This software is copyright (c) 2011 by Randy Stauner.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.