Move is_valid_class_name into XS
[gitmo/Mouse.git] / t / 001_mouse / 805-class_type.t
1 use strict;
2 use warnings;
3 use Test::More tests => 4;
4 {
5     package Response;
6     use Mouse;
7     use Mouse::Util::TypeConstraints;
8
9     require t::lib::ClassType_Foo;
10
11     # XXX: This below API is different from that of Moose.
12     # class_type() should be class_type 'ClassName';
13     #    class_type 'Headers' => { class => 't::lib::ClassType_Foo' };
14     # this should be subtype Headers => as 't::lib::ClassType_foo';
15     subtype 'Headers'
16         => as 't::lib::ClassType_Foo'
17     ;
18         
19     coerce 'Headers' =>
20         from 'HashRef' => via {
21             t::lib::ClassType_Foo->new(%{ $_ });
22         },
23     ;
24
25     has headers => (
26         is     => 'rw',
27         isa    => 'Headers',
28         coerce => 1,
29     );
30 }
31
32 my $res = Response->new(headers => { foo => 'bar' });
33 isa_ok($res->headers, 't::lib::ClassType_Foo');
34 is($res->headers->foo, 'bar');
35 $res->headers({foo => 'yay'});
36 isa_ok($res->headers, 't::lib::ClassType_Foo');
37 is($res->headers->foo, 'yay');