summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2007-05-14 10:12:25 +0000
committerMarc Espie <espie@cvs.openbsd.org>2007-05-14 10:12:25 +0000
commit4ff46ecaf2e95ee2b4a30f0291fdbc91cbf6bc56 (patch)
treea12cd5f17ba0e2551a7937a3c7dc46f2accda90e
parent4eb45a02d3106a414c165c9bbf9d188474aaa8df (diff)
move code around to allow OO access to installed packages always.
-rw-r--r--usr.sbin/pkg_add/Makefile3
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageRepository.pm78
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm97
3 files changed, 109 insertions, 69 deletions
diff --git a/usr.sbin/pkg_add/Makefile b/usr.sbin/pkg_add/Makefile
index 536ca92afc4..6f958be256d 100644
--- a/usr.sbin/pkg_add/Makefile
+++ b/usr.sbin/pkg_add/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.40 2007/05/01 18:29:36 espie Exp $
+# $OpenBSD: Makefile,v 1.41 2007/05/14 10:12:24 espie Exp $
.include <bsd.own.mk>
@@ -25,6 +25,7 @@ PACKAGES= \
OpenBSD/PackageLocator.pm \
OpenBSD/PackageName.pm \
OpenBSD/PackageRepository.pm \
+ OpenBSD/PackageRepository/Installed.pm \
OpenBSD/PackageRepository/SCP.pm \
OpenBSD/PackageRepositoryList.pm \
OpenBSD/PackingElement.pm \
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm
index 25bcade9976..36d55e1ed91 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm
@@ -1,7 +1,7 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackageRepository.pm,v 1.30 2007/05/14 10:00:08 espie Exp $
+# $OpenBSD: PackageRepository.pm,v 1.31 2007/05/14 10:12:24 espie Exp $
#
-# Copyright (c) 2003-2006 Marc Espie <espie@openbsd.org>
+# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
@@ -18,7 +18,15 @@
use strict;
use warnings;
+# XXX load extra class, grab match from Base class, and tweak inheritance
+# to get all methods.
+
+use OpenBSD::PackageRepository::Installed;
+$OpenBSD::PackageRepository::Installed::ISA=(qw(OpenBSD::PackageRepository));
+
package OpenBSD::PackageRepository;
+our @ISA=(qw(OpenBSD::PackageRepositoryBase));
+
use OpenBSD::PackageLocation;
sub _new
@@ -65,16 +73,6 @@ sub stemlist
return $self->{stemlist};
}
-sub match
-{
- my ($self, $search, $filter) = @_;
- if (defined $filter) {
- return &$filter($search->match_repo($self));
- } else {
- return $search->match_repo($self);
- }
-}
-
sub wipe_info
{
my ($self, $pkg) = @_;
@@ -243,62 +241,6 @@ sub cleanup
# nothing to do
}
-package OpenBSD::PackageRepository::Installed;
-our @ISA=qw(OpenBSD::PackageRepository);
-use OpenBSD::PackageInfo;
-
-my $singleton = bless {}, __PACKAGE__;
-
-sub new
-{
- return $singleton;
-}
-
-sub find
-{
- my ($repository, $name, $arch, $srcpath) = @_;
- my $self;
-
- if (is_installed($name)) {
- $self = OpenBSD::PackageLocation->new($repository, $name);
- $self->{dir} = installed_info($name);
- }
- return $self;
-}
-
-sub grabPlist
-{
- my ($repository, $name, $arch, $code) = @_;
- require OpenBSD::PackingList;
- return OpenBSD::PackingList->from_installation($name, $code);
-}
-
-sub available
-{
- return installed_packages();
-}
-
-sub list
-{
- my @list = installed_packages();
- return \@list;
-}
-
-sub stemlist
-{
- return installed_stems();
-}
-
-sub wipe_info
-{
-}
-
-sub may_exist
-{
- my ($self, $name) = @_;
- return is_installed($name);
-}
-
package OpenBSD::PackageRepository::Local;
our @ISA=qw(OpenBSD::PackageRepository);
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm
new file mode 100644
index 00000000000..6c1373c4b9f
--- /dev/null
+++ b/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm
@@ -0,0 +1,97 @@
+# ex:ts=8 sw=4:
+# $OpenBSD: Installed.pm,v 1.1 2007/05/14 10:12:24 espie Exp $
+#
+# Copyright (c) 2007 Marc Espie <espie@openbsd.org>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+use strict;
+use warnings;
+
+# XXX: we want to be able to load PackageRepository::Installed stand-alone,
+# so we put the only common method into PackageRepositoryBase.
+#
+# later, when we load the base PackageRepository, we tweak the inheritance
+# of PackageRepository::Installed to have full access...
+
+package OpenBSD::PackageRepositoryBase;
+
+sub match
+{
+ my ($self, $search, $filter) = @_;
+ if (defined $filter) {
+ return &$filter($search->match_repo($self));
+ } else {
+ return $search->match_repo($self);
+ }
+}
+
+package OpenBSD::PackageRepository::Installed;
+
+our @ISA = (qw(OpenBSD::PackageRepositoryBase));
+
+use OpenBSD::PackageInfo;
+
+my $singleton = bless {}, __PACKAGE__;
+
+sub new
+{
+ return $singleton;
+}
+
+sub find
+{
+ my ($repository, $name, $arch, $srcpath) = @_;
+ my $self;
+
+ if (is_installed($name)) {
+ $self = OpenBSD::PackageLocation->new($repository, $name);
+ $self->{dir} = installed_info($name);
+ }
+ return $self;
+}
+
+sub grabPlist
+{
+ my ($repository, $name, $arch, $code) = @_;
+ require OpenBSD::PackingList;
+ return OpenBSD::PackingList->from_installation($name, $code);
+}
+
+sub available
+{
+ return installed_packages();
+}
+
+sub list
+{
+ my @list = installed_packages();
+ return \@list;
+}
+
+sub stemlist
+{
+ return installed_stems();
+}
+
+sub wipe_info
+{
+}
+
+sub may_exist
+{
+ my ($self, $name) = @_;
+ return is_installed($name);
+}
+
+1;