Skip to content

Commit

Permalink
Updated "cpan" type spec
Browse files Browse the repository at this point in the history
  • Loading branch information
giterlizzi committed Jan 28, 2025
1 parent 49879e8 commit a5f20ba
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 92 deletions.
28 changes: 6 additions & 22 deletions lib/URI/PackageURL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use constant DEBUG => $ENV{PURL_DEBUG};

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

our $VERSION = '2.22';
our $VERSION = '2.22_1';
our @EXPORT = qw(encode_purl decode_purl);

my $PURL_REGEXP = qr{^pkg:[A-Za-z\\.\\-\\+][A-Za-z0-9\\.\\-\\+]*/.+};
Expand Down Expand Up @@ -296,8 +296,8 @@ URI::PackageURL - Perl extension for Package URL (aka "purl")
$purl = decode_purl('pkg:cpan/GDT/[email protected]');
say $purl->type; # cpan
$purl_string = encode_purl(type => cpan, name => 'URI::PackageURL', version => '2.22');
say $purl_string; # pkg:cpan/URI::[email protected]
$purl_string = encode_purl(type => cpan, namespace => 'GDT', name => 'URI-PackageURL', version => '2.22');
say $purl_string; # pkg:cpan/GDT/URI-[email protected]
=head1 DESCRIPTION
Expand Down Expand Up @@ -349,23 +349,11 @@ C<cpan> is an official "purl" type (L<https://github.com/package-url/purl-spec/b
=item * The default repository is C<https://www.cpan.org/>.
=item * The C<namespace>:
=item * The C<namespace> is the CPAN id of the author/publisher. It MUST be written uppercase and is required.
=over
=item * To refer to a CPAN distribution name, the C<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 C<::>.
=item * To refer to a CPAN module, the C<namespace> MUST be absent.
The module name MAY contain zero or more C<::> strings, and the module name MUST NOT contain a C<->
=back
=item * The C<name> is the module or distribution name and is case sensitive.
=item * The C<name> is the distribution name and is case sensitive.
=item * The C<version> is the module or distribution version.
=item * The C<version> is the distribution version.
=item * Optional qualifiers may include:
Expand All @@ -385,13 +373,9 @@ The module name MAY contain zero or more C<::> strings, and the module name MUST
=head3 Examples
pkg:cpan/Perl::[email protected]
pkg:cpan/DROLSKY/[email protected]
pkg:cpan/[email protected]
pkg:cpan/GDT/URI-PackageURL
pkg:cpan/LWP::UserAgent
pkg:cpan/OALDERS/[email protected]
pkg:cpan/URI
=head2 FUNCTIONAL INTERFACE
Expand Down
2 changes: 1 addition & 1 deletion lib/URI/PackageURL/App.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use Data::Dumper ();

use URI::PackageURL ();

our $VERSION = '2.22';
our $VERSION = '2.22_1';

sub cli_error {
my ($error) = @_;
Expand Down
18 changes: 6 additions & 12 deletions lib/URI/PackageURL/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use warnings;

use Exporter qw(import);

our $VERSION = '2.22';
our $VERSION = '2.22_1';
our @EXPORT = qw(purl_to_urls purl_components_normalize);

sub purl_components_normalize {
Expand Down Expand Up @@ -77,15 +77,13 @@ sub _cpan_normalize {

my (%component) = @_;

# 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 "::".
# The namespace is the CPAN id of the author/publisher. It MUST be written uppercase and is required.

# 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 "-"
unless (defined($component{namespace})) {
Carp::croak "Invalid Package URL: CPAN 'namespace' is required";
}

$component{namespace} = uc $component{namespace} if (defined $component{namespace});
$component{namespace} = uc $component{namespace};

if ((defined $component{namespace} && defined $component{name}) && $component{namespace} =~ /\:/) {
Carp::croak "Invalid Package URL: CPAN 'namespace' component must have the distribution author";
Expand All @@ -95,10 +93,6 @@ sub _cpan_normalize {
Carp::croak "Invalid Package URL: CPAN 'name' component must have the distribution name";
}

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

return \%component;

}
Expand Down
2 changes: 1 addition & 1 deletion lib/URI/VersionRange.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use constant FALSE => !!0;

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

our $VERSION = '2.22';
our $VERSION = '2.22_1';
our @EXPORT = qw(encode_vers decode_vers);

my $VERS_REGEXP = qr{^vers:[a-z\\.\\-\\+][a-z0-9\\.\\-\\+]*/.+};
Expand Down
2 changes: 1 addition & 1 deletion lib/URI/VersionRange/App.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use Data::Dumper ();

use URI::VersionRange ();

our $VERSION = '2.22';
our $VERSION = '2.22_1';

sub cli_error {
my ($error) = @_;
Expand Down
2 changes: 1 addition & 1 deletion lib/URI/VersionRange/Constraint.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use overload '""' => 'to_string', fallback => 1;

use URI::VersionRange::Version;

our $VERSION = '2.22';
our $VERSION = '2.22_1';

our %COMPARATOR = (
'=' => 'equal',
Expand Down
13 changes: 1 addition & 12 deletions t/10-encode.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,21 @@ use URI::PackageURL qw(encode_purl);


my @TESTS = (
{purl => 'pkg:cpan/Perl::[email protected]', type => 'cpan', name => 'Perl::Version', version => '1.013'},
{
purl => 'pkg:cpan/DROLSKY/[email protected]',
type => 'cpan',
namespace => 'DROLSKY',
name => 'DateTime',
version => '1.55'
},
{purl => 'pkg:cpan/[email protected]', type => 'cpan', name => 'DateTime', version => '1.55'},
{purl => 'pkg:cpan/GDT/URI-PackageURL', type => 'cpan', namespace => 'GDT', name => 'URI-PackageURL',},
{purl => 'pkg:cpan/LWP::UserAgent', type => 'cpan', name => 'LWP::UserAgent'},
{purl => 'pkg:cpan/GDT/URI-PackageURL', type => 'cpan', namespace => 'GDT', name => 'URI-PackageURL',},
{
purl => 'pkg:cpan/OALDERS/[email protected]',
type => 'cpan',
namespace => 'OALDERS',
name => 'libwww-perl',
version => '6.76'
},
{purl => 'pkg:cpan/URI', type => 'cpan', name => 'URI'},
{
purl => 'pkg:generic/100%25/100%25@100%25?repository_url=https://example.com/100%2525/#100%25',
type => 'generic',
Expand All @@ -38,13 +34,6 @@ my @TESTS = (
subpath => '100%',
},
{purl => 'pkg:brew/openssl%[email protected]', type => 'brew', name => '[email protected]', version => '1.1.1w'},
{purl => 'pkg:cpan/[email protected]%402', type => 'cpan', name => 'Storable', version => '0.6@2'},
{
purl => 'pkg:cpan/[email protected]%403-bin-1-MacOS',
type => 'cpan',
name => 'Storable',
version => '0.5@3-bin-1-MacOS'
},
);


Expand Down
48 changes: 6 additions & 42 deletions t/test-suite-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -553,30 +553,18 @@
},
{
"description": "cpan distribution name are case sensitive",
"purl": "pkg:cpan/DROLSKY/[email protected]",
"canonical_purl": "pkg:cpan/DROLSKY/[email protected]",
"purl": "pkg:cpan/GDT/[email protected]",
"canonical_purl": "pkg:cpan/GDT/[email protected]",
"type": "cpan",
"namespace": "DROLSKY",
"name": "DateTime",
"version": "1.55",
"qualifiers": null,
"subpath": null,
"is_invalid": false
},
{
"description": "cpan module name are case sensitive",
"purl": "pkg:cpan/URI::[email protected]",
"canonical_purl": "pkg:cpan/URI::[email protected]",
"type": "cpan",
"namespace": null,
"name": "URI::PackageURL",
"version": "2.11",
"namespace": "GDT",
"name": "URI-PackageURL",
"version": "2.23",
"qualifiers": null,
"subpath": null,
"is_invalid": false
},
{
"description": "cpan module name like distribution name",
"description": "cpan distribution without author",
"purl": "pkg:cpan/[email protected]",
"canonical_purl": "pkg:cpan/[email protected]",
"type": "cpan",
Expand All @@ -598,29 +586,5 @@
"qualifiers": null,
"subpath": null,
"is_invalid": true
},
{
"description": "cpan valid module name",
"purl": "pkg:cpan/[email protected]",
"canonical_purl": "pkg:cpan/[email protected]",
"type": "cpan",
"namespace": null,
"name": "DateTime",
"version": "1.55",
"qualifiers": null,
"subpath": null,
"is_invalid": false
},
{
"description": "cpan valid module name without version",
"purl": "pkg:cpan/URI",
"canonical_purl": "pkg:cpan/URI",
"type": "cpan",
"namespace": null,
"name": "URI",
"version": null,
"qualifiers": null,
"subpath": null,
"is_invalid": false
}
]

0 comments on commit a5f20ba

Please sign in to comment.