From: Fuji, Goro Date: Sat, 25 Sep 2010 06:56:46 +0000 (+0900) Subject: Fix destructor fallbacks in pure Perl X-Git-Tag: 0.72~12 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b17191d0f772ef7115555a605b6477ddb0f6bc8a;p=gitmo%2FMouse.git Fix destructor fallbacks in pure Perl --- diff --git a/lib/Mouse/Meta/Method/Destructor.pm b/lib/Mouse/Meta/Method/Destructor.pm index ae0eab1..7649525 100644 --- a/lib/Mouse/Meta/Method/Destructor.pm +++ b/lib/Mouse/Meta/Method/Destructor.pm @@ -1,15 +1,9 @@ package Mouse::Meta::Method::Destructor; use Mouse::Util qw(:meta); # enables strict and warnings -sub _empty_DESTROY{ } - sub _generate_destructor{ my (undef, $metaclass) = @_; - if(!$metaclass->name->can('DEMOLISH')){ - return \&_empty_DESTROY; - } - my $demolishall = ''; for my $class ($metaclass->linearized_isa) { if (Mouse::Util::get_code_ref($class, 'DEMOLISH')) { @@ -18,10 +12,14 @@ sub _generate_destructor{ } } - my $source = sprintf(<<'END_DESTROY', __LINE__, __FILE__, $demolishall); + my $name = $metaclass->name; + my $source = sprintf(<<'EOT', __LINE__, __FILE__, $name, $demolishall); #line %d %s + package %s; sub { my $self = shift; + return $self->Mouse::Object::DESTROY() + if ref($self) ne __PACKAGE__; my $e = do{ local $?; local $@; @@ -34,7 +32,7 @@ sub _generate_destructor{ no warnings 'misc'; die $e if $e; # rethrow } -END_DESTROY +EOT my $code; my $e = do{