From: Shawn M Moore Date: Wed, 3 Dec 2008 03:17:10 +0000 (+0000) Subject: Make the constructor close over the metaclass, and bless into the right class (so... X-Git-Tag: 0.19~136^2~76 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=24ad3f66c198a2cad61e0d7c91c956b1926746f9;p=gitmo%2FMouse.git Make the constructor close over the metaclass, and bless into the right class (so subclassing works) --- diff --git a/lib/Mouse/Meta/Method/Constructor.pm b/lib/Mouse/Meta/Method/Constructor.pm index 84d36ee..b1db7d4 100644 --- a/lib/Mouse/Meta/Method/Constructor.pm +++ b/lib/Mouse/Meta/Method/Constructor.pm @@ -3,34 +3,29 @@ use strict; use warnings; sub generate_constructor_method_inline { - my ($class, $meta) = @_; - my $code = $class->_generate_constructor_method_inline($meta); - warn $code if $ENV{DEBUG}; - - local $@; - my $res = eval $code; - die $@ if $@; - $res; -} - -sub _generate_constructor_method_inline { my ($class, $meta) = @_; + my $buildall = $class->_generate_BUILDALL($meta); my $buildargs = $class->_generate_BUILDARGS(); - my $classname = $meta->name; my $processattrs = $class->_generate_processattrs($meta); - return <<"..."; + my $code = <<"..."; sub { my \$class = shift; my \$args = $buildargs; - my \$instance = bless {}, '$classname'; - my \$meta = \$instance->meta; + my \$instance = bless {}, \$class; $processattrs; $buildall; return \$instance; } ... + + warn $code if $ENV{DEBUG}; + + local $@; + my $res = eval $code; + die $@ if $@; + $res; } sub _generate_processattrs {