From: Vincent Pit Date: Mon, 3 Nov 2008 08:53:32 +0000 (+0100) Subject: _ shouldn't push elements in flatten, but skip them X-Git-Tag: v0.09~14 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FSub-Prototype-Util.git;a=commitdiff_plain;h=39b18d4f8f133cb03d47a486464c5c96cb148d5f _ shouldn't push elements in flatten, but skip them --- diff --git a/lib/Sub/Prototype/Util.pm b/lib/Sub/Prototype/Util.pm index c5c6ffd..a92647f 100644 --- a/lib/Sub/Prototype/Util.pm +++ b/lib/Sub/Prototype/Util.pm @@ -87,8 +87,8 @@ sub flatten { } elsif ($p =~ /[\@\%]/) { push @args, @_; last; - } elsif ($p eq '_' && @_ == 0) { - push @args, $_; + } elsif ($p eq '_') { + shift; # without prototype, this argument wouldn't have been passed } else { push @args, shift; } diff --git a/t/10-flatten.t b/t/10-flatten.t index 8c23c3c..414cfcf 100644 --- a/t/10-flatten.t +++ b/t/10-flatten.t @@ -41,10 +41,8 @@ my @tests = ( [ '\[$@%]', 'class got scalarref', [ \1 ], [ 1 ] ], [ '\[$@%]', 'class got arrayref', [ [ 1 ] ], [ 1 ] ], [ '\[$@%]', 'class got hashref', [ { 1,2 } ], [ 1, 2 ] ], - [ '_', '_ with argument', [ 1, 2 ], [ 1 ] ] + [ '_', '_ with argument', [ 1, 2 ], [ ] ], + [ '_', '_ with no argument', [ ], [ ] ] ); -my $l = [ '_', '_ with no argument', [ ] ]; -$l->[3] = [ $l ]; -push @tests, $l; is_deeply( [ flatten($_->[0], @{$_->[2]}) ], $_->[3], $_->[1]) for @tests;