Revision history for MooseX-UndefTolerant
{{$NEXT}}
+ * avoid undef warning by not attempting to manipulate constructor data for
+ init_arg => undef attributes (thanks Damon Tkoch for the report!)
0.17 2012-05-03 14:43:42 PDT-0700
* re-release to fix dependency issue *again*! :)
# 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($params->{$key_name}))
+ if (defined $key_name and not defined($params->{$key_name}))
{
my $type_constraint = $self->type_constraint;
if ($type_constraint and not $type_constraint->check(undef))
}
}
- # Invoke the real init, as the above line cleared the undef
+ # Invoke the real init, as the above line cleared the undef param value
$self->$orig(@_)
});
--- /dev/null
+use strict;
+use warnings;
+
+use Test::More tests => 7;
+use Test::Fatal;
+use Test::Moose;
+use Test::NoWarnings 0.94 ':early';
+
+{
+package Foo;
+use Moose;
+use MooseX::UndefTolerant;
+
+has 'bar' => (
+ is => 'ro',
+ isa => 'Num',
+ init_arg => undef,
+);
+}
+
+package main;
+
+with_immutable
+{
+ is(exception { my $foo = Foo->new }, undef, 'constructed with no args');
+
+ is(exception { my $foo = Foo->new(bar => undef) }, undef, 'constructed with undef value');
+
+ is(exception { my $foo = Foo->new(bar => 1234) }, undef, 'constructed with defined value');
+} 'Foo';
+