From: Yuval Kogman Date: Wed, 13 Aug 2008 21:34:26 +0000 (+0000) Subject: accept hash ref to _new X-Git-Tag: 0_64_01~17 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=26ffbb36c3741396b796f1049a86b87cb8319c0d;p=gitmo%2FClass-MOP.git accept hash ref to _new --- diff --git a/lib/Class/MOP/Method/Constructor.pm b/lib/Class/MOP/Method/Constructor.pm index 466eee8..df1d5c2 100644 --- a/lib/Class/MOP/Method/Constructor.pm +++ b/lib/Class/MOP/Method/Constructor.pm @@ -86,11 +86,13 @@ sub generate_constructor_method_inline { my $self = shift; my $source = 'sub {'; - $source .= "\n" . 'my ($class, %params) = @_;'; + $source .= "\n" . 'my $class = shift;'; - $source .= "\n" . 'return Class::MOP::Class->initialize($class)->new_object(%params)'; + $source .= "\n" . 'return Class::MOP::Class->initialize($class)->new_object(@_)'; $source .= "\n" . ' if $class ne \'' . $self->associated_metaclass->name . '\';'; + $source .= "\n" . 'my $params = @_ == 1 ? $_[0] : {@_};'; + $source .= "\n" . 'my $instance = ' . $self->meta_instance->inline_create_instance('$class'); $source .= ";\n" . (join ";\n" => map { $self->_generate_slot_initializer($_) @@ -142,11 +144,11 @@ sub _generate_slot_initializer { if ( defined $attr->init_arg ) { return ( - 'if(exists $params{\'' . $attr->init_arg . '\'}){' . "\n" . + 'if(exists $params->{\'' . $attr->init_arg . '\'}){' . "\n" . $self->meta_instance->inline_set_slot_value( '$instance', ("'" . $attr->name . "'"), - '$params{\'' . $attr->init_arg . '\'}' ) . "\n" . + '$params->{\'' . $attr->init_arg . '\'}' ) . "\n" . '} ' . (!defined $default ? '' : 'else {' . "\n" . $self->meta_instance->inline_set_slot_value( '$instance',