Skip to content

Commit

Permalink
URI::PackageURL 2.11
Browse files Browse the repository at this point in the history
  • Loading branch information
giterlizzi committed Apr 20, 2024
1 parent 605279f commit 6cbede9
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/perltest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ jobs:
- name: Coverage
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: cover -test -report Coveralls
run: cover -test -report Coveralls || true
11 changes: 10 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
Revision history for Perl extension URI::PackageURL.
Revision history for URI::PackageURL.

2.11 2024-04-19
- Improved the cpan PURL type to be compatible with the 'PURL-TYPES' specification
(giterlizzi/perl-URI-PackageURL#8 - https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst)
- Added "luarocks" PURL type support
- Improved test suite (giterlizzi/perl-URI-PackageURL#11)
- Renamed CLI package in "URI::PackageURL::App"
- Changed JSON module pre-requisite to "JSON::PP" to be compatible with CPAN Toolchain
(giterlizzi/perl-URI-PackageURL#12)

2.04 2023-11-16
- Added "docker", "bitbuket", "golang" support to
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ examples/cpan-dist-download-and-test.sh
examples/rpm-to-purl.sh
INSTALL.md
lib/URI/PackageURL.pm
lib/URI/PackageURL/CLI.pm
lib/URI/PackageURL/App.pm
lib/URI/PackageURL/Util.pm
LICENSE
Makefile.PL
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ use URI::PackageURL;
# OO-interface

# Encode components in PackageURL string
$purl = URI::PackageURL->new(type => cpan, namespace => 'GDT', name => 'URI-PackageURL', version => '2.04');
$purl = URI::PackageURL->new(type => cpan, namespace => 'GDT', name => 'URI-PackageURL', version => '2.11');

say $purl; # pkg:cpan/GDT/URI-PackageURL@2.04
say $purl; # pkg:cpan/GDT/URI-PackageURL@2.11

# Parse PackageURL string
$purl = URI::PackageURL->from_string('pkg:cpan/GDT/URI-PackageURL@2.04');
$purl = URI::PackageURL->from_string('pkg:cpan/GDT/URI-PackageURL@2.11');

# exported functions

$purl = decode_purl('pkg:cpan/GDT/URI-PackageURL@2.04');
$purl = decode_purl('pkg:cpan/GDT/URI-PackageURL@2.11');
say $purl->type; # cpan

$purl_string = encode_purl(type => cpan, namespace => 'GDT', name => 'URI::PackageURL', version => '2.04');
$purl_string = encode_purl(type => cpan, namespace => 'GDT', name => 'URI::PackageURL', version => '2.11');
```


Expand All @@ -31,22 +31,22 @@ $purl_string = encode_purl(type => cpan, namespace => 'GDT', name => 'URI::Packa
Inspect and export "purl" string in various formats (JSON, YAML, Data::Dumper, ENV):

```console
$ purl-tool pkg:cpan/GDT/URI-PackageURL@2.04 --json | jq
$ purl-tool pkg:cpan/GDT/URI-PackageURL@2.11 --json | jq
{
"name": "URI-PackageURL",
"namespace": "GDT",
"qualifiers": {},
"subpath": null,
"type": "cpan",
"version": "2.04"
"version": "2.11"
}
```


Download package using "purl" string:

```console
$ wget $(purl-tool pkg:cpan/GDT/URI-PackageURL@2.04 --download-url)
$ wget $(purl-tool pkg:cpan/GDT/URI-PackageURL@2.11 --download-url)
```


Expand All @@ -57,7 +57,7 @@ Use "purl" string in your shell-scripts:

set -e

PURL="pkg:cpan/GDT/URI-PackageURL@2.04"
PURL="pkg:cpan/GDT/URI-PackageURL@2.11"

eval $(purl-tool "$PURL" --env)

Expand All @@ -79,7 +79,7 @@ Create on-the-fly a "purl" string:
$ purl-tool --type cpan \
--namespace GDT \
--name URI-PackageURL \
--version 2.04
--version 2.11
```


Expand Down Expand Up @@ -108,4 +108,4 @@ Using App::cpanminus:

## Copyright

- Copyright 2022-2023 © Giuseppe Di Terlizzi
- Copyright 2022-2024 © Giuseppe Di Terlizzi
14 changes: 7 additions & 7 deletions bin/purl-tool
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ purl-tool - Package URL tool
Parse the given Package URL string and return JSON and send the STDOUT to jq:
purl-tool pkg:cpan/GDT/URI-PackageURL@2.04 --json | jq
purl-tool pkg:cpan/GDT/URI-PackageURL@2.11 --json | jq
Download the package from the repository using Package URL string:
wget $(purl-tool pkg:cpan/GDT/URI-PackageURL@2.04 --download-url)
wget $(purl-tool pkg:cpan/GDT/URI-PackageURL@2.11 --download-url)
Create a canonical Package URL string
purl-tool --type cpan \
--namespace GDT \
--name URI-PackageURL \
--version 2.04
--version 2.11
=head1 DESCRIPTION
Expand All @@ -75,26 +75,26 @@ C<purl-tool> Package URL tool
Parse the given Package URL string and return JSON and send the STDOUT to L<jq>:
purl-tool pkg:cpan/GDT/URI-PackageURL@2.04 --json | jq
purl-tool pkg:cpan/GDT/URI-PackageURL@2.11 --json | jq
Download the package from the repository using Package URL string:
wget $(purl-tool pkg:cpan/GDT/URI-PackageURL@2.04 --download-url)
wget $(purl-tool pkg:cpan/GDT/URI-PackageURL@2.11 --download-url)
Create a canonical Package URL string:
purl-tool --type cpan \
--namespace GDT \
--name URI-PackageURL \
--version 2.04
--version 2.11
=head1 AUTHOR
L<Giuseppe Di Terlizzi|https://metacpan.org/author/gdt>
=head1 COPYRIGHT AND LICENSE
Copyright © 2022-2023 L<Giuseppe Di Terlizzi|https://metacpan.org/author/gdt>
Copyright © 2022-2024 L<Giuseppe Di Terlizzi|https://metacpan.org/author/gdt>
You may use and distribute this module according to the same terms
that Perl is distributed under.
16 changes: 8 additions & 8 deletions lib/URI/PackageURL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use constant PURL_DEBUG => $ENV{PURL_DEBUG};

use overload '""' => 'to_string', fallback => 1;

our $VERSION = '2.04_04';
our $VERSION = '2.11';
our @EXPORT = qw(encode_purl decode_purl);

my $PURL_REGEXP = qr{^pkg:[A-Za-z\\.\\-\\+][A-Za-z0-9\\.\\-\\+]*/.+};
Expand Down Expand Up @@ -367,21 +367,21 @@ URI::PackageURL - Perl extension for Package URL (aka "purl")
type => cpan,
namespace => 'GDT',
name => 'URI-PackageURL',
version => '2.10'
version => '2.11'
);
say $purl; # pkg:cpan/GDT/URI-PackageURL@2.10
say $purl; # pkg:cpan/GDT/URI-PackageURL@2.11
# Parse Package URL string
$purl = URI::PackageURL->from_string('pkg:cpan/GDT/URI-PackageURL@2.10');
$purl = URI::PackageURL->from_string('pkg:cpan/GDT/URI-PackageURL@2.11');
# exported functions
$purl = decode_purl('pkg:cpan/GDT/URI-PackageURL@2.10');
$purl = decode_purl('pkg:cpan/GDT/URI-PackageURL@2.11');
say $purl->type; # cpan
$purl_string = encode_purl(type => cpan, name => 'URI::PackageURL', version => '2.10');
say $purl_string; # pkg:cpan/URI::PackageURL@2.10
$purl_string = encode_purl(type => cpan, name => 'URI::PackageURL', version => '2.11');
say $purl_string; # pkg:cpan/URI::PackageURL@2.11
=head1 DESCRIPTION
Expand Down Expand Up @@ -497,7 +497,7 @@ Helper method for JSON modules (L<JSON>, L<JSON::PP>, L<JSON::XS>, L<Mojo::JSON>
use Mojo::JSON qw(encode_json);
say encode_json($purl); # {"name":"URI-PackageURL","namespace":"GDT","qualifiers":null,"subpath":null,"type":"cpan","version":"2.10"}
say encode_json($purl); # {"name":"URI-PackageURL","namespace":"GDT","qualifiers":null,"subpath":null,"type":"cpan","version":"2.11"}
=item $purl = URI::PackageURL->from_string($purl_string);
Expand Down
34 changes: 11 additions & 23 deletions lib/URI/PackageURL/App.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ use utf8;
use Getopt::Long qw( GetOptionsFromArray :config gnu_compat );
use Pod::Usage;
use Carp;
use JSON::PP;
use Data::Dumper;

use URI::PackageURL;

our $VERSION = '2.04_04';
our $VERSION = '2.11';

sub cli_error {
my ($error) = @_;
Expand Down Expand Up @@ -61,7 +63,7 @@ sub run {
say <<"VERSION";
$progname version $URI::PackageURL::VERSION
Copyright 2022-2023, Giuseppe Di Terlizzi <gdt\@cpan.org>
Copyright 2022-2024, Giuseppe Di Terlizzi <gdt\@cpan.org>
This program is part of the URI::PackageURL distribution and is free software;
you can redistribute it and/or modify it under the same terms as Perl itself.
Expand Down Expand Up @@ -133,27 +135,13 @@ VERSION
}

if ($options{format} eq 'json') {

if (eval { require JSON::PP }) {
print JSON::PP->new->canonical->pretty(1)->convert_blessed(1)->encode($purl);
return 0;
}

cli_error 'JSON module missing';
return 255;

print JSON::PP->new->canonical->pretty(1)->convert_blessed(1)->encode($purl);
return 0;
}

if ($options{format} eq 'dumper') {

if (eval { require Data::Dumper }) {
print Data::Dumper->new([$purl])->Indent(1)->Sortkeys(1)->Terse(1)->Useqq(1)->Dump;
return 0;
}

cli_error 'Data::Dumper module missing';
return 255;

print Data::Dumper->new([$purl])->Indent(1)->Sortkeys(1)->Terse(1)->Useqq(1)->Dump;
return 0;
}

if ($options{format} eq 'yaml') {
Expand Down Expand Up @@ -224,17 +212,17 @@ __END__
=head1 NAME
URI::PackageURL::CLI - URL::PackageURL (purl) Command Line Interface
URI::PackageURL::App - URL::PackageURL (purl) Command Line Interface
=head1 SYNOPSIS
use URI::PackageURL::CLI qw(run);
use URI::PackageURL::App qw(run);
run(\@ARGV);
=head1 DESCRIPTION
URI::PackageURL::CLI "Command Line Interface" helper module for C<purl-tool(1)>.
URI::PackageURL::App "Command Line Interface" helper module for C<purl-tool(1)>.
=over
Expand Down
8 changes: 4 additions & 4 deletions lib/URI/PackageURL/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use warnings;
use Carp;
use Exporter qw(import);

our $VERSION = '2.04_04';
our $VERSION = '2.11';
our @EXPORT = qw(purl_to_urls);

sub purl_to_urls {
Expand Down Expand Up @@ -446,13 +446,13 @@ C<cpan>, C<docker>, C<gem>, C<github>, C<gitlab>, C<luarocks>, C<maven>, C<npm>,
(*) Only with B<version> component
(**) Only if B<download_url> qualifier is provided
$urls = purl_to_urls('pkg:cpan/GDT/URI-PackageURL@2.10');
$urls = purl_to_urls('pkg:cpan/GDT/URI-PackageURL@2.11');
print Dumper($urls);
# $VAR1 = {
# 'repository' => 'https://metacpan.org/release/GDT/URI-PackageURL-2.10',
# 'download' => 'http://www.cpan.org/authors/id/G/GD/GDT/URI-PackageURL-2.10.tar.gz'
# 'repository' => 'https://metacpan.org/release/GDT/URI-PackageURL-2.11',
# 'download' => 'http://www.cpan.org/authors/id/G/GD/GDT/URI-PackageURL-2.11.tar.gz'
# };
=back
Expand Down
6 changes: 3 additions & 3 deletions t/40-cli.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use strict;
use warnings;

use Test::More;
use JSON;
use JSON::PP qw(decode_json);

use URI::PackageURL::App;

Expand All @@ -26,7 +26,7 @@ sub cmd {

}

my $t1 = 'pkg:cpan/GDT/URI-PackageURL@2.00';
my $t1 = 'pkg:cpan/GDT/URI-PackageURL@2.11';

subtest "App '$t1' (JSON output)" => sub {

Expand All @@ -41,7 +41,7 @@ subtest "App '$t1' (JSON output)" => sub {
is($test_2->{type}, 'cpan', 'JSON output: Type');
is($test_2->{namespace}, 'GDT', 'JSON output: Namespace');
is($test_2->{name}, 'URI-PackageURL', 'JSON output: Name');
is($test_2->{version}, '2.00', 'JSON output: Version');
is($test_2->{version}, '2.11', 'JSON output: Version');

};

Expand Down

0 comments on commit 6cbede9

Please sign in to comment.