From: 大沢 和宏 Date: Fri, 5 Dec 2008 00:22:40 +0000 (+0000) Subject: more optimized of TypeRegistry X-Git-Tag: 0.19~136^2~32 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d3982c7e7f662fb205f4fca0a264c3479bba4438;p=gitmo%2FMouse.git more optimized of TypeRegistry --- diff --git a/lib/Mouse/TypeRegistry.pm b/lib/Mouse/TypeRegistry.pm index b5d069c..c722ec1 100644 --- a/lib/Mouse/TypeRegistry.pm +++ b/lib/Mouse/TypeRegistry.pm @@ -47,7 +47,7 @@ my $optimized_constraints; my $optimized_constraints_base; { no warnings 'uninitialized'; - $optimized_constraints = $optimized_constraints_base = { + $SUBTYPE = { Any => sub { 1 }, Item => sub { 1 }, Bool => sub { @@ -79,7 +79,12 @@ my $optimized_constraints_base; Object => sub { blessed($_) && blessed($_) ne 'Regexp' }, }; + + sub optimized_constraints { $SUBTYPE } + my @SUBTYPE_KEYS = keys %{ $SUBTYPE }; + sub list_all_builtin_type_constraints { @SUBTYPE_KEYS } } + sub _subtype { my $pkg = caller(0); my($name, %conf) = @_; @@ -90,7 +95,6 @@ sub _subtype { my $stuff = $conf{where} || optimized_constraints()->{$as}; $SUBTYPE->{$name} = $stuff; - $optimized_constraints = +{ %{ $SUBTYPE }, %{ $optimized_constraints_base } }; } sub _coerce { @@ -150,12 +154,6 @@ sub typecast_constraints { return $value; } -sub optimized_constraints { $optimized_constraints } -{ - my @optimized_constraints_keys = keys %{ $optimized_constraints }; - sub list_all_builtin_type_constraints { @optimized_constraints_keys } -} - 1; __END__ diff --git a/t/800_shikabased/009-overwrite-builtin-subtype.t b/t/800_shikabased/009-overwrite-builtin-subtype.t new file mode 100644 index 0000000..9bdd60c --- /dev/null +++ b/t/800_shikabased/009-overwrite-builtin-subtype.t @@ -0,0 +1,11 @@ +use strict; +use warnings; +use Test::More tests => 1; + +eval { + package Request; + use Mouse::TypeRegistry; + + subtype 'Int' => where { 1}; +}; +like $@, qr/The type constraint 'Int' has already been created, cannot be created again in Request/;