Fixed bug in the immutable constructor. It now redispatches to
wu-lee [Mon, 6 Apr 2009 14:28:18 +0000 (15:28 +0100)]
Mouse::Object->new if the invoking class is not the one it was
contructed for, as Moose's implementation does.  Test case included.

lib/Mouse/Meta/Method/Constructor.pm
t/030_roles/failing/005_role_conflict_detection.t

index 24a2b3c..75f589d 100644 (file)
@@ -5,6 +5,7 @@ use warnings;
 sub generate_constructor_method_inline {
     my ($class, $meta) = @_;
 
+    my $associated_metaclass_name = $meta->name;
     my @attrs = $meta->compute_all_applicable_attributes;
     my $buildall = $class->_generate_BUILDALL($meta);
     my $buildargs = $class->_generate_BUILDARGS($meta);
@@ -14,6 +15,8 @@ sub generate_constructor_method_inline {
     my $code = <<"...";
     sub {
         my \$class = shift;
+        return \$class->Mouse::Object::new(\@_)
+            if \$class ne '$associated_metaclass_name';
         $buildargs;
         my \$instance = bless {}, \$class;
         $processattrs;
index eea1dc3..5be6ea6 100755 (executable)
@@ -346,7 +346,7 @@ is(My::Test14->twist(), 'My::Test::Base::twist', '... got the right method retur
 }    
 
 ok(Role::Reality->meta->has_method('twist'), '... the twist method has not been added');
-#ok(!Role::Reality->meta->does_role('Role::Plot'), '... our role does() the correct roles');
+ok(!Role::Reality->meta->does_role('Role::Plot'), '... our role does() the correct roles');
 is(Role::Reality->meta->get_method('twist')->(), 
     'Role::Reality::twist', 
     '... the twist method returns the right value');