Skip to content

Commit

Permalink
Improved "cpan" PURL type error messages and renamed the CLI package …
Browse files Browse the repository at this point in the history
…in "URI::PackageURL::App"
  • Loading branch information
giterlizzi committed Apr 19, 2024
1 parent c59fec3 commit 202e42c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions bin/purl-tool
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use strict;
use warnings;
use utf8;

use URI::PackageURL::CLI;
use URI::PackageURL::App;

exit URI::PackageURL::CLI->run(@ARGV) unless caller();
exit URI::PackageURL::App->run(@ARGV) unless caller();

1;

Expand Down
22 changes: 11 additions & 11 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_01';
our $VERSION = '2.04_02';
our @EXPORT = qw(encode_purl decode_purl);

my $PURL_REGEXP = qr{^pkg:[A-Za-z\\.\\-\\+][A-Za-z0-9\\.\\-\\+]*/.+};
Expand Down Expand Up @@ -49,23 +49,23 @@ sub new {
Carp::croak "Invalid Package URL: '$qualifier' is not a valid qualifier" if ($qualifier =~ /\%/);
}

$name =~ s/_/-/g if $type eq 'pypi';
$name =~ s/_/-/g if $type eq 'pypi';

if ($type eq 'cpan') {

# CPAN Author name is MUST be uppercased
$namespace = uc $namespace if ($namespace);

if (($namespace && $name) && $namespace =~ /\:/) {
Carp::croak "Invalid Package URL: CPAN 'namespace' must have the distribution author";
Carp::carp "Invalid Package URL: CPAN 'namespace' must have the distribution author";
}

if (($namespace && $name) && $name =~ /\:/) {
Carp::croak "Invalid Package URL: CPAN 'name' must have the distribution name";
Carp::carp "Invalid Package URL: CPAN 'name' must have the distribution name";
}

if (! $namespace && $name =~ /\-/) {
Carp::croak "Invalid Package URL: CPAN 'name' must have the module name";
if (!$namespace && $name =~ /\-/) {
Carp::carp "Invalid Package URL: CPAN 'name' must have the module name";
}

}
Expand Down Expand Up @@ -373,15 +373,15 @@ URI::PackageURL - Perl extension for Package URL (aka "purl")
say $purl; # pkg:cpan/GDT/URI-PackageURL@2.04
# Parse Package URL string
$purl = URI::PackageURL->from_string('pkg:cpan/URI-PackageURL@2.04');
$purl = URI::PackageURL->from_string('pkg:cpan/GDT/URI-PackageURL@2.04');
# exported functions
$purl = decode_purl('pkg:cpan/GDT/URI-PackageURL@2.04');
say $purl->type; # cpan
$purl_string = encode_purl(type => cpan, name => 'URI-PackageURL', version => '2.04');
say $purl_string; # pkg:cpan/URI-PackageURL@2.04
$purl_string = encode_purl(type => cpan, name => 'URI::PackageURL', version => '2.04');
say $purl_string; # pkg:cpan/URI::PackageURL@2.04
=head1 DESCRIPTION
Expand All @@ -407,7 +407,7 @@ The definition for each components is:
One of the primary reason for this single scheme is to facilitate the future
official registration of the "pkg" scheme for package URLs. Required.
=item * "type": the package "type" or package "protocol" such as maven, npm,
=item * "type": the package "type" or package "protocol" such as cpan, maven, npm,
nuget, gem, pypi, etc. Required.
=item * "namespace": some name prefix such as a Maven groupid, a Docker image
Expand Down Expand Up @@ -460,7 +460,7 @@ Create new B<URI::PackageURL> instance using provided Package URL components
=item $purl->type
The package "type" or package "protocol" such as maven, npm, nuget, gem, pypi, etc.
The package "type" or package "protocol" such as cpan, maven, npm, nuget, gem, pypi, etc.
=item $purl->namespace
Expand Down
6 changes: 3 additions & 3 deletions lib/URI/PackageURL/CLI.pm → lib/URI/PackageURL/App.pm
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package URI::PackageURL::CLI;
package URI::PackageURL::App;

use feature ':5.10';
use strict;
use warnings;
use utf8;

use Getopt::Long qw( GetOptionsFromArray :config gnu_compat pass_through );
use Getopt::Long qw( GetOptionsFromArray :config gnu_compat );
use Pod::Usage;
use Carp;

use URI::PackageURL;

our $VERSION = '2.04_01';
our $VERSION = '2.04_02';

sub cli_error {
my ($error) = @_;
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_01';
our $VERSION = '2.04_02';
our @EXPORT = qw(purl_to_urls);

sub purl_to_urls {
Expand Down
2 changes: 1 addition & 1 deletion t/99-official-purl-test-suite.t
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ sub test_purl_decode {

my $test_suite_file = File::Spec->catfile('t', 'test-suite-data.json');

BAIL_OUT('"test-suite-data.json" file not found') if (! -e $test_suite_file);
BAIL_OUT('"test-suite-data.json" file not found') if (!-e $test_suite_file);

open my $fh, '<', $test_suite_file or Carp::croak "Can't open file: $!";

Expand Down

0 comments on commit 202e42c

Please sign in to comment.