NAME
URI::PackageURL - Perl extension for Package URL (aka "purl")
SYNOPSIS
use URI::PackageURL;
# OO-interface
# Encode components in Package URL string
$purl = URI::PackageURL->new(
type => cpan,
namespace => 'GDT',
name => 'URI-PackageURL',
version => '2.21'
);
say $purl; # pkg:cpan/GDT/URI-PackageURL@2.20
# Parse Package URL string
$purl = URI::PackageURL->from_string('pkg:cpan/GDT/URI-PackageURL@2.20');
# exported functions
$purl = decode_purl('pkg:cpan/GDT/URI-PackageURL@2.20');
say $purl->type; # cpan
$purl_string = encode_purl(type => cpan, name => 'URI::PackageURL', version => '2.21');
say $purl_string; # pkg:cpan/URI::PackageURL@2.20
DESCRIPTION
This module converts Package URL components to "purl" string and vice versa.
A Package URL (aka "purl") is a URL string used to identify and locate a software package in a mostly universal and uniform way across programing languages, package managers, packaging conventions, tools, APIs and databases.
https://github.com/package-url/purl-spec
A purl is a URL composed of seven components:
scheme:type/namespace/name@version?qualifiers#subpath
Components are separated by a specific character for unambiguous parsing.
The definition for each components is:
"scheme": this is the URL scheme with the constant value of "pkg". One of the primary reason for this single scheme is to facilitate the future official registration of the "pkg" scheme for package URLs. Required.
"type": the package "type" or package "protocol" such as cpan, maven, npm, nuget, gem, pypi, etc. Required.
"namespace": some name prefix such as a Maven groupid, a Docker image owner, a GitHub user or organization. Optional and type-specific.
"name": the name of the package. Required.
"version": the version of the package. Optional.
"qualifiers": extra qualifying data for a package such as an OS, architecture, a distro, etc. Optional and type-specific.
"subpath": extra subpath within a package, relative to the package root. Optional.
CPAN PURL TYPE
cpan
is an official "purl" type (https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst)
The default repository is
https://www.cpan.org/
.The
namespace
:To refer to a CPAN distribution name, the
namespace
MUST be present. In this case, the namespace is the CPAN id of the author/publisher. It MUST be written uppercase, followed by the distribution name in the name component. A distribution name MUST NOT contain the string::
.To refer to a CPAN module, the
namespace
MUST be absent. The module name MAY contain zero or more::
strings, and the module name MUST NOT contain a-
The
name
is the module or distribution name and is case sensitive.The
version
is the module or distribution version.Optional qualifiers may include:
repository_url
: CPAN/MetaCPAN/BackPAN/DarkPAN repository base URL (default is https://www.cpan.org)download_url
: URL of package or distributionvcs_url
: extra URL for a package version control systemext
: file extension (default is tar.gz)
Examples
pkg:cpan/Perl::Version@1.013
pkg:cpan/DROLSKY/DateTime@1.55
pkg:cpan/DateTime@1.55
pkg:cpan/GDT/URI-PackageURL
pkg:cpan/LWP::UserAgent
pkg:cpan/OALDERS/libwww-perl@6.76
pkg:cpan/URI
FUNCTIONAL INTERFACE
They are exported by default:
- $purl_string = encode_purl(%purl_components)
-
Converts the given Package URL components to "purl" string. Croaks on error.
This function call is functionally identical to:
$purl_string = URI::PackageURL->new(%purl_components)->to_string;
- $purl_components = decode_purl($purl_string)
-
Converts the given "purl" string to Package URL components. Croaks on error.
This function call is functionally identical to:
$purl = URI::PackageURL->from_string($purl_string);
OBJECT-ORIENTED INTERFACE
- $purl = URI::PackageURL->new(%components)
-
Create new URI::PackageURL instance using provided Package URL components (type, name, version ,etc).
- $purl->type
-
The package "type" or package "protocol" such as cpan, maven, npm, nuget, gem, pypi, etc.
- $purl->namespace
-
Some name prefix such as a Maven groupid, a Docker image owner, a GitHub user or organization. Optional and type-specific.
- $purl->name
-
The "name" of the package.
- $purl->version
-
The "version" of the package.
- $purl->qualifiers
-
Extra qualifying data for a package such as an OS, architecture, a distro, etc.
- $purl->subpath
-
Extra subpath within a package, relative to the package root.
- $purl->to_string
-
Stringify Package URL components.
- $purl->to_urls
-
Return download and/or repository URLs.
- $purl->TO_JSON
-
Helper method for JSON modules (JSON, JSON::PP, JSON::XS, Mojo::JSON, etc).
use Mojo::JSON qw(encode_json); say encode_json($purl); # {"name":"URI-PackageURL","namespace":"GDT","qualifiers":null,"subpath":null,"type":"cpan","version":"2.20"}
- $purl = URI::PackageURL->from_string($purl_string);
-
Converts the given "purl" string to Package URL components. Croaks on error.
SUPPORT
Bugs / Feature Requests
Please report any bugs or feature requests through the issue tracker at https://github.com/giterlizzi/perl-URI-PackageURL/issues. You will be notified automatically of any progress on your issue.
Source Code
This is open source software. The code repository is available for public review and contribution under the terms of the license.
https://github.com/giterlizzi/perl-URI-PackageURL
git clone https://github.com/giterlizzi/perl-URI-PackageURL.git
AUTHOR
Giuseppe Di Terlizzi <gdt@cpan.org>
LICENSE AND COPYRIGHT
This software is copyright (c) 2022-2024 by Giuseppe Di Terlizzi.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.