1 package Method::Generate::DemolishAll;
4 use base qw(Moo::Object);
5 use Devel::GlobalDestruction ();
11 my ($self, $into) = @_;
12 quote_sub "${into}::DEMOLISHALL", join '',
13 $self->_handle_subdemolish($into),
14 qq{ my \$self = shift;\n},
15 $self->demolishall_body_for($into, '$self', '@_'),
17 quote_sub "${into}::DESTROY", join '',
24 $self->DEMOLISHALL(Devel::GlobalDestruction::in_global_destruction);
30 die $e if $e; # rethrow
34 sub demolishall_body_for {
35 my ($self, $into, $me, $args) = @_;
37 grep *{_getglob($_)}{CODE},
39 @{Moo::_Utils::_get_linear_isa($into)};
40 join '', map qq{ ${me}->${_}(${args});\n}, @demolishers;
43 sub _handle_subdemolish {
44 my ($self, $into) = @_;
45 ' if (ref($_[0]) ne '.perlstring($into).') {'."\n".
46 ' return shift->Moo::Object::DEMOLISHALL(@_)'.";\n".