diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2012-07-08 18:28:35 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2012-07-08 18:28:35 +0000 |
commit | 5810da240cfde42702250b3a8b6d16bd113ecc37 (patch) | |
tree | 4d1f501cfd4a5bc2d82f8711f84a8461736b4d8b | |
parent | 459006cb41d01c3fc25af5de01b9d54554125bae (diff) |
pass @ (array) information along to auto-make simpler accessors
-rw-r--r-- | usr.bin/libtool/LT/Getopt.pm | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/usr.bin/libtool/LT/Getopt.pm b/usr.bin/libtool/LT/Getopt.pm index 48068a47428..047df32f062 100644 --- a/usr.bin/libtool/LT/Getopt.pm +++ b/usr.bin/libtool/LT/Getopt.pm @@ -1,4 +1,4 @@ -# $OpenBSD: Getopt.pm,v 1.4 2012/07/08 11:17:12 espie Exp $ +# $OpenBSD: Getopt.pm,v 1.5 2012/07/08 18:28:34 espie Exp $ # Copyright (c) 2012 Marc Espie <espie@openbsd.org> # @@ -83,15 +83,15 @@ our @ISA = qw(Option); sub setup { - my ($self, $opts) = @_; - $opts->add_option_accessor($$self); + my ($self, $opts, $isarray) = @_; + $opts->add_option_accessor($$self, $isarray); return $self; } sub match { my ($self, $_, $opts, $canonical, $code) = @_; - if (m/^\-$$self$/) { + if (m/^\-\Q$$self\E$/) { &$code($opts, $canonical, 1); return 1; } @@ -160,14 +160,18 @@ use LT::Util; sub add_option_accessor { - my ($self, $option) = @_; + my ($self, $option, $isarray) = @_; my $access = $option; $access =~ s/^\-//; $access =~ s/-/_/g; - my $actual = sub { - my $self = shift; - return $self->{opt}{$option}; - }; + my $actual = $isarray ? + sub { + my $self = shift; + return @{$self->{opt}{$option}}; + } : sub { + my $self = shift; + return $self->{opt}{$option}; + }; my $callpkg = ref($self); unless ($self->can($access)) { no strict 'refs'; @@ -181,12 +185,13 @@ sub create_options my @options = (); # first pass creates accessors while (my $opt = shift @l) { + my $isarray = ($opt =~ s/\@$//); # default code or not my $code; if (@l > 0 && ref($l[0]) eq 'CODE') { $code = shift @l; } else { - if ($opt =~ s/\@$//) { + if ($isarray) { $code = sub { my ($object, $canonical, $value) = @_; push(@{$object->{opt}{$canonical}}, $value); @@ -198,7 +203,7 @@ sub create_options }; } } - push(@options, Options->new($opt, $code)->setup($self)); + push(@options, Options->new($opt, $code)->setup($self, $isarray)); } return @options; } |