Parse::CPAN::Packages(3pm) | User Contributed Perl Documentation | Parse::CPAN::Packages(3pm) |
Parse::CPAN::Packages - Parse 02packages.details.txt.gz
use Parse::CPAN::Packages; # must have downloaded my $p = Parse::CPAN::Packages->new("02packages.details.txt.gz"); # either a filename as above or pass in the contents of the file # (uncompressed) my $p = Parse::CPAN::Packages->new($packages_details_contents); my $m = $p->package("Acme::Colour"); # $m is a Parse::CPAN::Packages::Package object print $m->package, "\n"; # Acme::Colour print $m->version, "\n"; # 1.00 my $d = $m->distribution(); # $d is a Parse::CPAN::Packages::Distribution object print $d->prefix, "\n"; # L/LB/LBROCARD/Acme-Colour-1.00.tar.gz print $d->dist, "\n"; # Acme-Colour print $d->version, "\n"; # 1.00 print $d->maturity, "\n"; # released print $d->filename, "\n"; # Acme-Colour-1.00.tar.gz print $d->cpanid, "\n"; # LBROCARD print $d->distvname, "\n"; # Acme-Colour-1.00 # all the package objects my @packages = $p->packages; # all the distribution objects my @distributions = $p->distributions; # the latest distribution $d = $p->latest_distribution("Acme-Colour"); is($d->prefix, "L/LB/LBROCARD/Acme-Colour-1.00.tar.gz"); is($d->version, "1.00"); # all the latest distributions my @distributions = $p->latest_distributions;
The Comprehensive Perl Archive Network (CPAN) is a very useful collection of Perl code. It has several indices of the files that it hosts, including a file named "02packages.details.txt.gz" in the "modules" directory. This file contains lots of useful information and this module provides a simple interface to the data contained within.
In a future release Parse::CPAN::Packages::Package and Parse::CPAN::Packages::Distribution might have more information.
The constructor can be passed either the path to the "02packages.details.txt.gz" file, a path to an ungzipped version of this file, or a scalar containing the entire uncompressed contents of the file.
Note that this module does not concern itself with downloading this file. You should do this yourself. For example:
use LWP::Simple qw(get); my $data = get("http://www.cpan.org/modules/02packages.details.txt.gz"); my $p = Parse::CPAN::Packages->new($data);
If you have a configured CPAN, then there's usually already a cached file available:
use CPAN; $CPAN::Be_Silent = 1; CPAN::HandleConfig->load; my $file = $CPAN::Config->{keep_source_where} . "/modules/02packages.details.txt.gz"; my $p = Parse::CPAN::Packages->new($file);
my $p = Parse::CPAN::Packages->new($gzfilename); my $package = $p->package("Acme::Colour");
my $p = Parse::CPAN::Packages->new($gzfilename); my $dist = $p->distribution('L/LB/LBROCARD/Acme-Colour-1.00.tar.gz');
my $p = Parse::CPAN::Packages->new($gzfilename); my $dist = $p->distribution('Acme-Color');
These methods return the information from the preamble at the start of the file. They return undef if for any reason no matching preamble line was found.
These are additional methods that you may find useful.
Note that each time this function is run the packages and distribtions found will be "added" to the current list of packages.
my @distributions = $p->latest_distributions;
Leon Brocard <acme@astray.com>
Copyright (C) 2004-9, Leon Brocard
This module is free software; you can redistribute it or modify it under the same terms as Perl itself.
This module leaks memory as packages hold distributions and distributions hold packages. No attempt has been made to fix this as it's not anticpated that this will be used in long running programs that will dispose of the objects once created.
The old interface for "new" where if you passed no arguments it would look for a "02packages.details.txt.gz" in your current directory is no longer supported.
delete_* methods. merge_into method. Documentation for other modules.
CPAN::DistInfoname, Parse::CPAN::Packages::Writer.
2022-06-16 | perl v5.34.0 |