package Mouse::Meta::Method::Destructor;
-use Mouse::Util; # enables strict and warnings
+use Mouse::Util qw(:meta); # enables strict and warnings
sub _empty_DESTROY{ }
my $demolishall = '';
for my $class ($metaclass->linearized_isa) {
- no strict 'refs';
- if (*{$class . '::DEMOLISH'}{CODE}) {
- $demolishall .= "${class}::DEMOLISH(\$self);\n";
+ if (Mouse::Util::get_code_ref($class, 'DEMOLISH')) {
+ $demolishall .= sprintf "%s::DEMOLISH(\$self, \$Mouse::Util::in_global_destruction);\n",
+ $class,
}
}
- my $source = sprintf("#line %d %s\n", __LINE__, __FILE__) . <<"...";
+ my $source = sprintf(<<'END_DESTROY', __LINE__, __FILE__, $demolishall);
+#line %d %s
sub {
- my \$self = shift;
- $demolishall;
+ my $self = shift;
+ my $e = do{
+ local $?;
+ local $@;
+ eval{
+ # demolishall
+ %s;
+ };
+ $@;
+ };
+ no warnings 'misc';
+ die $e if $e; # rethrow
}
-...
+END_DESTROY
my $code;
my $e = do{
1;
__END__
+
+=head1 NAME
+
+Mouse::Meta::Method::Destructor - A Mouse method generator for destructors
+
+=head1 VERSION
+
+This document describes Mouse version 0.71
+
+=head1 SEE ALSO
+
+L<Moose::Meta::Method::Destructor>
+
+=cut