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 PkgVer ...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/46fd0811a377
branches:  trunk
changeset: 382719:46fd0811a377
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Wed Aug 03 19:22:34 2022 +0000

description:
lintpkgsrc: refactor PkgVer internals to be more descriptive

diffstat:

 pkgtools/lintpkgsrc/files/lintpkgsrc.pl |  52 ++++++++++++++++----------------
 pkgtools/lintpkgsrc/files/t/packages.t  |  11 ++++++-
 2 files changed, 36 insertions(+), 27 deletions(-)

diffs (121 lines):

diff -r baba53307ab4 -r 46fd0811a377 pkgtools/lintpkgsrc/files/lintpkgsrc.pl
--- a/pkgtools/lintpkgsrc/files/lintpkgsrc.pl   Wed Aug 03 18:51:56 2022 +0000
+++ b/pkgtools/lintpkgsrc/files/lintpkgsrc.pl   Wed Aug 03 19:22:34 2022 +0000
@@ -1,6 +1,6 @@
 #!@PERL5@
 
-# $NetBSD: lintpkgsrc.pl,v 1.43 2022/08/03 16:15:49 rillig Exp $
+# $NetBSD: lintpkgsrc.pl,v 1.44 2022/08/03 19:22:34 rillig Exp $
 
 # Written by David Brownlee <abs%netbsd.org@localhost>.
 #
@@ -28,53 +28,53 @@
 package PkgVer;
 
 sub new($$$) {
-       my $class = shift;
-       my $self = {};
-
+       my ($class, $pkgbase, $pkgversion) = @_;
+       my $self = {
+           pkgbase    => $pkgbase,
+           pkgversion => $pkgversion,
+           vars       => {},
+       };
        bless $self, $class;
-       $self->{_pkg} = $_[0];
-       $self->{_ver} = $_[1];
        return $self;
 }
 
+sub pkg($) {
+       my ($self) = @_;
+
+       $self->{pkgbase};
+}
+
+sub ver($) {
+       my ($self) = @_;
+
+       $self->{pkgversion};
+}
+
 sub pkgname($) {
        my $self = shift;
 
        $self->pkg . '-' . $self->ver;
 }
 
-sub pkg($) {
-       my $self = shift;
-
-       $self->{_pkg};
-}
-
 sub var($$$) {
-       my $self = shift;
-       my ($key, $val) = @_;
+       my ($self, $key, $val) = @_;
 
        (defined $val)
-           ? ($self->{$key} = $val)
-           : $self->{$key};
-}
-
-sub ver($) {
-       my $self = shift;
-
-       $self->{_ver};
+           ? ($self->{vars}->{$key} = $val)
+           : $self->{vars}->{$key};
 }
 
 sub vars($) {
-       my $self = shift;
+       my ($self) = @_;
 
-       grep(!/^_(pkg|ver)$/, keys %{$self});
+       keys %{$self->{vars}};
 }
 
 sub store($) {
        my $self = shift;
 
-       my $name = $self->{_pkg};
-       my $ver = $self->{_ver};
+       my $name = $self->pkg;
+       my $ver = $self->ver;
 
        $name =~ /\s/ and die "cannot store package name '$name'\n";
        $ver =~ /\s/ and die "cannot store package version '$ver'\n";
diff -r baba53307ab4 -r 46fd0811a377 pkgtools/lintpkgsrc/files/t/packages.t
--- a/pkgtools/lintpkgsrc/files/t/packages.t    Wed Aug 03 18:51:56 2022 +0000
+++ b/pkgtools/lintpkgsrc/files/t/packages.t    Wed Aug 03 19:22:34 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: packages.t,v 1.4 2022/08/03 18:51:56 rillig Exp $
+# $NetBSD: packages.t,v 1.5 2022/08/03 19:22:34 rillig Exp $
 
 use strict;
 use warnings;
@@ -9,6 +9,14 @@
 
 require('../lintpkgsrc.pl');
 
+sub test_pkgver() {
+       my $pkgver = PkgVer->new('base', '1.0nb4');
+
+       ok($pkgver->pkg , 'base');
+       ok($pkgver->ver , '1.0nb4');
+       ok($pkgver->pkgname , 'base-1.0nb4');
+}
+
 sub test_package_variables() {
        my $pkglist = PkgList->new();
        my $pkgbase_1_0 = $pkglist->add('pkgbase', '1.0');
@@ -57,5 +65,6 @@
            . "package\tpkgbase\t1.3nb4\n");
 }
 
+test_pkgver();
 test_package_variables();
 test_store_order();



Home | Main Index | Thread Index | Old Index