Commit | Line | Data |
ecc6e3b1 |
1 | use strict; |
2 | use warnings; |
3 | use Test::More tests => 4; |
ecc6e3b1 |
4 | { |
5 | package Response; |
6 | use Mouse; |
3b46bd49 |
7 | use Mouse::Util::TypeConstraints; |
ecc6e3b1 |
8 | |
a5fc1e9a |
9 | require t::lib::ClassType_Foo; |
10 | |
d9f8c878 |
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 | |
61a02a3a |
19 | coerce 'Headers' => |
20 | from 'HashRef' => via { |
2f6fade8 |
21 | t::lib::ClassType_Foo->new(%{ $_ }); |
ecc6e3b1 |
22 | }, |
61a02a3a |
23 | ; |
ecc6e3b1 |
24 | |
25 | has headers => ( |
26 | is => 'rw', |
27 | isa => 'Headers', |
28 | coerce => 1, |
29 | ); |
30 | } |
31 | |
32 | my $res = Response->new(headers => { foo => 'bar' }); |
2f6fade8 |
33 | isa_ok($res->headers, 't::lib::ClassType_Foo'); |
ecc6e3b1 |
34 | is($res->headers->foo, 'bar'); |
35 | $res->headers({foo => 'yay'}); |
2f6fade8 |
36 | isa_ok($res->headers, 't::lib::ClassType_Foo'); |
ecc6e3b1 |
37 | is($res->headers->foo, 'yay'); |