From: Stevan Little Date: Mon, 23 Feb 2009 19:58:00 +0000 (+0000) Subject: new test X-Git-Tag: 0.72~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=77b2b6f2ff38f991eaefa4d50547d95b09ed848c;p=gitmo%2FMoose.git new test --- diff --git a/t/020_attributes/025_chained_coercion.t b/t/020_attributes/025_chained_coercion.t new file mode 100644 index 0000000..108a174 --- /dev/null +++ b/t/020_attributes/025_chained_coercion.t @@ -0,0 +1,49 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 4; +use Test::Exception; + +{ + 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'); + +