From: Dave Rolsky <autarch@urth.org>
Date: Thu, 1 Sep 2011 14:52:52 +0000 (-0500)
Subject: Explicitly test each value of handles to make sure it's sane
X-Git-Tag: 2.0300~93
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b0b04f2bdc2492f31d566655327911836a98570a;p=gitmo%2FMoose.git

Explicitly test each value of handles to make sure it's sane
---

diff --git a/lib/Moose/Meta/Attribute/Native/Trait.pm b/lib/Moose/Meta/Attribute/Native/Trait.pm
index 52b19ee..3728406 100644
--- a/lib/Moose/Meta/Attribute/Native/Trait.pm
+++ b/lib/Moose/Meta/Attribute/Native/Trait.pm
@@ -124,13 +124,24 @@ around '_canonicalize_handles' => sub {
             "The 'handles' option must be a HASH reference, not $handles");
     }
 
-    return map {
-        my $to = $handles->{$_};
-        $to = [$to] unless ref $to;
-        $_ => $to
-    } keys %$handles;
+    return
+        map { $_ => $self->_canonicalize_handles_value( $handles->{$_} ) }
+        keys %$handles;
 };
 
+sub _canonicalize_handles_value {
+    my $self  = shift;
+    my $value = shift;
+
+    if ( ref $value && 'ARRAY' ne ref $value ) {
+        $self->throw_error(
+            "All values passed to handles must be strings or ARRAY references, not $value"
+        );
+    }
+
+    return ref $value ? $value : [$value];
+}
+
 around '_make_delegation_method' => sub {
     my $next = shift;
     my ( $self, $handle_name, $method_to_call ) = @_;