added role_type on Mouse::TypeRegistry
[gitmo/Mouse.git] / t / 800_shikabased / 005-class_type.t
diff --git a/t/800_shikabased/005-class_type.t b/t/800_shikabased/005-class_type.t
new file mode 100644 (file)
index 0000000..b47077c
--- /dev/null
@@ -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');