Skip to content

Commit

Permalink
Return empty string from list import.
Browse files Browse the repository at this point in the history
The documentation never said that a list was returned; indeed the example
provided is broken in that it prints out ARRAY(...) if run. Let us change
its behaviour to do as expected by the docs.
  • Loading branch information
dracos committed Jan 2, 2018
1 parent 4c602d0 commit c3cfc61
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#
#========================================================================

* Matthew Somerville stopped a list import from printing an ARRAY(...) string.
https://github.com/abw/Template2/issues/33


#-----------------------------------------------------------------------
# Version 2.27 - 13th December 2016
#------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion lib/Template/Manual/VMethods.pod
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ current list.
two = [ 4 5 6 ];
three = [ 7 8 9 ];
one.import(two, three);
one.join(', ); # 1, 2, 3, 4, 5, 6, 7, 8, 9
one.join(', '); # 1, 2, 3, 4, 5, 6, 7, 8, 9
%]
=head2 merge
Expand Down
2 changes: 1 addition & 1 deletion lib/Template/VMethods.pm
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ sub list_unique {
sub list_import {
my $list = shift;
push(@$list, grep defined, map ref eq 'ARRAY' ? @$_ : undef, @_);
return $list;
return '';

This comment has been minimized.

Copy link
@atoomic

atoomic Nov 5, 2019

Collaborator

this is a bad idea and going to break existing code..
we should preserve the return

}

sub list_merge {
Expand Down
6 changes: 4 additions & 2 deletions t/vmethods/list.t
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ Tom
-- name list import one --
[% list_one = [ 1 2 3 ];
list_two = [ 4 5 6 ];
list_one.import(list_two).join(', ') %]
list_one.import(list_two);
list_one.join(', ') %]
-- expect --
1, 2, 3, 4, 5, 6
Expand All @@ -295,7 +296,8 @@ Tom
[% list_one = [ 1 2 3 ];
list_two = [ 4 5 6 ];
list_three = [ 7 8 9 0 ];
list_one.import(list_two, list_three).join(', ') %]
list_one.import(list_two, list_three);
list_one.join(', ') %]
-- expect --
1, 2, 3, 4, 5, 6, 7, 8, 9, 0
Expand Down

0 comments on commit c3cfc61

Please sign in to comment.