summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2020-02-03 22:52:53 -0700
committerSean Whitton <spwhitton@spwhitton.name>2020-02-03 22:52:53 -0700
commitd81f0bf1ee13d0054f15fee94f98bb5b5b494d7a (patch)
treeb89fbbfb1f5fe3050a2ced718b16ddf5e3947391
parentd191a33ce44be3c4e8242fd0b3abed365a9abf20 (diff)
downloadp5-Git-Annex-d81f0bf1ee13d0054f15fee94f98bb5b5b494d7a.tar.gz
change what Git::Annex:BatchCommand::say does in scalar context
I believe this is more useful. Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
-rw-r--r--lib/Git/Annex/BatchCommand.pm8
-rwxr-xr-xt/13_batchcommand.t6
2 files changed, 8 insertions, 6 deletions
diff --git a/lib/Git/Annex/BatchCommand.pm b/lib/Git/Annex/BatchCommand.pm
index e9e9379..80fdd3c 100644
--- a/lib/Git/Annex/BatchCommand.pm
+++ b/lib/Git/Annex/BatchCommand.pm
@@ -82,9 +82,9 @@ sub new {
Say a line or lines of input to the batch command's standard input.
Trailing line breaks in C<$input> are optional.
-In list context, returns a list of chomped git-annex's responses to
-the items of input, chomped. In scalar context, returns the number of
-trueish responses.
+In list context, returns a list of git-annex's responses to the items
+of input, chomped. In scalar context, returns the last of git-annex's
+responses, chomped.
=cut
@@ -97,7 +97,7 @@ sub say {
chomp(my $out = readline $self->{_out});
push @output, $out;
}
- return wantarray ? @output : scalar @output;
+ return wantarray ? @output : $output[$#output];
}
=head2 restart
diff --git a/t/13_batchcommand.t b/t/13_batchcommand.t
index e2e5cce..3d72e8f 100755
--- a/t/13_batchcommand.t
+++ b/t/13_batchcommand.t
@@ -46,11 +46,13 @@ with_temp_annexes {
"it passes --batch to git-annex";
my ($response1, $response2) = $batch->say("foo/foo2/baz", "foo/foo2/baz");
is $response1, $response2, "it returns a list in list context";
- is scalar $batch->say("foo/foo2/baz", "foo/foo2/baz"), 2,
- "it returns a scalar in scalar context";
my ($response3, $response4) = $batch->say("foo/foo2/baz", "foo/bar");
is_deeply [$response3, $response4], ["foo/foo2/baz", ""],
"it returns results in the correct order";
+ my $response5 = $batch->say("foo/foo2/baz");
+ is $response5, "foo/foo2/baz", "it returns a single result into a scalar";
+ my ($response6) = $batch->say("foo/foo2/baz");
+ is $response6, "foo/foo2/baz", "it still returns a list in list context";
undef $batch;
ok !kill(0, $second_pid),