From: Jesse Luehrs Date: Tue, 15 Jun 2010 08:52:14 +0000 (-0500) Subject: factor out a small part of the constructor inlining X-Git-Tag: 1.08~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5117b888d4fd87a867a231338d4b2fbe6e5c36a4;p=gitmo%2FMoose.git factor out a small part of the constructor inlining --- diff --git a/lib/Moose/Meta/Method/Constructor.pm b/lib/Moose/Meta/Method/Constructor.pm index 3d429fb..8d8fcee 100644 --- a/lib/Moose/Meta/Method/Constructor.pm +++ b/lib/Moose/Meta/Method/Constructor.pm @@ -59,9 +59,11 @@ sub _initialize_body { $source .= "\n" . 'my $class = Scalar::Util::blessed($_instance) || $_instance;'; - $source .= "\n" . 'return $class->Moose::Object::new(@_)'; - $source .= "\n if \$class ne '" . $self->associated_metaclass->name - . "';\n"; + $source .= "\n" . "if (\$class ne '" . $self->associated_metaclass->name + . "') {"; + $source .= "\n return " + . $self->_generate_fallback_constructor('$class') . ";"; + $source .= "\n}\n"; $source .= $self->_generate_params('$params', '$class'); $source .= $self->_generate_instance('$instance', '$class'); @@ -111,6 +113,11 @@ sub _initialize_body { $self->{'body'} = $code; } +sub _generate_fallback_constructor { + my ( $self, $class_var ) = @_; + "${class_var}->Moose::Object::new(\@_)"; +} + sub _generate_params { my ( $self, $var, $class_var ) = @_; "my $var = " . $self->_generate_BUILDARGS( $class_var, '@_' ) . ";\n";