Skip tests for strict constructor on Moose
[gitmo/Mouse.git] / t / 001_mouse / 806-role_type.t
CommitLineData
ecc6e3b1 1use strict;
2use warnings;
47f36c05 3use Test::More tests => 5;
ecc6e3b1 4
5{
47f36c05 6 package Request::Headers::Role;
7 use Mouse::Role;
8 has 'foo' => ( is => 'rw' );
9}
10
11{
12 package Request::Headers;
ecc6e3b1 13 use Mouse;
47f36c05 14 with 'Request::Headers::Role';
15}
16
17{
18 package Response::Headers::Role;
19 use Mouse::Role;
ecc6e3b1 20 has 'foo' => ( is => 'rw' );
21}
22
23{
47f36c05 24 package Response::Headers;
25 use Mouse;
26 with 'Response::Headers::Role';
27}
28
29{
ecc6e3b1 30 package Response;
31 use Mouse;
3b46bd49 32 use Mouse::Util::TypeConstraints;
ecc6e3b1 33
47f36c05 34 role_type Headers => { role => 'Response::Headers::Role' };
61a02a3a 35 coerce 'Headers' =>
36 from 'HashRef' => via {
ecc6e3b1 37 Response::Headers->new(%{ $_ });
38 },
61a02a3a 39 ;
ecc6e3b1 40
41 has headers => (
42 is => 'rw',
43 isa => 'Headers',
44 coerce => 1,
45 );
46}
47
48my $res = Response->new(headers => { foo => 'bar' });
49isa_ok($res->headers, 'Response::Headers');
50is($res->headers->foo, 'bar');
51$res->headers({foo => 'yay'});
52isa_ok($res->headers, 'Response::Headers');
53is($res->headers->foo, 'yay');
47f36c05 54
55eval {
56 $res->headers( Request::Headers->new( foo => 'baz' ) );
57};
58ok $@;