X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F800_shikabased%2F005-class_type.t;fp=t%2F800_shikabased%2F005-class_type.t;h=b47077c2af713b664377db019ab1b021ed6d807d;hb=47f36c052bd0722ea67a4fbc18aca51234a1f5bc;hp=0000000000000000000000000000000000000000;hpb=b6ffa107ada7a537575481d277818e207ed219fb;p=gitmo%2FMouse.git diff --git a/t/800_shikabased/005-class_type.t b/t/800_shikabased/005-class_type.t new file mode 100644 index 0000000..b47077c --- /dev/null +++ b/t/800_shikabased/005-class_type.t @@ -0,0 +1,35 @@ +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' }; + coerce 'Headers' => +{ + HashRef => sub { + Response::Headers->new(%{ $_ }); + }, + }; + + has headers => ( + is => 'rw', + isa => 'Headers', + coerce => 1, + ); +} + +my $res = Response->new(headers => { foo => 'bar' }); +isa_ok($res->headers, 'Response::Headers'); +is($res->headers->foo, 'bar'); +$res->headers({foo => 'yay'}); +isa_ok($res->headers, 'Response::Headers'); +is($res->headers->foo, 'yay');