From: Yuval Kogman Date: Sat, 23 May 2009 20:45:05 +0000 (+0200) Subject: Inline DESTROY even without DEMOLISH methods X-Git-Tag: 0.80~69 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8c86556cba116d097d2ae85cd3940aa280139989;p=gitmo%2FMoose.git Inline DESTROY even without DEMOLISH methods This prevents Moose::Object::DESTROY from calling Moose::Object::DEMOLISHALL only to find that there are no DEMOLISH methods at every object destruction --- diff --git a/Changes b/Changes index 88d3321..0bdc83b 100644 --- a/Changes +++ b/Changes @@ -8,6 +8,9 @@ for, noteworthy changes. up three times today (perigrin) - Win doy $10 dollars because Sartak didn't think anybody would document this fast enough (perigrin) + * Moose::Meta::Method::Destructor + - Inline a DESTROY method even if there are no DEMOLISH methods to + prevent unnecessary introspection in Moose::Object::DEMOLISHALL 0.79 Wed, May 13, 2009 * Tests diff --git a/lib/Moose/Meta/Method/Destructor.pm b/lib/Moose/Meta/Method/Destructor.pm index a687d77..5946c23 100644 --- a/lib/Moose/Meta/Method/Destructor.pm +++ b/lib/Moose/Meta/Method/Destructor.pm @@ -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,18 +78,22 @@ 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(