NAME
URI::PackageURL - Perl extension for Package URL (aka "purl")
SYNOPSIS
use URI::PackageURL;
# OO-interface
# Encode components in PackageURL string
$purl = URI::PackageURL->new(
type => cpan,
namespace => 'GDT',
name => 'URI-PackageURL',
version => '2.03'
);
say $purl; # pkg:cpan/GDT/URI-PackageURL@2.03
# Parse PackageURL string
$purl = URI::PackageURL->from_string('pkg:cpan/URI-PackageURL@2.03');
# exported funtions
$purl = decode_purl('pkg:cpan/GDT/URI-PackageURL@2.03');
say $purl->type; # cpan
$purl_string = encode_purl(type => cpan, name => 'URI-PackageURL', version => '2.03');
say $purl_string; # pkg:cpan/URI-PackageURL@2.03
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 defintion 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 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.
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 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.03"}
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-2023 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.