From ed9f4ce03ac493ab133ff1849f45a52ef03d1f1b Mon Sep 17 00:00:00 2001 From: Marc Espie Date: Mon, 9 Jul 2012 17:53:16 +0000 Subject: finally, also do accessors for short options. Turns out to be useful. fix the array accessor... --- usr.bin/libtool/LT/Getopt.pm | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/libtool/LT/Getopt.pm b/usr.bin/libtool/LT/Getopt.pm index 5302811cd8c..82c5fe0a52f 100644 --- a/usr.bin/libtool/LT/Getopt.pm +++ b/usr.bin/libtool/LT/Getopt.pm @@ -1,4 +1,4 @@ -# $OpenBSD: Getopt.pm,v 1.6 2012/07/09 13:37:39 espie Exp $ +# $OpenBSD: Getopt.pm,v 1.7 2012/07/09 17:53:15 espie Exp $ # Copyright (c) 2012 Marc Espie # @@ -39,13 +39,16 @@ sub new bless \$v, $class; } -package Option::Short; -our @ISA = qw(Option); sub setup { - # short options don't make accessors + my ($self, $opts, $isarray) = @_; + $opts->add_option_accessor($$self, $isarray); + return $self; } +package Option::Short; +our @ISA = qw(Option); + sub match { my ($self, $_, $opts, $canonical, $code) = @_; @@ -81,13 +84,6 @@ sub match package Option::Long; our @ISA = qw(Option); -sub setup -{ - my ($self, $opts, $isarray) = @_; - $opts->add_option_accessor($$self, $isarray); - return $self; -} - sub match { my ($self, $_, $opts, $canonical, $code) = @_; @@ -132,8 +128,8 @@ sub new sub setup { - my ($self, $allopts) = @_; - $self->{alt}[0]->setup($allopts); + my ($self, $allopts, $isarray) = @_; + $self->{alt}[0]->setup($allopts, $isarray); return $self; } @@ -167,6 +163,7 @@ sub add_option_accessor my $actual = $isarray ? sub { my $self = shift; + $self->{opt}{$option} //= []; if (wantarray) { return @{$self->{opt}{$option}}; } else { -- cgit v1.2.3