X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F800_shikabased%2F005-class_type.t;h=5b61762bb5b03f3620261ef6ef2e73e6fa47ecd0;hb=925ef7611f6ffc6b67b4fa5cbbbb3abe94c5f947;hp=b47077c2af713b664377db019ab1b021ed6d807d;hpb=47f36c052bd0722ea67a4fbc18aca51234a1f5bc;p=gitmo%2FMouse.git diff --git a/t/800_shikabased/005-class_type.t b/t/800_shikabased/005-class_type.t index b47077c..5b61762 100644 --- a/t/800_shikabased/005-class_type.t +++ b/t/800_shikabased/005-class_type.t @@ -1,24 +1,26 @@ 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; + use Mouse::Util::TypeConstraints; + + require t::lib::ClassType_Foo; - class_type Headers => { class => 'Response::Headers' }; - coerce 'Headers' => +{ - HashRef => sub { - Response::Headers->new(%{ $_ }); + # XXX: This below API is different from that of Moose. + # class_type() should be class_type 'ClassName'; + # class_type 'Headers' => { class => 't::lib::ClassType_Foo' }; + # this should be subtype Headers => as 't::lib::ClassType_foo'; + subtype 'Headers' + => as 't::lib::ClassType_Foo' + ; + + coerce 'Headers' => + from 'HashRef' => via { + t::lib::ClassType_Foo->new(%{ $_ }); }, - }; + ; has headers => ( is => 'rw', @@ -28,8 +30,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');