revert local $\@ around require to avoid eating errors
[gitmo/Role-Tiny.git] / lib / Method / Generate / Constructor.pm
index e4f7b1f..95cbe88 100644 (file)
@@ -42,7 +42,8 @@ sub generate_method {
     $spec->{$no_init}{init_arg} = $no_init;
   }
   local $self->{captures} = {};
-  my $body = '    my $class = shift;'."\n";
+  my $body = '    my $class = shift;'."\n"
+            .'    $class = ref($class) if ref($class);'."\n";
   $body .= $self->_handle_subconstructor($into, $name);
   my $into_buildargs = $into->can('BUILDARGS');
   if ( $into_buildargs && $into_buildargs != \&Moo::Object::BUILDARGS ) {
@@ -54,12 +55,16 @@ sub generate_method {
   $body .= '    my $new = '.$self->construction_string.";\n";
   $body .= $self->_assign_new($spec);
   if ($into->can('BUILD')) {
-    { local $@; require Method::Generate::BuildAll; }
+    require Method::Generate::BuildAll;
     $body .= Method::Generate::BuildAll->new->buildall_body_for(
       $into, '$new', '$args'
     );
   }
   $body .= '    return $new;'."\n";
+  if ($into->can('DEMOLISH')) {
+    { local $@; require Method::Generate::DemolishAll; }
+    Method::Generate::DemolishAll->new->generate_method($into);
+  }
   quote_sub
     "${into}::${name}" => $body,
     $self->{captures}, $quote_opts||{}