From: wu-lee Date: Mon, 6 Apr 2009 14:28:18 +0000 (+0100) Subject: Fixed bug in the immutable constructor. It now redispatches to X-Git-Tag: 0.20~12 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=commitdiff_plain;h=4e14530461aa16875d80a0574d8f98e4eb5d24a8 Fixed bug in the immutable constructor. It now redispatches to Mouse::Object->new if the invoking class is not the one it was contructed for, as Moose's implementation does. Test case included. --- diff --git a/lib/Mouse/Meta/Method/Constructor.pm b/lib/Mouse/Meta/Method/Constructor.pm index 24a2b3c..75f589d 100644 --- a/lib/Mouse/Meta/Method/Constructor.pm +++ b/lib/Mouse/Meta/Method/Constructor.pm @@ -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; diff --git a/t/030_roles/failing/005_role_conflict_detection.t b/t/030_roles/failing/005_role_conflict_detection.t index eea1dc3..5be6ea6 100755 --- a/t/030_roles/failing/005_role_conflict_detection.t +++ b/t/030_roles/failing/005_role_conflict_detection.t @@ -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');