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 {
push @args, shift;
}
}
+
return @args;
}