From: Eric Wong Date: Sun, 27 Dec 2020 02:53:03 +0000 (+0000) Subject: git: qx: avoid extra "local" for scalar context case X-Git-Tag: v1.7.0~1477 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=645ec505c03c86ed4500151737bcf3d636d9b18b;p=public-inbox.git git: qx: avoid extra "local" for scalar context case We can use the ternary operator to avoid an early return, here --- 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');