From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id B10151F57C for ; Wed, 4 Oct 2023 03:49:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1696391376; bh=saXtzXazONyVg5sM+xK7SA9QUS/ZVZExcKXbL3RCurg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=U4awKGvQxK27IJnWZBHjxk+bx3WShnl1tpgg7/gJvcl2pJ5WGSmQm6bIgOagEsIpK oI5/otriKnFYsqG+Y3283w5POfK1bMGaO12LH7B3/T7MzALvtSpL1026LlSB4qZCd2 6BtvsV+ba6eXI0F0s2W3QneKEK84YCw60DwH2FUo= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 20/21] lei: document and local-ize $OPT hashref Date: Wed, 4 Oct 2023 03:49:32 +0000 Message-ID: <20231004034933.3343930-21-e@80x24.org> In-Reply-To: <20231004034933.3343930-1-e@80x24.org> References: <20231004034933.3343930-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 a5a6d321..5f3147bf 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;