summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm42
-rw-r--r--usr.sbin/pkg_add/OpenBSD/State.pm47
2 files changed, 58 insertions, 31 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm b/usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm
index a83ca85cc0a..3f09866af3f 100644
--- a/usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm
+++ b/usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: AddCreateDelete.pm,v 1.6 2010/06/15 08:35:11 espie Exp $
+# $OpenBSD: AddCreateDelete.pm,v 1.7 2010/06/25 10:19:00 espie Exp $
#
# Copyright (c) 2007-2010 Marc Espie <espie@openbsd.org>
#
@@ -24,7 +24,6 @@ use warnings;
package OpenBSD::AddCreateDelete::State;
our @ISA = qw(OpenBSD::State);
-use OpenBSD::Subst;
use OpenBSD::State;
use OpenBSD::ProgressMeter;
@@ -32,7 +31,6 @@ sub init
{
my $self = shift;
- $self->{subst} = OpenBSD::Subst->new;
$self->{progressmeter} = OpenBSD::ProgressMeter->new;
$self->{bad} = 0;
$self->SUPER::init;
@@ -44,24 +42,12 @@ sub progress
return $self->{progressmeter};
}
-sub verbose
-{
- my $self = shift;
- return $self->{v};
-}
-
sub not
{
my $self = shift;
return $self->{not};
}
-sub opt
-{
- my ($self, $k) = @_;
- return $self->{opt}{$k};
-}
-
sub _print
{
my $self = shift;
@@ -74,27 +60,23 @@ sub _errprint
$self->progress->errprint(@_);
}
-package OpenBSD::AddCreateDelete;
-use OpenBSD::Getopt;
-use OpenBSD::Error;
-
sub handle_options
{
- my ($self, $opt_string, $state, @usage) = @_;
+ my ($state, $opt_string, @usage) = @_;
+ $state->SUPER::handle_options('mnx'.$opt_string, @usage);
- $state->{opt}{v} = 0;
- $state->{opt}{h} = sub { $state->usage; };
- $state->{opt}{D} = sub {
- $state->{subst}->parse_option(shift);
- };
- $state->usage_is(@usage);
- $state->do_options(sub {
- getopts('hmnvxD:'.$opt_string, $state->{opt});
- });
$state->progress->setup($state->opt('x'), $state->opt('m'));
- $state->{v} = $state->opt('v');
$state->{not} = $state->opt('n');
}
+package OpenBSD::AddCreateDelete;
+use OpenBSD::Error;
+
+sub handle_options
+{
+ my ($self, $opt_string, $state, @usage) = @_;
+ $state->handle_options($opt_string, $self, @usage);
+}
+
1;
diff --git a/usr.sbin/pkg_add/OpenBSD/State.pm b/usr.sbin/pkg_add/OpenBSD/State.pm
index 6b969dab0a0..0e8c97f9000 100644
--- a/usr.sbin/pkg_add/OpenBSD/State.pm
+++ b/usr.sbin/pkg_add/OpenBSD/State.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: State.pm,v 1.4 2010/06/15 08:29:22 espie Exp $
+# $OpenBSD: State.pm,v 1.5 2010/06/25 10:19:00 espie Exp $
#
# Copyright (c) 2007-2010 Marc Espie <espie@openbsd.org>
#
@@ -23,6 +23,10 @@ use warnings;
# in particular, provides "singleton-like" access to UI.
package OpenBSD::State;
use Carp;
+use OpenBSD::Subst;
+require Exporter;
+our @ISA = qw(Exporter);
+our @EXPORT = ();
sub new
{
@@ -34,6 +38,8 @@ sub new
sub init
{
+ my $self = shift;
+ $self->{subst} = OpenBSD::Subst->new;
}
sub usage_is
@@ -42,6 +48,18 @@ sub usage_is
$self->{usage} = \@usage;
}
+sub verbose
+{
+ my $self = shift;
+ return $self->{v};
+}
+
+sub opt
+{
+ my ($self, $k) = @_;
+ return $self->{opt}{$k};
+}
+
sub usage
{
my $self = shift;
@@ -130,6 +148,33 @@ sub do_options
bless sub { $state->usage("#1", $_)}, "OpenBSD::Error::catchall");
}
+sub handle_options
+{
+ my ($state, $opt_string, @usage) = @_;
+ require OpenBSD::Getopt;
+
+ $state->{opt}{v} = 0;
+ $state->{opt}{h} = sub { $state->usage; };
+ $state->{opt}{D} = sub {
+ $state->{subst}->parse_option(shift);
+ };
+ $state->usage_is(@usage);
+ $state->do_options(sub {
+ OpenBSD::Getopt::getopts('hvD:'.$opt_string, $state->{opt});
+ });
+ $state->{v} = $state->opt('v');
+ return if $state->{no_exports};
+ # XXX
+ no strict "refs";
+ no strict "vars";
+ for my $k (keys %{$state->{opt}}) {
+ ${"opt_$k"} = $state->opt($k);
+ push(@EXPORT, "\$opt_$k");
+ }
+ local $Exporter::ExportLevel = 1;
+ import OpenBSD::State;
+}
+
my @signal_name = ();
sub fillup_names
{