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=db966423c21ecad9b97542f03678c1c0e32cd1d8;hp=09e23bc938c87d28430d3e0fcfb38ca987fa5751;hb=70a922201a3b13a22b86ea918f53d3b964c377c7;hpb=8da68341396129a1b4545299fda0fae7e9cf6d56 diff --git a/lib/Mouse/Meta/Method/Destructor.pm b/lib/Mouse/Meta/Method/Destructor.pm index 09e23bc..db96642 100644 --- a/lib/Mouse/Meta/Method/Destructor.pm +++ b/lib/Mouse/Meta/Method/Destructor.pm @@ -1,37 +1,64 @@ package Mouse::Meta::Method::Destructor; -use strict; -use warnings; - -sub generate_destructor_method_inline { - my ($class, $meta) = @_; - - my $demolishall = do { - if ($meta->name->can('DEMOLISH')) { - my @code = (); - no strict 'refs'; - for my $klass ($meta->linearized_isa) { - if (*{$klass . '::DEMOLISH'}{CODE}) { - push @code, "${klass}::DEMOLISH(\$self);"; - } - } - join "\n", @code; - } else { - return; # no demolish =) +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')) { + $demolishall .= sprintf "%s::DEMOLISH(\$self, \$Mouse::Util::in_global_destruction);\n", + $class, } - }; + } - my $code = <<"..."; + 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 } -... - warn $code if $ENV{DEBUG}; +END_DESTROY - local $@; - my $res = eval $code; - die $@ if $@; - return $res; + my $code; + my $e = do{ + local $@; + $code = eval $source; + $@; + }; + die $e if $e; + return $code; } 1; +__END__ + +=head1 NAME + +Mouse::Meta::Method::Destructor - A Mouse method generator for destructors + +=head1 VERSION + +This document describes Mouse version 0.50_03 + +=head1 SEE ALSO + +L + +=cut