diff options
-rw-r--r-- | lib/Git/Annex/BatchCommand.pm | 8 | ||||
-rwxr-xr-x | t/13_batchcommand.t | 6 |
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), |