);
}
$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||{}
qq{ my \$self = shift;\n},
$self->demolishall_body_for($into, '$self', '@_'),
qq{ return \$self\n};
+ quote_sub "${into}::DESTROY", join '',
+ q! my $self = shift;
+ my $e = do {
+ local $?;
+ local $@;
+ require Moo::_Utils;
+ eval {
+ $self->DEMOLISHALL($Moo::_Utils::_in_global_destruction);
+ };
+ $@;
+ };
+
+ no warnings 'misc';
+ die $e if $e; # rethrow
+ !;
}
sub demolishall_body_for {
sub new {
my $class = shift;
+ unless (exists $NO_DEMOLISH{$class}) {
+ unless ($NO_DEMOLISH{$class} = !$class->can('DEMOLISH')) {
+ ($DEMOLISH_MAKER ||= do {
+ { local $@; require Method::Generate::DemolishAll; }
+ Method::Generate::DemolishAll->new
+ })->generate_method($class);
+ }
+ }
$NO_BUILD{$class} and
return bless({ ref($_[0]) eq 'HASH' ? %{$_[0]} : @_ }, $class);
$NO_BUILD{$class} = !$class->can('BUILD') unless exists $NO_BUILD{$class};
})->generate_method(ref($self)))}(@_);
}
-sub DESTROY {
- my $self = shift;
-
- my $class = ref($self);
-
- $NO_DEMOLISH{$class} = !$class->can('DEMOLISH')
- unless exists $NO_DEMOLISH{$class};
-
- return if $NO_DEMOLISH{$class};
-
- my $e = do {
- local $?;
- local $@;
- require Moo::_Utils;
- eval {
- $self->DEMOLISHALL($Moo::_Utils::_in_global_destruction);
- };
- $@;
- };
-
- no warnings 'misc';
- die $e if $e; # rethrow
-}
-
sub does {
{ local $@; require Role::Tiny; }
{ no warnings 'redefine'; *does = \&Role::Tiny::does_role }