Commit | Line | Data |
4060c871 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More tests => 4; |
7 | use Test::Exception; |
8 | |
9 | { |
10 | package Baz; |
11 | use Mouse; |
12 | use Mouse::Util::TypeConstraints; |
13 | |
14 | coerce 'Baz' => from 'HashRef' => via { Baz->new($_) }; |
15 | |
16 | has 'hello' => ( |
17 | is => 'ro', |
18 | isa => 'Str', |
19 | ); |
20 | |
21 | package Bar; |
22 | use Mouse; |
23 | use Mouse::Util::TypeConstraints; |
24 | |
25 | coerce 'Bar' => from 'HashRef' => via { Bar->new($_) }; |
26 | |
27 | has 'baz' => ( |
28 | is => 'ro', |
29 | isa => 'Baz', |
30 | coerce => 1 |
31 | ); |
32 | |
33 | package Foo; |
34 | use Mouse; |
35 | |
36 | has 'bar' => ( |
37 | is => 'ro', |
38 | isa => 'Bar', |
39 | coerce => 1, |
40 | ); |
41 | } |
42 | |
43 | my $foo = Foo->new(bar => { baz => { hello => 'World' } }); |
44 | isa_ok($foo, 'Foo'); |
45 | isa_ok($foo->bar, 'Bar'); |
46 | isa_ok($foo->bar->baz, 'Baz'); |
47 | is($foo->bar->baz->hello, 'World', '... this all worked fine'); |
48 | |
49 | |