X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FMethod%2FDestructor.pm;h=ee10bdc9d6b28b41147cf8ab7f93cbfa227d2452;hb=3eb89f709f04907580b508f821d6be2316fcb65f;hp=1fce623c11019aa9d92089faad009620b835c812;hpb=6eff32cb0a932c52b0f65e9fbbcc99508cb734d1;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Method/Destructor.pm b/lib/Moose/Meta/Method/Destructor.pm index 1fce623..ee10bdc 100644 --- a/lib/Moose/Meta/Method/Destructor.pm +++ b/lib/Moose/Meta/Method/Destructor.pm @@ -4,9 +4,11 @@ package Moose::Meta::Method::Destructor; use strict; use warnings; +use Devel::GlobalDestruction (); use Scalar::Util 'blessed', 'weaken'; +use Try::Tiny (); -our $VERSION = '0.89_02'; +our $VERSION = '1.01'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; @@ -79,20 +81,31 @@ sub _initialize_body { my @DEMOLISH_methods = $self->associated_metaclass->find_all_methods_by_name('DEMOLISH'); my $source; + $source = 'sub {' . "\n"; + $source .= 'my $self = shift;' . "\n"; + $source .= 'return $self->Moose::Object::DESTROY(@_)' . "\n"; + $source .= ' if Scalar::Util::blessed($self) ne '; + $source .= "'" . $self->associated_metaclass->name . "'"; + $source .= ';' . "\n"; + if ( @DEMOLISH_methods ) { - $source = 'sub {'; - $source .= 'local ( $., $@, $!, $^E, $? );' . "\n"; + $source .= 'local $?;' . "\n"; + + $source .= 'my $in_global_destruction = Devel::GlobalDestruction::in_global_destruction;' . "\n"; + + $source .= 'Try::Tiny::try {' . "\n"; + + $source .= '$self->' . $_->{class} . '::DEMOLISH($in_global_destruction);' . "\n" + for @DEMOLISH_methods; - $source - .= join ";\n" => - map { '$_[0]->' . $_->{class} . '::DEMOLISH()' } - @DEMOLISH_methods; + $source .= '}'; + $source .= q[ Try::Tiny::catch { no warnings 'misc'; die $_ };] . "\n"; + $source .= 'return;' . "\n"; - $source .= ";\n" . '}'; - } else { - $source = 'sub { }'; } + $source .= '}'; + warn $source if $self->options->{debug}; my ( $code, $e ) = $self->_compile_code( @@ -167,13 +180,17 @@ of its parents defines a C method, it needs a destructor. =back +=head1 BUGS + +See L for details on reporting bugs. + =head1 AUTHORS Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE -Copyright 2006-2009 by Infinity Interactive, Inc. +Copyright 2006-2010 by Infinity Interactive, Inc. L