From: Matt S Trout Date: Tue, 24 Apr 2012 18:48:01 +0000 (+0000) Subject: make extends after has work X-Git-Tag: v0.091000~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3b0d7efda1e2c58cd56285dc1cc2c563cb44d657;p=gitmo%2FMoo.git make extends after has work --- diff --git a/Changes b/Changes index 28f9525..d7c2242 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ + - make extends after has work - name subs if Sub::Name is available for better stracktraces - undefer all subs before creating a concrete Moose metaclass - fix bug in _load_module where global vars could cause mis-detection diff --git a/lib/Moo.pm b/lib/Moo.pm index ff1e20d..1f6300d 100644 --- a/lib/Moo.pm +++ b/lib/Moo.pm @@ -20,6 +20,11 @@ sub import { _load_module($_) for @_; # Can't do *{...} = \@_ or 5.10.0's mro.pm stops seeing @ISA @{*{_getglob("${target}::ISA")}{ARRAY}} = @_; + if (my $old = delete $Moo::MAKERS{$target}{constructor}) { + delete _getstash($target)->{new}; + Moo->_constructor_maker_for($target) + ->register_attribute_specs(%{$old->all_attribute_specs}); + } }; _install_coderef "${target}::with" => sub { require Moo::Role; diff --git a/t/has-before-extends.t b/t/has-before-extends.t new file mode 100644 index 0000000..2c36995 --- /dev/null +++ b/t/has-before-extends.t @@ -0,0 +1,25 @@ +use strictures 1; +use Test::More; + +{ + package Fail1; + + use Moo; + + has 'attr1' => (is => 'ro'); + + package Fail2; + + use Moo; + + has 'attr2' => (is => 'ro'); + + extends 'Fail1'; +} + +my $new = Fail2->new({ attr1 => 'value1', attr2 => 'value2' }); + +is($new->attr1, 'value1', 'inherited attr ok'); +is($new->attr2, 'value2', 'subclass attr ok'); + +done_testing;