From: 大沢 和宏 Date: Mon, 8 Dec 2008 03:16:44 +0000 (+0000) Subject: pre load class in class_type X-Git-Tag: 0.19~136^2~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2f6fade8c45bfc6086a1fb2342de026397cab53c;p=gitmo%2FMouse.git pre load class in class_type --- diff --git a/lib/Mouse/TypeRegistry.pm b/lib/Mouse/TypeRegistry.pm index 156dcc6..458c810 100644 --- a/lib/Mouse/TypeRegistry.pm +++ b/lib/Mouse/TypeRegistry.pm @@ -127,6 +127,7 @@ sub _class_type { my $pkg = caller(0); my($name, $conf) = @_; my $class = $conf->{class}; + Mouse::load_class($class); _subtype( $name => where => sub { defined $_ && ref($_) eq $class; diff --git a/t/800_shikabased/005-class_type.t b/t/800_shikabased/005-class_type.t index d8b89cf..18418e3 100644 --- a/t/800_shikabased/005-class_type.t +++ b/t/800_shikabased/005-class_type.t @@ -1,22 +1,15 @@ use strict; use warnings; use Test::More tests => 4; - -{ - package Response::Headers; - use Mouse; - has 'foo' => ( is => 'rw' ); -} - { package Response; use Mouse; use Mouse::TypeRegistry; - class_type Headers => { class => 'Response::Headers' }; + class_type Headers => { class => 't::lib::ClassType_Foo' }; coerce 'Headers' => from 'HashRef' => via { - Response::Headers->new(%{ $_ }); + t::lib::ClassType_Foo->new(%{ $_ }); }, ; @@ -28,8 +21,8 @@ use Test::More tests => 4; } my $res = Response->new(headers => { foo => 'bar' }); -isa_ok($res->headers, 'Response::Headers'); +isa_ok($res->headers, 't::lib::ClassType_Foo'); is($res->headers->foo, 'bar'); $res->headers({foo => 'yay'}); -isa_ok($res->headers, 'Response::Headers'); +isa_ok($res->headers, 't::lib::ClassType_Foo'); is($res->headers->foo, 'yay'); diff --git a/t/lib/ClassType_Foo.pm b/t/lib/ClassType_Foo.pm new file mode 100644 index 0000000..9c9bbd8 --- /dev/null +++ b/t/lib/ClassType_Foo.pm @@ -0,0 +1,4 @@ +package t::lib::ClassType_Foo; +use Mouse; +has 'foo' => ( is => 'rw' ); +1;