pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/lintpkgsrc/files lintpkgsrc: cleanup: split P...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/25cb8296d864
branches:  trunk
changeset: 383056:25cb8296d864
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Thu Aug 11 07:18:47 2022 +0000

description:
lintpkgsrc: cleanup: split PkgDb::pkgver into separate subroutines

diffstat:

 pkgtools/lintpkgsrc/files/lintpkgsrc.pl |  28 ++++++++++++++--------------
 pkgtools/lintpkgsrc/files/t/packages.t  |   8 ++++----
 2 files changed, 18 insertions(+), 18 deletions(-)

diffs (98 lines):

diff -r 19adf9533b79 -r 25cb8296d864 pkgtools/lintpkgsrc/files/lintpkgsrc.pl
--- a/pkgtools/lintpkgsrc/files/lintpkgsrc.pl   Thu Aug 11 07:07:26 2022 +0000
+++ b/pkgtools/lintpkgsrc/files/lintpkgsrc.pl   Thu Aug 11 07:18:47 2022 +0000
@@ -1,6 +1,6 @@
 #!@PERL5@
 
-# $NetBSD: lintpkgsrc.pl,v 1.73 2022/08/11 07:07:26 rillig Exp $
+# $NetBSD: lintpkgsrc.pl,v 1.74 2022/08/11 07:18:47 rillig Exp $
 
 # Written by David Brownlee <abs%netbsd.org@localhost>.
 #
@@ -123,17 +123,16 @@
        map { $_->pkgver } $self->pkgs;
 }
 
-# pkgver($pkgbase) returns all PkgVers of the given pkgbase, sorted by
-# version in decreasing alphabetical(!) order.
-#
-# pkgver($pkgbase, $pkgversion) returns the package, or undef.
-sub pkgver($self, $pkgbase = undef, $pkgversion = undef) {
+# All PkgVers of the given pkgbase, sorted by version in decreasing
+# alphabetical(!) order.
+sub pkgvers_by_pkgbase($self, $pkgbase) {
        my $pkgs = $self->{$pkgbase};
-       defined $pkgs && defined $pkgversion
-           ? $pkgs->pkgver($pkgversion)
-           : defined $pkgs
-           ? $pkgs->pkgver
-           : ();
+       defined $pkgs ? $pkgs->pkgver : ();
+}
+
+sub pkgver($self, $pkgbase, $pkgversion) {
+       my $pkgs = $self->{$pkgbase};
+       defined $pkgs ? $pkgs->pkgver($pkgversion) : undef;
 }
 
 # pkgs() returns all Pkgs, sorted by pkgbase.
@@ -834,8 +833,9 @@
                # (package)(cmp)(pkgversion)
                my ($test, @pkgvers);
 
+               # TODO: rename $matchpkgname to be more accurate.
                ($matchpkgname, $test, $matchver) = ($1, $2, $3);
-               if (@pkgvers = $pkgdb->pkgver($matchpkgname)) {
+               if (@pkgvers = $pkgdb->pkgvers_by_pkgbase($matchpkgname)) {
                        foreach my $pkgver (@pkgvers) {
                                if ($test eq '-') {
                                        if ($pkgver->pkgversion eq $matchver) {
@@ -1388,7 +1388,7 @@
        my @installed;
        foreach my $pkgname (sort @pkgs) {
                if ($pkgname =~ /^([^*?[]+)-([\d*?[].*)/) {
-                       foreach my $pkgver ($pkgdb->pkgver($1)) {
+                       foreach my $pkgver ($pkgdb->pkgvers_by_pkgbase($1)) {
                                next if $pkgver->var('dir') =~ /-current/;
                                push @installed, $pkgver;
                                last;
@@ -1557,7 +1557,7 @@
                print $_;
                next unless $pkgname =~ /^([^*?[]+)-([\d*?[].*)/;
 
-               foreach my $pkgver ($pkgdb->pkgver($1)) {
+               foreach my $pkgver ($pkgdb->pkgvers_by_pkgbase($1)) {
                        next if $pkgver->var('dir') =~ /-current/;
                        push @update, $pkgver;
                        last;
diff -r 19adf9533b79 -r 25cb8296d864 pkgtools/lintpkgsrc/files/t/packages.t
--- a/pkgtools/lintpkgsrc/files/t/packages.t    Thu Aug 11 07:07:26 2022 +0000
+++ b/pkgtools/lintpkgsrc/files/t/packages.t    Thu Aug 11 07:18:47 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: packages.t,v 1.11 2022/08/11 07:07:27 rillig Exp $
+# $NetBSD: packages.t,v 1.12 2022/08/11 07:18:47 rillig Exp $
 
 use strict;
 use warnings;
@@ -56,10 +56,10 @@
        my $actual = join(', ', map { $_->pkgname } $pkgdb->pkgvers_all);
        ok($actual, 'base-8.0, base-1.0, other-5.7');
 
-       $actual = join(', ', map { $_->pkgname } $pkgdb->pkgver('base'));
+       $actual = join(', ', map { $_->pkgname } $pkgdb->pkgvers_by_pkgbase('base'));
        ok($actual, 'base-8.0, base-1.0');
 
-       $actual = join(', ', map { $_->pkgname } $pkgdb->pkgver('unknown'));
+       $actual = join(', ', map { $_->pkgname } $pkgdb->pkgvers_by_pkgbase('unknown'));
        ok($actual, '');
 
        ok($pkgdb->pkgver('base', '1.0')->pkgname, 'base-1.0');
@@ -93,7 +93,7 @@
        ok($versions, '2.0, 1.5, 1.10, 1.0');
 
        # The versioned packages are sorted in decreasing alphabetical order.
-       my @pkgvers = $pkgdb->pkgver('pkgbase');
+       my @pkgvers = $pkgdb->pkgvers_by_pkgbase('pkgbase');
        ok(join(', ', map { $_->pkgversion } @pkgvers), '2.0, 1.5, 1.10, 1.0');
        ok($pkgvers[0], $pkgbase_2_0);
        ok($pkgvers[3], $pkgbase_1_0);



Home | Main Index | Thread Index | Old Index