X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FMethod%2FDestructor.pm;h=98121fc8721ff5699108ca2c6210afc4ccb969b7;hb=6f94c802188d44415bafdd64422cecd24585a289;hp=a687d773b24d0dec7f93876f638f25030bfdcec4;hpb=dbe21639d532a07229d0beeffafafba66a7e26f5;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Method/Destructor.pm b/lib/Moose/Meta/Method/Destructor.pm index a687d77..98121fc 100644 --- a/lib/Moose/Meta/Method/Destructor.pm +++ b/lib/Moose/Meta/Method/Destructor.pm @@ -6,12 +6,12 @@ use warnings; use Scalar::Util 'blessed', 'weaken'; -our $VERSION = '0.79'; +our $VERSION = '0.87'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; use base 'Moose::Meta::Method', - 'Class::MOP::Method::Generated'; + 'Class::MOP::Method::Inlined'; sub new { my $class = shift; @@ -57,7 +57,7 @@ sub is_needed { || $self->throw_error( "The is_needed method expected a metaclass object as its arugment"); - return $metaclass->find_method_by_name('DEMOLISH'); + return $metaclass->find_method_by_name("DEMOLISHALL"); } sub initialize_body { @@ -78,24 +78,33 @@ sub _initialize_body { my @DEMOLISH_methods = $self->associated_metaclass->find_all_methods_by_name('DEMOLISH'); - return unless @DEMOLISH_methods; + my $source; + if ( @DEMOLISH_methods ) { + $source = 'sub {'; - my $source = 'sub {'; + my @DEMOLISH_calls; + foreach my $method (@DEMOLISH_methods) { + push @DEMOLISH_calls => '$_[0]->' . $method->{class} . '::DEMOLISH()'; + } - my @DEMOLISH_calls; - foreach my $method (@DEMOLISH_methods) { - push @DEMOLISH_calls => '$_[0]->' . $method->{class} . '::DEMOLISH()'; - } + $source .= join ";\n" => @DEMOLISH_calls; - $source .= join ";\n" => @DEMOLISH_calls; + $source .= ";\n" . '}'; + } else { + $source = 'sub { }'; + } - $source .= ";\n" . '}'; warn $source if $self->options->{debug}; - my $code = $self->_compile_code( + my ( $code, $e ) = $self->_compile_code( environment => {}, code => $source, - ) or $self->throw_error("Could not eval the destructor :\n\n$source\n\nbecause :\n\n$@", error => $@, data => $source); + ); + + $self->throw_error( + "Could not eval the destructor :\n\n$source\n\nbecause :\n\n$e", + error => $e, data => $source ) + if $e; $self->{'body'} = $code; }