From: Shawn M Moore Date: Mon, 22 Dec 2008 03:32:37 +0000 (+0000) Subject: You can redefine types in the original package X-Git-Tag: 0.19~86 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0d062abb99e8c296c9f5d9f6ea6a100c8bde3294;p=gitmo%2FMouse.git You can redefine types in the original package --- diff --git a/lib/Mouse/Util/TypeConstraints.pm b/lib/Mouse/Util/TypeConstraints.pm index 732797f..ec44eb1 100644 --- a/lib/Mouse/Util/TypeConstraints.pm +++ b/lib/Mouse/Util/TypeConstraints.pm @@ -90,7 +90,7 @@ my $optimized_constraints_base; sub _type { my $pkg = caller(0); my($name, %conf) = @_; - if (my $type = $TYPE{$name}) { + 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 { $TYPE{delete $conf{as} || 'Any' } }; @@ -102,7 +102,7 @@ sub _type { sub _subtype { my $pkg = caller(0); my($name, %conf) = @_; - if (my $type = $TYPE{$name}) { + 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 { $TYPE{delete $conf{as} || 'Any' } }; diff --git a/t/800_shikabased/002-coerce_multi_class.t b/t/800_shikabased/002-coerce_multi_class.t index b2d26b8..2166e3f 100644 --- a/t/800_shikabased/002-coerce_multi_class.t +++ b/t/800_shikabased/002-coerce_multi_class.t @@ -90,9 +90,11 @@ ok !$@; eval { package Response; - type 'Headers' => where { defined $_ && eval { $_->isa('Response::Headers') } }; + type 'Headers' => where { + eval { $_->isa('Response::Headers') } + }; }; -like $@, qr/The type constraint 'Headers' has already been created in Response and cannot be created again in Response/; +ok(!$@, "You can redefine types in their original package"); { package Request;