We only need local $? if we inline calls to DEMOLISH
[gitmo/Moose.git] / t / attributes / chained_coercion.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 {
9     package Baz;
10     use Moose;
11     use Moose::Util::TypeConstraints;
12
13     coerce 'Baz' => from 'HashRef' => via { Baz->new($_) };
14
15     has 'hello' => (
16         is      => 'ro',
17         isa     => 'Str',
18     );
19
20     package Bar;
21     use Moose;
22     use Moose::Util::TypeConstraints;
23
24     coerce 'Bar' => from 'HashRef' => via { Bar->new($_) };
25
26     has 'baz' => (
27         is      => 'ro',
28         isa     => 'Baz',
29         coerce  => 1
30     );
31
32     package Foo;
33     use Moose;
34
35     has 'bar' => (
36         is      => 'ro',
37         isa     => 'Bar',
38         coerce  => 1,
39     );
40 }
41
42 my $foo = Foo->new(bar => { baz => { hello => 'World' } });
43 isa_ok($foo, 'Foo');
44 isa_ok($foo->bar, 'Bar');
45 isa_ok($foo->bar->baz, 'Baz');
46 is($foo->bar->baz->hello, 'World', '... this all worked fine');
47
48 done_testing;