From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id A57A61F934 for ; Sun, 27 Dec 2020 02:53:08 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/5] git: qx: avoid extra "local" for scalar context case Date: Sun, 27 Dec 2020 02:53:03 +0000 Message-Id: <20201227025307.77703-2-e@80x24.org> In-Reply-To: <20201227025307.77703-1-e@80x24.org> References: <20201227025307.77703-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We can use the ternary operator to avoid an early return, here --- lib/PublicInbox/Git.pm | 6 ++---- t/git.t | 1 + 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index 08406925..73dc7d3e 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -362,10 +362,8 @@ sub popen { sub qx { my ($self, @cmd) = @_; my $fh = $self->popen(@cmd); - local $/ = "\n"; - return <$fh> if wantarray; - local $/; - <$fh> + local $/ = wantarray ? "\n" : undef; + <$fh>; } # check_async and cat_async may trigger the other, so ensure they're diff --git a/t/git.t b/t/git.t index dfd7173a..dcd053c5 100644 --- a/t/git.t +++ b/t/git.t @@ -79,6 +79,7 @@ if (1) { my @ref = $gcf->qx(qw(cat-file blob), $buf); my $nl = scalar @ref; ok($nl > 1, "qx returned array length of $nl"); + is(join('', @ref), $ref, 'qx array and scalar context both work'); $gcf->qx(qw(repack -adq)); ok($gcf->packed_bytes > 0, 'packed size is positive');