Parse::Distname(3pm)

πŸ“¦
version 0.05 Β· 6 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

✨ 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> πŸ’Œ


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