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

index 93efb1f1286ee4c28a4c64c664f3f1ed7731dd0b..efcd9749771bafbedce3173e8970a399da6a3422 100644 (file)
@@ -45,19 +45,23 @@ They all handle C<5.10>'s C<_> prototype.
 
 =cut
 
-my %sigils = qw/SCALAR $ ARRAY @ HASH % GLOB * CODE &/;
+my %sigils   = qw/SCALAR $ ARRAY @ HASH % GLOB * CODE &/;
 my %reftypes = reverse %sigils;
 
 sub _check_ref {
- my ($a, $p) = @_;
- my $r;
- if (!defined $a || !defined($r = reftype $a)) { # not defined or plain scalar
-  croak 'Got ' . ((defined $a) ? 'a plain scalar' : 'undef')
-               . ' where a reference was expected';
+ my ($arg, $sigil) = @_;
+
+ my $reftype;
+ if (not defined $arg or not defined($reftype = reftype $arg)) {
+  # not defined or plain scalar
+  my $that = (defined $arg) ? 'a plain scalar' : 'undef';
+  croak "Got $that where a reference was expected";
  }
- croak 'Unexpected ' . $r . ' reference' unless exists $sigils{$r}
-                                            and $p =~ /\Q$sigils{$r}\E/;
- return $r;
+
+ croak "Unexpected $reftype reference" unless exists $sigils{$reftype}
+                                          and $sigil =~ /\Q$sigils{$reftype}\E/;
+
+ $reftype;
 }
 
 sub _clean_msg {