* 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
+ * fixed case where an attribute on an immutable class was being stripped
+ of its undef value at construction time even if its type constraint
+ already can tolerate undef.
0.12 2011-04-03
* This module can now be used in roles with Moose 1.9900+. (Jesse Luehrs)
my @source = $self->$orig(@_);
my $init_arg = $attr->init_arg;
-
- return
- "if ( exists \$params->{$init_arg} && defined \$params->{$init_arg} ) {",
- @source,
+ my $type_constraint = $attr->type_constraint;
+ my $tc_says_clean = ($type_constraint && !$type_constraint->check(undef) ? 1 : 0);
+
+ return ($tc_says_clean ? (
+ "if ( exists \$params->{'$init_arg'} && defined \$params->{'$init_arg'} ) {",
+ ) : (),
+ @source,
+ $tc_says_clean ? (
'} else {',
- "delete \$params->{$init_arg};",
- '}';
+ "delete \$params->{'$init_arg'};",
+ '}',
+ ) : (),
+ );
};
no Moose::Role;
is (exception { $obj = Foo->new(attr3 => undef) }, undef,
'assigning undef to attr3 is acceptable');
- ok($obj->has_attr3, 'attr3 retains its undef value when assigned undef in constructor');
+ ok($obj->has_attr3, 'attr3 still has a value');
+ is($obj->attr3, undef, '...which is undef, when assigned undef in constructor');
},
undef,
'successfully tested spot-application of UT trait in '
'assigning undef to attr2 does not produce an error');
ok(!$obj->has_attr2, 'attr2 has no value when assigned undef in constructor');
- is( exception { $obj = Foo->new(attr3 => undef) }, undef,
+ is( exception { $obj = Bar->new(attr3 => undef) }, undef,
'assigning undef to attr3 is acceptable');
- ok($obj->has_attr3, 'attr3 retains its undef value when assigned undef in constructor');
+ ok($obj->has_attr3, 'attr3 still has a value');
+ is($obj->attr3, undef, '...which is undef, when assigned undef in constructor');
}
{