diff options
Diffstat (limited to 't/attributes/chained_coercion.t')
-rw-r--r-- | t/attributes/chained_coercion.t | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/t/attributes/chained_coercion.t b/t/attributes/chained_coercion.t new file mode 100644 index 0000000..853f251 --- /dev/null +++ b/t/attributes/chained_coercion.t @@ -0,0 +1,46 @@ +use strict; +use warnings; + +use Test::More; + +{ + package Baz; + use Moose; + use Moose::Util::TypeConstraints; + + coerce 'Baz' => from 'HashRef' => via { Baz->new($_) }; + + has 'hello' => ( + is => 'ro', + isa => 'Str', + ); + + package Bar; + use Moose; + use Moose::Util::TypeConstraints; + + coerce 'Bar' => from 'HashRef' => via { Bar->new($_) }; + + has 'baz' => ( + is => 'ro', + isa => 'Baz', + coerce => 1 + ); + + package Foo; + use Moose; + + has 'bar' => ( + is => 'ro', + isa => 'Bar', + coerce => 1, + ); +} + +my $foo = Foo->new(bar => { baz => { hello => 'World' } }); +isa_ok($foo, 'Foo'); +isa_ok($foo->bar, 'Bar'); +isa_ok($foo->bar->baz, 'Baz'); +is($foo->bar->baz->hello, 'World', '... this all worked fine'); + +done_testing; |