From: Karen Etheridge Date: Sat, 24 Mar 2012 21:18:31 +0000 (-0700) Subject: Prevent all attribute initializers from seeing the value when we remove it, not just... X-Git-Tag: 0.13~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=95f919704c988799ad0eca0b012fcc2a75ee69b6;p=gitmo%2FMooseX-UndefTolerant.git Prevent all attribute initializers from seeing the value when we remove it, not just this one This also avoids dereferencing an undef value in the wrapped method - I don't know why this wasn't generating a warning, but it's still not optimal --- diff --git a/Changes b/Changes index cfc2914..83fb3c2 100644 --- a/Changes +++ b/Changes @@ -4,6 +4,9 @@ Revision history for MooseX-UndefTolerant * unit test improvements - tighter TODO scopes, better diagnostics on failure, Test::Moose for cleaner logic * fix documentation referencing Moose changes that are still TBD + * undef attr values being stripped at construction time are now removed + from visibility of all attr initializations, not just the one being + updated at the time 0.12 2011-04-03 * This module can now be used in roles with Moose 1.9900+. (Jesse Luehrs) diff --git a/lib/MooseX/UndefTolerant/Attribute.pm b/lib/MooseX/UndefTolerant/Attribute.pm index aa8f5d1..9caabc7 100644 --- a/lib/MooseX/UndefTolerant/Attribute.pm +++ b/lib/MooseX/UndefTolerant/Attribute.pm @@ -4,19 +4,19 @@ use Moose::Role; around('initialize_instance_slot', sub { my $orig = shift; my $self = shift; + my ($meta_instance, $instance, $params) = @_; my $key_name = $self->init_arg; - # $_[2] is the hashref of options passed to the constructor. - # If our parameter passed in was undef, pop it off the args... + # If our parameter passed in was undef, remove it from the parameter list... # but leave the value unscathed if the attribute's type constraint can # handle undef (or doesn't have one, which implicitly means it can) - if (not defined $key_name or not defined($_[2]->{$key_name})) + if (not defined $key_name or not defined($params->{$key_name})) { my $type_constraint = $self->type_constraint; if ($type_constraint and not $type_constraint->check(undef)) { - pop; + delete $params->{$key_name}; } }