added role_type on Mouse::TypeRegistry
[gitmo/Mouse.git] / t / 800_shikabased / 005-class_type.t
1 use strict;
2 use warnings;
3 use Test::More tests => 4;
4
5 {
6     package Response::Headers;
7     use Mouse;
8     has 'foo' => ( is => 'rw' );
9 }
10
11 {
12     package Response;
13     use Mouse;
14     use Mouse::TypeRegistry;
15
16     class_type Headers => { class => 'Response::Headers' };
17     coerce 'Headers' => +{
18         HashRef => sub {
19             Response::Headers->new(%{ $_ });
20         },
21     };
22
23     has headers => (
24         is     => 'rw',
25         isa    => 'Headers',
26         coerce => 1,
27     );
28 }
29
30 my $res = Response->new(headers => { foo => 'bar' });
31 isa_ok($res->headers, 'Response::Headers');
32 is($res->headers->foo, 'bar');
33 $res->headers({foo => 'yay'});
34 isa_ok($res->headers, 'Response::Headers');
35 is($res->headers->foo, 'yay');