[Moose-commits] r7783 - Moose/trunk/t/020_attributes

stevan at code2.0beta.co.uk stevan at code2.0beta.co.uk
Mon Feb 23 19:58:00 GMT 2009


Author: stevan
Date: 2009-02-23 11:58:00 -0800 (Mon, 23 Feb 2009)
New Revision: 7783

Added:
   Moose/trunk/t/020_attributes/025_chained_coercion.t
Log:
new test

Added: Moose/trunk/t/020_attributes/025_chained_coercion.t
===================================================================
--- Moose/trunk/t/020_attributes/025_chained_coercion.t	                        (rev 0)
+++ Moose/trunk/t/020_attributes/025_chained_coercion.t	2009-02-23 19:58:00 UTC (rev 7783)
@@ -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');
+
+




More information about the Moose-commits mailing list