]> git.vpit.fr Git - perl/modules/Sub-Prototype-Util.git/commitdiff
Clean up flatten()
authorVincent Pit <vince@profvince.com>
Thu, 25 Aug 2011 09:42:18 +0000 (11:42 +0200)
committerVincent Pit <vince@profvince.com>
Thu, 25 Aug 2011 10:13:42 +0000 (12:13 +0200)
lib/Sub/Prototype/Util.pm

index a580cc16343103d061e3b8bc8c2a9e81debdb5d9..bfbd2a20b60129f898ba3db11df2495ddd794224 100644 (file)
@@ -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;
 }