Skip to content

Commit

Permalink
URI::PackageURL 2.10
Browse files Browse the repository at this point in the history
  • Loading branch information
giterlizzi committed Apr 19, 2024
1 parent 605279f commit 14f704f
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 45 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.10 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
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.10');

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

# 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.10');

# exported functions

$purl = decode_purl('pkg:cpan/GDT/URI-PackageURL@2.04');
$purl = decode_purl('pkg:cpan/GDT/URI-PackageURL@2.10');
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.10');
```


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.10 --json | jq
{
"name": "URI-PackageURL",
"namespace": "GDT",
"qualifiers": {},
"subpath": null,
"type": "cpan",
"version": "2.04"
"version": "2.10"
}
```


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.10 --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.10"

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.10
```


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.10 --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.10 --download-url)
Create a canonical Package URL string
purl-tool --type cpan \
--namespace GDT \
--name URI-PackageURL \
--version 2.04
--version 2.10
=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.10 --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.10 --download-url)
Create a canonical Package URL string:
purl-tool --type cpan \
--namespace GDT \
--name URI-PackageURL \
--version 2.04
--version 2.10
=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.
2 changes: 1 addition & 1 deletion 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.10';
our @EXPORT = qw(encode_purl decode_purl);

my $PURL_REGEXP = qr{^pkg:[A-Za-z\\.\\-\\+][A-Za-z0-9\\.\\-\\+]*/.+};
Expand Down
28 changes: 8 additions & 20 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.10';

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
2 changes: 1 addition & 1 deletion 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.10';
our @EXPORT = qw(purl_to_urls);

sub purl_to_urls {
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.10';

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.10', 'JSON output: Version');

};

Expand Down

0 comments on commit 14f704f

Please sign in to comment.