Parse::Distname(3pm) | User Contributed Perl Documentation | Parse::Distname(3pm) |
Parse::Distname - parse a distribution name
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
Parse::Distname is yet another distribution name parser. It works almost the same as CPAN::DistnameInfo, but Parse::Distname takes a different approach. It tries to extract a version part of a distribution and treat the rest as a distribution name, contrary to CPAN::DistnameInfo which tries to define a name part and treat 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.
Parse::Distname exports one function "parse_distname" if requested. It returns a hash reference, with the following keys as of this writing:
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
say parse_distname('Dist-0.01.tar.gz')->{pause_id}; # (undef, not LOCAL)
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).
say parse_distname('AUTHOR/sub/Dist-0.01.tar.gz')->{name_and_version}; # Dist-0.01
say parse_distname('AUTHOR/sub/Dist-0.01.tar.gz')->{name}; # Dist say parse_distname('AUTHOR/v0.1.tar.gz')->{name}; # (empty)
say parse_distname('AUTHOR/Dist.tar.gz')->{version}; # (undef) say parse_distname('AUTHOR/Dist-0.01-TRIAL.tar.gz')->{version}; # 0.01-TRIAL
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
For compatibility with CPAN::DistnameInfo, Parse::Distname has the same methods/accessors, so you can use it as a drop-in replacement.
In addition, "is_perl6" and "version_number" are available.
CPAN::DistnameInfo
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.
2022-10-13 | perl v5.34.0 |