summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2010-06-30 10:35:25 +0000
committerMarc Espie <espie@cvs.openbsd.org>2010-06-30 10:35:25 +0000
commit4409563d2bef22b074108211225b1a6c080c1566 (patch)
treed59323ca475e26733898b0ff090cd02c97bbd2d3
parent456e5cae1a80cacc6bb3b061bbeeb41996d10524 (diff)
pass state along to find_by_spec, clean up error messages.
Simplify PkgLocator/PkgRepo access with new API
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PkgInfo.pm24
1 files changed, 9 insertions, 15 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PkgInfo.pm b/usr.sbin/pkg_add/OpenBSD/PkgInfo.pm
index 3de9e1a50c8..e013dfe7a42 100644
--- a/usr.sbin/pkg_add/OpenBSD/PkgInfo.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PkgInfo.pm
@@ -1,6 +1,6 @@
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: PkgInfo.pm,v 1.9 2010/06/25 14:32:18 espie Exp $
+# $OpenBSD: PkgInfo.pm,v 1.10 2010/06/30 10:35:24 espie Exp $
#
# Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org>
#
@@ -211,21 +211,17 @@ sub find_pkg_in
sub find_pkg
{
my ($self, $state, $pkgname, $code) = @_;
- require OpenBSD::PackageRepository::Installed;
- if ($self->find_pkg_in($state, OpenBSD::PackageRepository::Installed->new, $pkgname,
+ if ($self->find_pkg_in($state, $state->repo->installed, $pkgname,
$code)) {
return;
}
- require OpenBSD::PackageLocator;
-
my $repo;
if ($pkgname =~ m/[\/\:]/o) {
- ($repo, $pkgname) =
- OpenBSD::PackageLocator->new($state)->path_parse($pkgname);
+ ($repo, $pkgname) = $state->repo->path_parse($pkgname);
} else {
- $repo = 'OpenBSD::PackageLocator';
+ $repo = $state->repo;
}
$self->find_pkg_in($state, $repo, $pkgname, $code);
@@ -248,17 +244,16 @@ sub get_comment
sub find_by_spec
{
- my $pat = shift;
+ my ($pat, $state) = @_;
require OpenBSD::Search;
- require OpenBSD::PackageRepository::Installed;
my $s = OpenBSD::Search::PkgSpec->new($pat);
if (!$s->is_valid) {
- print STDERR "Invalid spec: $pat\n";
+ $state->errsay("Invalid spec: #1", $pat);
return ();
} else {
- my $r = OpenBSD::PackageRepository::Installed->new->match_locations($s);
+ my $r = $state->repo->installed->match_locations($s);
return sort {$a->name <=> $b->name} @$r;
}
@@ -474,7 +469,7 @@ sub parse_and_run
@list = find_by_path($pat);
push(@ARGV, @list);
} else {
- @list = find_by_spec($pat);
+ @list = find_by_spec($pat, $state);
push(@extra, @list);
}
if (@list == 0) {
@@ -509,12 +504,11 @@ sub parse_and_run
}
if ($state->opt('Q')) {
- require OpenBSD::PackageLocator;
require OpenBSD::Search;
print "PKG_PATH=$ENV{PKG_PATH}\n" if $state->verbose;
my $partial = OpenBSD::Search::PartialStem->new($state->opt('Q'));
- my $r = OpenBSD::PackageLocator->new($state)->match_locations($partial);
+ my $r = $state->repo->match_locations($partial);
for my $p (sort map {$_->name} @$r) {
$state->say(