From: Matt S Trout Date: Sat, 8 Jan 2011 06:14:54 +0000 (+0000) Subject: fix constructor firing for nonMoo through multiple layers of Moo X-Git-Tag: release_0.9.5~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=53875e2cf2ae5e6e86491d68649f320ec72fb4f7;p=gitmo%2FRole-Tiny.git fix constructor firing for nonMoo through multiple layers of Moo --- diff --git a/Changes b/Changes index 51ad7f0..f825bfb 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ + - Fix nonMoo constructor firing through multiple layers of Moo - Fix bug where nonMoo is mistakenly detected given a Moo superclass with no attributes (and hence no own constructor) diff --git a/lib/Moo.pm b/lib/Moo.pm index 2c02cf2..33d33ac 100644 --- a/lib/Moo.pm +++ b/lib/Moo.pm @@ -74,7 +74,6 @@ sub _constructor_maker_for { $moo_constructor = 1; # no other constructor, make a Moo one } }; - require Moo::_mro unless $moo_constructor; Method::Generate::Constructor ->new( package => $target, @@ -82,8 +81,11 @@ sub _constructor_maker_for { require Method::Generate::Accessor; Method::Generate::Accessor->new; }, - ($moo_constructor ? () - : (construction_string => '$class->next::method(@_)')) + construction_string => ( + $moo_constructor + ? ($con ? $con->construction_string : undef) + : ('$class->'.$target.'::SUPER::new(@_)') + ) ) ->install_delayed ->register_attribute_specs(%{$con?$con->all_attribute_specs:{}}) diff --git a/t/extends-non-moo.t b/t/extends-non-moo.t index 9c6beb1..17d87fd 100644 --- a/t/extends-non-moo.t +++ b/t/extends-non-moo.t @@ -30,6 +30,11 @@ use Test::More; use Moo; extends 't::moo::extends_non_moo::middle'; has 'attr' => (is=>'ro'); + + package t::moo::extends_non_moo::second_level_moo; + use Moo; + extends 't::moo::extends_non_moo::moo_with_attr'; + has 'attr2' => (is=>'ro'); } ok my $app = 100, @@ -53,4 +58,10 @@ ok $app = t::moo::extends_non_moo::moo_with_attr->wrap($app), is $app, 100, '$app still 100'; +ok $app = t::moo::extends_non_moo::second_level_moo->wrap($app), + '$app from $app'; + +is $app, 100, + '$app still 100'; + done_testing();