Parse::Distname(3pm)
β¨ Parse::Distname β¨
okay bestie, welcome to the User Contributed Perl Documentation corner of the man pages π this is Parse::Distname β a 3pm manual page β and it is lowkey one of the cutest little parsers out there. let's get into it π«Ά
π NAME π
Parse::Distname β parse a distribution name πΈ
π¦ SYNOPSIS π¦
use Parse::Distname 'parse_distname';
my $info = parse_distname('ISHIGAKI/Parse-Distname-0.01.tar.gz');
# for compatibility with CPAN::DistnameInfo
my $info_obj = Parse::Distname->new('ISHIGAKI/Parse-Distname-0.01.tar.gz');
say $info_obj->dist; # Parse-Distname
π DESCRIPTION π
so Parse::Distname is yet another distribution name parser π it works almost the same as CPAN::DistnameInfo, BUT it takes a different approach, and that's the whole vibe.
the way it does it: it tries to extract a version part of a distribution and treat the rest as a distribution name. CPAN::DistnameInfo is the opposite girlie β she tries to define a name part and treats the rest as a version. π
because of this difference, when Parse::Distname parses a weird distribution name such as "AUTHOR/v1.0.tar.gz", it says the name is empty and the version is "v1.0", while CPAN::DistnameInfo says the name is "v" and the version is "1.0". π see test files in this distribution if you need more details. as of this writing, Parse::Distname returns a different result for about 200+ distributions among about 320000 BackPan distributions. it's giving "not like other parsers" and honestly? iconic π
π FUNCTION π
Parse::Distname exports one function, parse_distname, if requested. it returns a hash reference</>, with the following keys as of this writing:
β arg
the path you passed to the function. if what you passed is some kind of an object (of Path::Tiny, for example), it's stringified. β¨
π§ cpan_path
a relative path to the distribution, whose base directory is assumed CPAN/authors/id/. if org_path doesn't contain a pause_id, the distribution is assumed to belong to LOCAL user. for example,
say parse_distname('Dist-0.01.tar.gz')->{cpan_path};
# L/LO/LOCAL/Dist-0.01.tar.gz
if you only gives a pause_id, parent directories are supplemented. π«Ά
say parse_distname('ISHIGAKI/Dist-0.01.tar.gz')->{cpan_path};
# I/IS/ISHIGAKI/Dist-0.01.tar.gz
πΈ pause_id
the pause_id of the distribution. contrary to the above, this is empty if you don't give a pause_id. no cap.
say parse_distname('Dist-0.01.tar.gz')->{pause_id};
# (undef, not LOCAL)
π¦ subdir
a PAUSE distribution may be put into a subdirectory under the author directory. if the name contains such a subdirectory, it's kept here. π
say parse_distname('AUTHOR/sub/Dist-0.01.tar.gz')->{subdir};
# sub
Perl 6 distributions are (almost) always put under Perl6/ subdirectory under each author's directory (with a few exceptions). π
π name_and_version
the name and version of the distribution, without an extension and directory parts, which should not be empty as long as the distribution has an extension that PAUSE accepts.
say parse_distname('AUTHOR/sub/Dist-0.01.tar.gz')->{name_and_version};
# Dist-0.01
β¨ name
the name part of the distribution. this may be empty if no valid name is found π
say parse_distname('AUTHOR/sub/Dist-0.01.tar.gz')->{name};
# Dist
say parse_distname('AUTHOR/v0.1.tar.gz')->{name};
# (empty)
π version
the version part of the distribution. this also may be empty, and this may not always be a valid version, and may have a following part such as "-TRIAL". π
say parse_distname('AUTHOR/Dist.tar.gz')->{version};
# (undef)
say parse_distname('AUTHOR/Dist-0.01-TRIAL.tar.gz')->{version};
# 0.01-TRIAL
π version_number
the first numerical part of the version. this also may be empty, and this may not always be a valid version.
say parse_distname('AUTHOR/Dist-0.01-TRIAL.tar.gz')->{version_number};
# 0.01
say parse_distname('AUTHOR/Dist-0_0_1.tar.gz')->{version_number};
# 0_0_1
π extension
the extension of the distribution. if no valid extension is found, parse_distname returns false (undef). β οΈ
π§ is_perl6
for convenience, if subdir exists and it starts with Perl6/, this becomes true. β
π is_dev
if the version looks like "\d+.\d+_\d+", or contains "-TRIAL", this becomes true. PAUSE treats such a distribution as a developer's release and doesn't list it in its indices. π
π METHODS π
for compatibility with CPAN::DistnameInfo, Parse::Distname has the same methods/accessors, so you can use it as a drop-in replacement. slay. π«Ά
in addition, "is_perl6" and "version_number" are available. β¨
π SEE ALSO π
CPAN::DistnameInfo
π AUTHOR π
Kenichi Ishigaki, <ishigaki@cpan.org> π
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2018 by Kenichi Ishigaki.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. π
and that's the whole page bestie, no filler, every single key accounted for π
mwah π this was perl v5.36.0, dated 2022-10-13, and yes it's the Parse::Distname(3pm) page β go parse something cute, you got this π¦β¨
π¦ where this page comes from
- ubuntu noble: libparse-distname-perl 0.05-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libparse-distname-perl 0.05-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libparse-distname-perl 0.05-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms