From 35c6b7a022bfe54a9f4e4d1a6a88ceb29638458c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 4 Oct 2023 03:49:32 +0000 Subject: [PATCH] lei: document and local-ize $OPT hashref This variable needs to be visible to a callback running inside Getopt::Long, but we don't need to keep it around after LEI->optparse runs. --- lib/PublicInbox/LEI.pm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index a5a6d321a..5f3147bfb 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -37,15 +37,16 @@ $GLP->configure(qw(gnu_getopt no_ignore_case auto_abbrev)); my $GLP_PASS = Getopt::Long::Parser->new; $GLP_PASS->configure(qw(gnu_getopt no_ignore_case auto_abbrev pass_through)); -our %PATH2CFG; # persistent for socket daemon -our $MDIR2CFGPATH; # /path/to/maildir => { /path/to/config => [ ino watches ] } +our (%PATH2CFG, # persistent for socket daemon +$MDIR2CFGPATH, # /path/to/maildir => { /path/to/config => [ ino watches ] } +$OPT, # shared between optparse and opt_dash callback (for Getopt::Long) +); # TBD: this is a documentation mechanism to show a subcommand # (may) pass options through to another command: sub pass_through { $GLP_PASS } -my $OPT; -sub opt_dash ($$) { +sub opt_dash ($$) { # callback runs inside optparse my ($spec, $re_str) = @_; # 'limit|n=i', '([0-9]+)' my ($key) = ($spec =~ m/\A([a-z]+)/g); my $cb = sub { # Getopt::Long "<>" catch-all handler @@ -691,7 +692,7 @@ sub optparse ($$$) { # allow _complete --help to complete, not show help return 1 if substr($cmd, 0, 1) eq '_'; $self->{cmd} = $cmd; - $OPT = $self->{opt} //= {}; + local $OPT = $self->{opt} //= {}; my $info = $CMD{$cmd} // [ '[...]' ]; my ($proto, undef, @spec) = @$info; my $glp = ref($spec[-1]) eq ref($GLP) ? pop(@spec) : $GLP; -- 2.47.2