From: gfx Date: Sun, 20 Sep 2009 06:53:03 +0000 (+0900) Subject: Fix a bug related to the randomized hash keys. X-Git-Tag: 0.32~47 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cd2b92018095c8d3bc88f46cef5f5a0a11e0bf3b;p=gitmo%2FMouse.git Fix a bug related to the randomized hash keys. --- diff --git a/lib/Mouse/Util/TypeConstraints.pm b/lib/Mouse/Util/TypeConstraints.pm index 993e8e0..8df17ea 100644 --- a/lib/Mouse/Util/TypeConstraints.pm +++ b/lib/Mouse/Util/TypeConstraints.pm @@ -18,19 +18,17 @@ my %COERCE; my %COERCE_KEYS; sub as ($) { - as => $_[0] + return(as => $_[0]); } sub where (&) { - where => $_[0] + return(where => $_[0]) } sub message (&) { - message => $_[0] + return(message => $_[0]) } sub from { @_ } -sub via (&) { - $_[0] -} +sub via (&) { $_[0] } BEGIN { no warnings 'uninitialized'; @@ -78,9 +76,10 @@ BEGIN { sub type { my $pkg = caller(0); my($name, %conf) = @_; + if ($TYPE{$name} && $TYPE_SOURCE{$name} ne $pkg) { Carp::croak "The type constraint '$name' has already been created in $TYPE_SOURCE{$name} and cannot be created again in $pkg"; - }; + } my $constraint = $conf{where} || do { my $as = delete $conf{as} || 'Any'; if (! exists $TYPE{$as}) { @@ -133,7 +132,7 @@ sub subtype { } sub coerce { - my($name, %conf) = @_; + my $name = shift; Carp::croak "Cannot find type '$name', perhaps you forgot to load it." unless $TYPE{$name}; @@ -142,7 +141,8 @@ sub coerce { $COERCE{$name} = {}; $COERCE_KEYS{$name} = []; } - while (my($type, $code) = each %conf) { + + while (my($type, $code) = splice @_, 0, 2) { Carp::croak "A coercion action already exists for '$type'" if $COERCE{$name}->{$type}; @@ -155,9 +155,10 @@ sub coerce { } } - unshift @{ $COERCE_KEYS{$name} }, $type; + push @{ $COERCE_KEYS{$name} }, $type; $COERCE{$name}->{$type} = $code; } + return; } sub class_type { diff --git a/t/800_shikabased/013-compatibility-get_method_list.t b/t/800_shikabased/013-compatibility-get_method_list.t index b2852c2..d43247c 100644 --- a/t/800_shikabased/013-compatibility-get_method_list.t +++ b/t/800_shikabased/013-compatibility-get_method_list.t @@ -1,7 +1,7 @@ use strict; use warnings; use Test::More; -plan skip_all => "This test requires Moose 0.81" unless eval { require Moose; Moose->VERSION(0.81); }; +plan skip_all => "This test requires Moose 0.90" unless eval { require Moose; Moose->VERSION(0.90); }; plan tests => 6; test($_) for qw/Moose Mouse/;