summaryrefslogtreecommitdiff
path: root/t/attributes/chained_coercion.t
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2015-06-06 17:50:16 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2015-06-06 17:50:16 +0000
commit5ac2026f7eed78958d69d051e7a8e993dcf51205 (patch)
tree298c3d2f08bdfe5689998b11892d72a897985be1 /t/attributes/chained_coercion.t
downloadMoose-tarball-master.tar.gz
Diffstat (limited to 't/attributes/chained_coercion.t')
-rw-r--r--t/attributes/chained_coercion.t46
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;