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: refactor PkgList...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/1a7777293f13
branches:  trunk
changeset: 382721:1a7777293f13
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Wed Aug 03 20:04:34 2022 +0000

description:
lintpkgsrc: refactor PkgList internals to be more descriptive

The indirection layer through '_pkgs' was not necessary.

diffstat:

 pkgtools/lintpkgsrc/files/lintpkgsrc.pl |  66 +++++++++++++++++----------------
 1 files changed, 34 insertions(+), 32 deletions(-)

diffs (107 lines):

diff -r f8e6a38187b4 -r 1a7777293f13 pkgtools/lintpkgsrc/files/lintpkgsrc.pl
--- a/pkgtools/lintpkgsrc/files/lintpkgsrc.pl   Wed Aug 03 19:47:02 2022 +0000
+++ b/pkgtools/lintpkgsrc/files/lintpkgsrc.pl   Wed Aug 03 20:04:34 2022 +0000
@@ -1,6 +1,6 @@
 #!@PERL5@
 
-# $NetBSD: lintpkgsrc.pl,v 1.45 2022/08/03 19:47:02 rillig Exp $
+# $NetBSD: lintpkgsrc.pl,v 1.46 2022/08/03 20:04:34 rillig Exp $
 
 # Written by David Brownlee <abs%netbsd.org@localhost>.
 #
@@ -156,62 +156,64 @@
 #
 package PkgList;
 
-sub add($@) {
-       my $self = shift;
+sub new($) {
+       my ($class) = @_;
 
-       if (!$self->pkgs($_[0])) {
-               $self->{_pkgs}{ $_[0] } = new Pkgs $_[0];
-       }
-       $self->pkgs($_[0])->add(@_);
-}
-
-sub new($) {
-       my $class = shift;
-       my $self = {};
+       my $self = {}; # pkgbase => Pkgs
        bless $self, $class;
        return $self;
 }
 
+sub add($$$) {
+       my ($self, $pkgbase, $pkgversion) = @_;
+
+       if (!$self->{$pkgbase}) {
+               $self->{$pkgbase} = Pkgs->new($pkgbase);
+       }
+       $self->{$pkgbase}->add($pkgbase, $pkgversion);
+}
+
 sub numpkgver($) {
-       my $self = shift;
+       my ($self) = @_;
+
        scalar($self->pkgver);
 }
 
-sub pkgver($@) {
-       my $self = shift;
+sub pkgver($$$) {
+       my ($self, $pkgbase, $pkgversion) = @_;
 
-       if (@_ == 0) {
-               my (@list);
+       if (!defined $pkgbase) {
+               my (@pkgvers);
                foreach my $pkg ($self->pkgs) {
-                       push(@list, $pkg->pkgver);
+                       push(@pkgvers, $pkg->pkgver);
                }
-               return (@list);
+               return @pkgvers;
        }
 
-       if (defined $self->{_pkgs}{$_[0]}) {
-               return (@_ > 1)
-                   ? $self->{_pkgs}{$_[0]}->pkgver($_[1])
-                   : $self->{_pkgs}{$_[0]}->pkgver();
+       my $pkgs = $self->{$pkgbase};
+       if (defined $pkgs) {
+               return defined $pkgversion
+                   ? $pkgs->pkgver($pkgversion)
+                   : $pkgs->pkgver();
        }
        return;
 }
 
-sub pkgs($@) {
-       my $self = shift;
+sub pkgs($$) {
+       my ($self, $pkgbase) = @_;
 
-       if (@_) {
-               return $self->{_pkgs}{$_[0]};
+       if (defined $pkgbase) {
+               return $self->{$pkgbase};
        } else {
-               return (sort { $a->pkg cmp $b->pkg } values %{$self->{_pkgs}});
+               return sort { $a->pkg cmp $b->pkg } values %{$self};
        }
 }
 
 sub store($) {
-       my $self = shift;
+       my ($self) = @_;
 
-       my $pkgs = $self->{_pkgs};
-       foreach my $pkg (sort keys %$pkgs) {
-               $pkgs->{$pkg}->store();
+       foreach my $pkgbase (sort keys %$self) {
+               $self->{$pkgbase}->store();
        }
 }
 



Home | Main Index | Thread Index | Old Index