Merge branch 'topic/native-trait-bugfix'
Dave Rolsky [Fri, 19 Nov 2010 15:16:53 +0000 (09:16 -0600)]
Conflicts:
Changes
lib/Moose/Meta/Method/Accessor/Native/Collection.pm

Changes
lib/Moose/Meta/Method/Accessor/Native/Collection.pm
t/070_native_traits/011_array_subtypes.t

diff --git a/Changes b/Changes
index e73dbcd..a99d871 100644 (file)
--- a/Changes
+++ b/Changes
@@ -19,6 +19,12 @@ NEXT
   * We now load the roles needed for native delegations only as needed. This
     speeds up the compilation time for Moose itself. (doy)
 
+  [BUG FIXES]
+
+  * When using native delegations, if an array or hash ref member failed a
+    type constraint check, Moose ended up erroring out with "Can't call method
+    "get_message" on unblessed reference" instead of generating a useful error
+    based on the failed type constraint. Reported by t0m. (Dave Rolsky)
 
 1.19 Tue, Nov 2, 2010
 
index 5e75523..26cf3c5 100644 (file)
@@ -107,7 +107,7 @@ sub _inline_check_member_constraint {
                 $self->_inline_throw_error(
                     '"A new member value for ' . $attr_name
                   . ' does not pass its type constraint because: "'
-                  . ' . $member_tc->get_message($_)',
+                  . ' . $member_tc_obj->get_message($_)',
                     'data => $_',
                 ) . ';',
             '}',
index 1c30ad4..6b38ae7 100644 (file)
@@ -234,4 +234,32 @@ my $foo = Foo->new;
     );
 }
 
+{
+    package Bar;
+    use Moose;
+}
+
+{
+    package HasArray;
+    use Moose;
+
+    has objects => (
+        isa     => 'ArrayRef[Foo]',
+        traits  => ['Array'],
+        handles => {
+            push_objects => 'push',
+        },
+    );
+}
+
+{
+    my $ha = HasArray->new();
+
+    like(
+        exception { $ha->push_objects( Bar->new ) },
+        qr/\QValidation failed for 'Foo'/,
+        'got expected error when pushing an object of the wrong class onto an array ref'
+    );
+}
+
 done_testing;