X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FMethod%2FDestructor.pm;h=36113928dc33fd4b99bff0e69b08fd598a3ae9d6;hp=bdaea1bd56171a65bea3e5348aef0ed8e834f850;hb=HEAD;hpb=6e168432fa69bbe87ff0dd12e355a8b5d99a1a9c diff --git a/lib/Mouse/Meta/Method/Destructor.pm b/lib/Mouse/Meta/Method/Destructor.pm index bdaea1b..3611392 100644 --- a/lib/Mouse/Meta/Method/Destructor.pm +++ b/lib/Mouse/Meta/Method/Destructor.pm @@ -1,38 +1,50 @@ package Mouse::Meta::Method::Destructor; -use Mouse::Util qw(get_code_ref); # enables strict and warnings +use Mouse::Util qw(:meta); # enables strict and warnings -sub _empty_DESTROY{ } +use constant _MOUSE_DEBUG => $ENV{MOUSE_DEBUG} ? 1 : 0; sub _generate_destructor{ my (undef, $metaclass) = @_; - if(!$metaclass->name->can('DEMOLISH')){ - return \&_empty_DESTROY; - } - my $demolishall = ''; for my $class ($metaclass->linearized_isa) { - if (get_code_ref($class, 'DEMOLISH')) { - $demolishall .= "${class}::DEMOLISH(\$self);\n"; + if (Mouse::Util::get_code_ref($class, 'DEMOLISH')) { + $demolishall .= ' ' . $class + . '::DEMOLISH($self, $Mouse::Util::in_global_destruction);' + . "\n", } } - my $source = sprintf("#line %d %s\n", __LINE__, __FILE__) . <<"..."; - sub { - my \$self = shift; - local \$?; - - my \$e = do{ - local \$@; + if($demolishall) { + $demolishall = sprintf <<'EOT', $demolishall; + my $e = do{ + local $?; + local $@; eval{ - $demolishall; + %s; }; - \$@; + $@; }; no warnings 'misc'; - die \$e if \$e; # rethrow + die $e if $e; # rethrow +EOT } -... + + my $name = $metaclass->name; + my $source = sprintf(<<'EOT', __FILE__, $name, $demolishall); +#line 1 "%s" + package %s; + sub { + my($self) = @_; + return $self->Mouse::Object::DESTROY() + if ref($self) ne __PACKAGE__; + # DEMOLISHALL + %s; + return; + } +EOT + + warn $source if _MOUSE_DEBUG; my $code; my $e = do{ @@ -53,7 +65,7 @@ Mouse::Meta::Method::Destructor - A Mouse method generator for destructors =head1 VERSION -This document describes Mouse version 0.40_05 +This document describes Mouse version 0.95 =head1 SEE ALSO