Skip to content

Commit

Permalink
Merge branch 'version-range'
Browse files Browse the repository at this point in the history
  • Loading branch information
giterlizzi committed May 11, 2024
2 parents 6cbede9 + 1cb8c67 commit 7777c5a
Show file tree
Hide file tree
Showing 18 changed files with 1,445 additions and 62 deletions.
8 changes: 7 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
Revision history for URI::PackageURL.
Change history for URI-PackageURL

2.20 2024-05-11
- Added support for the official "cpan" PURL type specification (giterlizzi/perl-URI-PackageURL#8)
- Added "Version Range" (vers) support
- Added "URI::VersionRange::Version::cpan" version comparator for "cpan" scheme
- Added "vers-tool(1)"

2.11 2024-04-19
- Improved the cpan PURL type to be compatible with the 'PURL-TYPES' specification
Expand Down
8 changes: 8 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
bin/purl-tool
bin/vers-tool
Changes
examples/cpan-dist-download-and-test.sh
examples/rpm-to-purl.sh
examples/version-comparators.pl
INSTALL.md
lib/URI/PackageURL.pm
lib/URI/PackageURL/App.pm
lib/URI/PackageURL/Util.pm
lib/URI/VersionRange.pm
lib/URI/VersionRange/App.pm
lib/URI/VersionRange/Constraint.pm
lib/URI/VersionRange/Version.pm
LICENSE
Makefile.PL
MANIFEST This list of files
Expand All @@ -15,6 +21,8 @@ t/10-encode.t
t/20-decode.t
t/30-util.t
t/40-cli.t
t/50-version-range.t
t/90-cpan-distname-info.t
t/99-official-purl-test-suite.t
t/manifest.t
t/pod-coverage.t
Expand Down
4 changes: 2 additions & 2 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ WriteMakefile(
MIN_PERL_VERSION => 5.010,
PL_FILES => {},
CONFIGURE_REQUIRES => {'ExtUtils::MakeMaker' => '0'},
TEST_REQUIRES => {'Test::More' => '0', 'JSON::PP' => '0'},
PREREQ_PM => {'JSON::PP' => '0'},
TEST_REQUIRES => {'Test::More' => '0', 'JSON::PP' => '0', 'CPAN::DistnameInfo' => 0},
PREREQ_PM => {'JSON::PP' => '0', 'List::Util' => '0'},
META_MERGE => {
'meta-spec' => {version => 2},
'resources' => {
Expand Down
20 changes: 10 additions & 10 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.11');
$purl = URI::PackageURL->new(type => cpan, namespace => 'GDT', name => 'URI-PackageURL', version => '2.20');

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

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

# exported functions

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

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


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.11 --json | jq
$ purl-tool pkg:cpan/GDT/URI-PackageURL@2.20 --json | jq
{
"name": "URI-PackageURL",
"namespace": "GDT",
"qualifiers": {},
"subpath": null,
"type": "cpan",
"version": "2.11"
"version": "2.20"
}
```


Download package using "purl" string:

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


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

set -e

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

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.11
--version 2.20
```


Expand Down
78 changes: 78 additions & 0 deletions bin/vers-tool
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/perl

use strict;
use warnings;
use utf8;

use URI::VersionRange::App;

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

1;

__END__
=encoding utf-8
=head1 NAME
vers-tool - Version Range tool
=head1 SYNOPSIS
vers-tool [OPTIONS]...STRING
vers-tool STRING --contains STRING
vers-tool [--help|--man|-v]
Options:
--help Brief help message
--man Full documentation
-v Print version
--contains=VERSION Check if a version is contained within a range
--format=FORMAT Output format
--json JSON output format (--format=json)
-h, --human-readable Human-readable format (--format=human-readable)
Examples:
Decode a "vers" string:
vers-tool "vers:cpan/1.00|>=2.00|<5.00" | jq
Check if a version is contained within a range:
vers-tool "vers:cpan/1.00|>=2.00|<5.00" --contains "2.20"
Humanize "vers":
vers-tool "vers:cpan/1.00|>=2.00|<5.00" --human-readable
=head1 DESCRIPTION
C<vers-tool> Version Range tool
=head1 EXAMPLES
Decode a "vers" string:
vers-tool "vers:cpan/1.00|>=2.00|<5.00" | jq
Check if a version is contained within a range:
vers-tool "vers:cpan/1.00|>=2.00|<5.00" --contains "2.20"
Humanize "vers":
vers-tool "vers:cpan/1.00|>=2.00|<5.00" --human-readable
=head1 AUTHOR
L<Giuseppe Di Terlizzi|https://metacpan.org/author/gdt>
=head1 COPYRIGHT AND LICENSE
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.
29 changes: 29 additions & 0 deletions examples/version-comparators.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package URI::VersionRange::Version::generic {

use Version::libversion::XS;

use parent 'URI::VersionRange::Version';
use overload ('cmp' => \&compare, '<=>' => \&compare, fallback => 1);

sub compare {
my ($left, $right) = @_;
return version_compare2($left->[0], $right->[0]);
}

}

package URI::VersionRange::Version::rpm {

use RPM4;

use parent 'URI::VersionRange::Version';
use overload ('cmp' => \&compare, '<=>' => \&compare, fallback => 1);

sub compare {
my ($left, $right) = @_;
return rpmvercmp($left->[0], $right->[0]);
}

}

1;
Loading

0 comments on commit 7777c5a

Please sign in to comment.