From: Vincent Pit Date: Thu, 25 Aug 2011 09:42:18 +0000 (+0200) Subject: Clean up flatten() X-Git-Tag: v0.10~9 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FSub-Prototype-Util.git;a=commitdiff_plain;h=eb44d389e2988873318074f6fe1f090886e4beba Clean up flatten() --- diff --git a/lib/Sub/Prototype/Util.pm b/lib/Sub/Prototype/Util.pm index a580cc1..bfbd2a2 100644 --- a/lib/Sub/Prototype/Util.pm +++ b/lib/Sub/Prototype/Util.pm @@ -76,26 +76,31 @@ It croaks if the arguments can't possibly match the required prototype, e.g. whe sub flatten { my $proto = shift; + return @_ unless defined $proto; + my @args; while ($proto =~ /(\\?)(\[[^\]]+\]|[^\];])/g) { - my $p = $2; + my $sigil = $2; + if ($1) { - my $a = shift; - my $r = _check_ref $a, $p; - push @args, $r eq 'SCALAR' - ? $$a - : ($r eq 'ARRAY' - ? @$a - : ($r eq 'HASH' - ? %$a - : ($r eq 'GLOB' - ? *$a - : &$a # _check_ref ensures this must be a code ref + my $arg = shift; + my $reftype = _check_ref $arg, $sigil; + + push @args, $reftype eq 'SCALAR' + ? $$arg + : ($reftype eq 'ARRAY' + ? @$arg + : ($reftype eq 'HASH' + ? %$arg + : ($reftype eq 'GLOB' + ? *$arg + : &$arg # _check_ref ensures this must be a code ref ) ) ); - } elsif ($p =~ /[\@\%]/) { + + } elsif ($sigil =~ /[\@\%]/) { push @args, @_; last; } else { @@ -103,6 +108,7 @@ sub flatten { push @args, shift; } } + return @args; }