Parse::...Packages(3)
π
Parse::CPAN::Packages π
okay bestie, welcome to the User Contributed Perl Documentation page for Parse::...Packages(3). yes, the manual name has that little ellipsis moment, but the module is Parse::CPAN::Packages, and it is fully here to parse 02packages.details.txt.gz. we are gonna get into it, no cap. π«Άβ¨
πΈ NAME πΈ
Parse::CPAN::Packagesβ Parse02packages.details.txt.gz
β¨ SYNOPSIS β¨
okay so this is the whole synopsis vibe, copy-paste ready:
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;
π¦ DESCRIPTION π¦
okay so the Comprehensive Perl Archive Network (CPAN) is a very useful collection of Perl code, literally iconic. it has several indices of the files that it hosts, including a file named 02packages.details.txt.gz in the modules directory. that file contains lots of useful information, and this module provides a simple interface to the data contained within. slay. π
and a lil future tea: in a future release Parse::CPAN::Packages::Package and Parse::CPAN::Packages::Distribution might have more information. π
π§ Methods π§
new
Creates a new instance from a details file.
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);
package($packagename)
Returns a Parse::CPAN::Packages::Package that represents the named package.
my $p = Parse::CPAN::Packages->new($gzfilename);
my $package = $p->package("Acme::Colour");
packages()
Returns a list of Parse::CPAN::Packages::Package objects representing all the packages that were extracted from the file.
package_count()
Returns the number of packages stored.
distribution($filename)
Returns a Parse::CPAN::Packages::Distribution object that represents the filename passed:
my $p = Parse::CPAN::Packages->new($gzfilename);
my $dist = $p->distribution('L/LB/LBROCARD/Acme-Colour-1.00.tar.gz');
distributions()
Returns a list of Parse::CPAN::Packages::Distribution objects representing all the known distributions.
distribution_count()
Returns the number of distributions stored.
latest_distribution($distname)
Returns the Parse::CPAN::Packages::Distribution object that represents the latest distribution for the named disribution passed, that is to say it returns the distribution that has the highest version number (as determined by version.pm or number comparison if that fails):
my $p = Parse::CPAN::Packages->new($gzfilename);
my $dist = $p->distribution('Acme-Color');
latest_distrbutions()
Returns a list of Parse::CPAN::Packages::Distribution objects representing all the latest distributions.
latest_distribution_count()
Returns the number of distributions stored.
π Preamble Methods π
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.
file()url()description()columns()intended_for()written_by()line_count()last_updated()
π¦ Addtional Methods π¦
These are additional methods that you may find useful.
parse($filename)
Parses the filename. Works in a similar fashion to the the constructor (i.e. you can pass it a filename for a compressed/1uncompressed file, a uncompressed scalar containing the file. You can also pass nothing to indicate to load the compressed file from the current working directory.)
Note that each time this function is run the packages and distribtions found will be "added" to the current list of packages.
add_quick($package_name, $package_version, $prefix)
Quick way of adding a new package and distribution.
add_package($package_obj)
Adds a package. Note that youβll probably want to add the corrisponding distribution for that package too (itβs not done automatically.)
add_distribution($distribution_obj)
Adds a distribution. Note that youβll probably want to add the corresponding packages for that distribution too (itβs not done automatically.)
distribution_from_prefix($prefix)
Returns a distribution given a prefix.
latest_distributions
Returns all the latest distributions:
my @distributions = $p->latest_distributions;
π AUTHOR π
Leon Brocard <acme@astray.com>
π COPYRIGHT π
Copyright (C) 2004-9, Leon Brocard
π LICENSE π
This module is free software; you can redistribute it or modify it under the same terms as Perl itself.
π BUGS π
β οΈ bestie, bug alert: 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.
π₯ TODO π₯
delete_*methods.merge_intomethod.- Documentation for other modules.
π SEE ALSO π
CPAN::DistInfoname, Parse::CPAN::Packages::Writer.
mwah π this page was brought to you by perl v5.42.0, dated 2015-04-14, under the User Contributed Perl Documentation banner for Parse::...Packages(3). bye bestie, go parse something cute π«Άβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Parse-CPAN-Packages 2.40-bp160.1.11 Β· Artistic-1.0 or GPL-1.0+
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms