lib/Moo/HandleMoose.pm: Fix for rt#84615
[gitmo/Moo.git] / lib / Moo / HandleMoose.pm
index c7c29f0..3bcb725 100644 (file)
@@ -65,20 +65,25 @@ 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), {}, [] )
     }
   };
 
-  my %methods = %{Role::Tiny->_concrete_methods_of($name)};
-
-  while (my ($meth_name, $meth_code) = each %methods) {
-    $meta->add_method($meth_name, $meth_code) if $meth_code;
+  for my $spec (values %$attr_specs) {
+    if (my $inflators = delete $spec->{moosify}) {
+      $_->($spec) for @$inflators;
+    }
   }
 
+  my %methods = %{Role::Tiny->_concrete_methods_of($name)};
+
   # if stuff gets added afterwards, _maybe_reset_handlemoose should
   # trigger the recreation of the metaclass but we need to ensure the
   # Role::Tiny cache is cleared so we don't confuse Moo itself.
@@ -144,6 +149,11 @@ sub inject_real_metaclass_for {
       }
     }
   }
+  for my $meth_name (keys %methods) {
+    my $meth_code = $methods{$meth_name};
+    $meta->add_method($meth_name, $meth_code) if $meth_code;
+  }
+
   if ($am_role) {
     my $info = $Moo::Role::INFO{$name};
     $meta->add_required_methods(@{$info->{requires}});