From: Kent Fredric Date: Tue, 23 Apr 2013 21:11:21 +0000 (+1200) Subject: lib/Moo/HandleMoose.pm: Fix for rt#84615 X-Git-Tag: v1.002000~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5d20f26c05ae145f3f3cfa6b2d8486e5b2f70f29;p=gitmo%2FMoo.git lib/Moo/HandleMoose.pm: Fix for rt#84615 If the constructor autovivification call returns 'undef', then the package we're trying to get the contructor for, ( and from that, the constructor specs ), that package was not constructed via package; use Moo; doesn't turn up in %Moo::MAKERS, and must either be either Moose::Object itself, or a simple child class of that. Therefore, assume it has no attributes, and inflate a minimal methods-only metaclass. --- diff --git a/Changes b/Changes index b5c9bc9..493cc83 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ + - successfully inflate a metaclass for attributeless classes (RT#86415) - fix false default values used with non-lazy accessors - stop built values that fail isa checks still getting stored in the object - stop lazy+weak_ref accessors re-building their value on every call diff --git a/lib/Moo/HandleMoose.pm b/lib/Moo/HandleMoose.pm index 8b19839..3bcb725 100644 --- a/lib/Moo/HandleMoose.pm +++ b/lib/Moo/HandleMoose.pm @@ -65,11 +65,14 @@ sub inject_real_metaclass_for { { @attr_info }, [ @attr_info[grep !($_ % 2), 0..$#attr_info] ] ) - } else { - my $specs = Moo->_constructor_maker_for($name)->all_attribute_specs; + } elsif ( my $cmaker = Moo->_constructor_maker_for($name) ) { + my $specs = $cmaker->all_attribute_specs; (0, Moose::Meta::Class->initialize($name), $specs, [ sort { $specs->{$a}{index} <=> $specs->{$b}{index} } keys %$specs ] ); + } else { + # This codepath is used if $name does not exist in $Moo::MAKERS + (0, Moose::Meta::Class->initialize($name), {}, [] ) } };