DEATH TO ALL zionist ELLIPSES
[gitmo/Moose.git] / t / 020_attributes / 025_chained_coercion.t
CommitLineData
77b2b6f2 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 Moose;
12 use Moose::Util::TypeConstraints;
d03bd989 13
77b2b6f2 14 coerce 'Baz' => from 'HashRef' => via { Baz->new($_) };
d03bd989 15
77b2b6f2 16 has 'hello' => (
17 is => 'ro',
d03bd989 18 isa => 'Str',
77b2b6f2 19 );
d03bd989 20
77b2b6f2 21 package Bar;
22 use Moose;
23 use Moose::Util::TypeConstraints;
d03bd989 24
77b2b6f2 25 coerce 'Bar' => from 'HashRef' => via { Bar->new($_) };
d03bd989 26
77b2b6f2 27 has 'baz' => (
28 is => 'ro',
d03bd989 29 isa => 'Baz',
77b2b6f2 30 coerce => 1
31 );
d03bd989 32
77b2b6f2 33 package Foo;
34 use Moose;
d03bd989 35
77b2b6f2 36 has 'bar' => (
37 is => 'ro',
d03bd989 38 isa => 'Bar',
77b2b6f2 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');
1808c2da 47is($foo->bar->baz->hello, 'World', 'this all worked fine');
77b2b6f2 48
49