From: Dave Rolsky 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.0205~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ff64e6e82d0357f4a5b7a79d20064e847d1d6783;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 ) = @_;