Resolve a todo
[gitmo/Mouse.git] / t / 020_attributes / 025_chained_coercion.t
CommitLineData
4060c871 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 4;
7use 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
43my $foo = Foo->new(bar => { baz => { hello => 'World' } });
44isa_ok($foo, 'Foo');
45isa_ok($foo->bar, 'Bar');
46isa_ok($foo->bar->baz, 'Baz');
47is($foo->bar->baz->hello, 'World', '... this all worked fine');
48
49