From: Dave Rolsky Date: Thu, 4 Dec 2008 16:59:27 +0000 (+0000) Subject: More refactorings - short circuit out of various methods if we're not X-Git-Tag: 0.71_02~23 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2690a5c01d7c6a19c1d40789880d678899b8d1b0;p=gitmo%2FClass-MOP.git More refactorings - short circuit out of various methods if we're not going to do them (inline constructor, destructor, etc) --- diff --git a/lib/Class/MOP/Immutable.pm b/lib/Class/MOP/Immutable.pm index 793d2bf..494a340 100644 --- a/lib/Class/MOP/Immutable.pm +++ b/lib/Class/MOP/Immutable.pm @@ -140,8 +140,13 @@ sub _inline_constructor { return unless $options->{inline_constructor}; + return + unless $options->{replace_constructor} + or !$metaclass->has_method( $options->{constructor_name} ); + my $constructor_class = $options->{constructor_class} || 'Class::MOP::Method::Constructor'; + $metaclass->add_method( $options->{constructor_name}, $constructor_class->new( @@ -151,9 +156,8 @@ sub _inline_constructor { package_name => $metaclass->name, name => $options->{constructor_name} ) - ) - if $options->{replace_constructor} - or !$metaclass->has_method( $options->{constructor_name} ); + ); + } sub _inline_destructor { @@ -167,17 +171,18 @@ sub _inline_destructor { my $destructor_class = $options->{destructor_class}; - if ( $destructor_class->is_needed($metaclass) ) { - my $destructor = $destructor_class->new( - options => $options, - metaclass => $metaclass, - package_name => $metaclass->name, - name => 'DESTROY' - ); + return unless $destructor_class->is_needed($metaclass); - $metaclass->add_method( 'DESTROY' => $destructor ) - if $destructor->is_needed; - } + my $destructor = $destructor_class->new( + options => $options, + metaclass => $metaclass, + package_name => $metaclass->name, + name => 'DESTROY' + ); + + return unless $destructor->is_needed; + + $metaclass->add_method( 'DESTROY' => $destructor ) } sub _memoize_methods {