From: Dave Rolsky Date: Thu, 4 Dec 2008 20:35:53 +0000 (+0000) Subject: Add a can_be_inlined method to CMOP::Method::Constructor which we X-Git-Tag: 0.71_02~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f0de47d9b033b6b5175454e7fb3fb43c4ef5ed2e;p=gitmo%2FClass-MOP.git Add a can_be_inlined method to CMOP::Method::Constructor which we check in CMOP::Immutable. We will override this in Moose to only inline the constructor if our class wants to use the one from Moose::Object. --- diff --git a/lib/Class/MOP/Immutable.pm b/lib/Class/MOP/Immutable.pm index eda19ba..47e1bac 100644 --- a/lib/Class/MOP/Immutable.pm +++ b/lib/Class/MOP/Immutable.pm @@ -147,17 +147,16 @@ sub _inline_constructor { my $constructor_class = $options->{constructor_class} || 'Class::MOP::Method::Constructor'; - $metaclass->add_method( - $options->{constructor_name}, - $constructor_class->new( - options => $options, - metaclass => $metaclass, - is_inline => 1, - package_name => $metaclass->name, - name => $options->{constructor_name} - ) + my $constructor = $constructor_class->new( + options => $options, + metaclass => $metaclass, + is_inline => 1, + package_name => $metaclass->name, + name => $options->{constructor_name}, ); + $metaclass->add_method( $options->{constructor_name} => $constructor ) + if $constructor->can_be_inlined; } sub _inline_destructor { diff --git a/lib/Class/MOP/Method/Constructor.pm b/lib/Class/MOP/Method/Constructor.pm index db506b8..f14c035 100644 --- a/lib/Class/MOP/Method/Constructor.pm +++ b/lib/Class/MOP/Method/Constructor.pm @@ -52,6 +52,8 @@ sub _new { }, $class; } +sub can_be_inlined { 1 } + ## accessors sub options { (shift)->{'options'} } @@ -227,6 +229,12 @@ metaclass which is passed into C. This returns a boolean, but since constructors are very rarely not inlined, this always returns true for now. +=item B + +This method always returns true in this class. It exists so that +subclasses (like in Moose) can override and do some sort of checking +to determine whether or not inlining the constructor is safe. + =item B This creates the code reference for the constructor itself.