From 0806f3412f73bbfe32f0f57504c3fff200247a0a Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 14 Aug 2015 14:13:11 +0100 Subject: [PATCH] Permit defvalopt $fn to be a scalar ref instead (nfc, since no users) --- dgit | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/dgit b/dgit index 4f63f032..d4193ccd 100755 --- a/dgit +++ b/dgit @@ -3111,14 +3111,15 @@ sub cmd_version { our (%valopts_long, %valopts_short); our @rvalopts; -sub defvalopt ($$$&) { - my ($long,$short,$val_re,$fn) = @_; - my $oi = { Long => $long, Short => $short, Re => $val_re, Fn => $fn }; +sub defvalopt ($$$$) { + my ($long,$short,$val_re,$how) = @_; + my $oi = { Long => $long, Short => $short, Re => $val_re, How => $how }; $valopts_long{$long} = $oi; $valopts_short{$short} = $oi; - # $fn subref should: + # $how subref should: # do whatever assignemnt or thing it likes with $_[0] # if the option should not be passed on to remote, @rvalopts=() + # or $how can be a scalar ref, meaning simply assign the value } defvalopt '--since-version', '-v', '[^_]+|_', sub { @@ -3148,7 +3149,12 @@ sub parseopts () { } badusage "bad value \`$val' for $what" unless $val =~ m/^$oi->{Re}$(?!\n)/s; - $oi->{Fn}($val); + my $how = $oi->{How}; + if (ref($how) eq 'SCALAR') { + $$how = $val; + } else { + $how->($val); + } push @ropts, @rvalopts; }; -- 2.30.2