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=c0fcbda0d536bb2381d1b9b47b93881d0000a5e1;hb=HEAD;hpb=123fd4f8368c8a468d735c9ee43ee871e22dc301 diff --git a/lib/Mouse/Meta/Method/Destructor.pm b/lib/Mouse/Meta/Method/Destructor.pm index c0fcbda..3611392 100644 --- a/lib/Mouse/Meta/Method/Destructor.pm +++ b/lib/Mouse/Meta/Method/Destructor.pm @@ -1,40 +1,50 @@ package Mouse::Meta::Method::Destructor; 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 (Mouse::Util::get_code_ref($class, 'DEMOLISH')) { - $demolishall .= sprintf "%s::DEMOLISH(\$self, \$Mouse::Util::in_global_destruction);\n", - $class, + $demolishall .= ' ' . $class + . '::DEMOLISH($self, $Mouse::Util::in_global_destruction);' + . "\n", } } - my $source = sprintf(<<'END_DESTROY', __LINE__, __FILE__, $demolishall); -#line %d %s - sub { - my $self = shift; + if($demolishall) { + $demolishall = sprintf <<'EOT', $demolishall; my $e = do{ local $?; local $@; eval{ - # demolishall %s; }; $@; }; no warnings 'misc'; die $e if $e; # rethrow +EOT } -END_DESTROY + + 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{ @@ -55,7 +65,7 @@ Mouse::Meta::Method::Destructor - A Mouse method generator for destructors =head1 VERSION -This document describes Mouse version 0.50_09 +This document describes Mouse version 0.95 =head1 SEE ALSO