From: Karen Etheridge Date: Wed, 3 Nov 2010 23:01:12 +0000 (-0700) Subject: rename a variable, to make it more clear that we are not working with the Moose:... X-Git-Tag: 0.09~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8e67fa0cc9dee4d8ea506e8f7db0c5d6a2ef9917;p=gitmo%2FMooseX-UndefTolerant.git rename a variable, to make it more clear that we are not working with the Moose::Meta::Attribute object here, but the parameter name as passed to the constructor --- diff --git a/lib/MooseX/UndefTolerant/Constructor.pm b/lib/MooseX/UndefTolerant/Constructor.pm index 47d8128..841811d 100644 --- a/lib/MooseX/UndefTolerant/Constructor.pm +++ b/lib/MooseX/UndefTolerant/Constructor.pm @@ -4,15 +4,17 @@ use Moose::Role; around('_generate_slot_initializer', sub { my $orig = shift; my $self = shift; - my $attr = $self->_attributes->[$_[0]]->init_arg; + + # note the key in the params may not match the attr name. + my $key_name = $self->_attributes->[$_[0]]->init_arg; # insert a line of code at the start of the initializer, # clearing the param if it's undefined. - if (defined $attr) { + if (defined $key_name) { my $tolerant_code = - qq# delete \$params->{'$attr'} unless # . - qq# exists \$params->{'$attr'} && defined \$params->{'$attr'};\n#; + qq# delete \$params->{'$key_name'} unless # . + qq# exists \$params->{'$key_name'} && defined \$params->{'$key_name'};\n#; return $tolerant_code . $self->$orig(@_); }