From: Yuval Kogman Date: Sun, 27 Jan 2008 00:16:37 +0000 (+0000) Subject: init_arg can be undef X-Git-Tag: 0_53~19 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c16c9c1b42d62dd68dcfbe2f2b71025f5fd39c50;p=gitmo%2FClass-MOP.git init_arg can be undef --- diff --git a/lib/Class/MOP/Method/Constructor.pm b/lib/Class/MOP/Method/Constructor.pm index fb3a316..5006d31 100644 --- a/lib/Class/MOP/Method/Constructor.pm +++ b/lib/Class/MOP/Method/Constructor.pm @@ -129,17 +129,28 @@ sub _generate_slot_initializer { $default = '$instance->'.$attr->builder; } - 'if(exists $params{\'' . $attr->init_arg . '\'}){' . "\n" . - $self->meta_instance->inline_set_slot_value( - '$instance', - ("'" . $attr->name . "'"), - '$params{\'' . $attr->init_arg . '\'}' ) . "\n" . - '} ' . (!defined $default ? '' : 'else {' . "\n" . - $self->meta_instance->inline_set_slot_value( - '$instance', - ("'" . $attr->name . "'"), - $default ) . "\n" . - '}'); + if ( defined $attr->init_arg ) { + return ( + 'if(exists $params{\'' . $attr->init_arg . '\'}){' . "\n" . + $self->meta_instance->inline_set_slot_value( + '$instance', + ("'" . $attr->name . "'"), + '$params{\'' . $attr->init_arg . '\'}' ) . "\n" . + '} ' . (!defined $default ? '' : 'else {' . "\n" . + $self->meta_instance->inline_set_slot_value( + '$instance', + ("'" . $attr->name . "'"), + $default ) . "\n" . + '}') + ); + } elsif ( defined $default ) { + return ( + $self->meta_instance->inline_set_slot_value( + '$instance', + ("'" . $attr->name . "'"), + $default ) . "\n" + ); + } else { return '' } } 1;