From: Cory Watson Date: Wed, 2 Dec 2009 14:31:07 +0000 (-0600) Subject: Fix. X-Git-Tag: 0.05~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=efcfddbdcfac9bcc3b9a8190f9fe3089199d65ec;p=gitmo%2FMooseX-UndefTolerant.git Fix. --- diff --git a/Changes b/Changes index e566494..3790191 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for MooseX-UndefTolerant +0.02 December 2, 2009 + * Actually check the value properly, therefore setting it properly + 0.01 Date/time First version, released on an unsuspecting world. diff --git a/lib/MooseX/UndefTolerant/Attribute.pm b/lib/MooseX/UndefTolerant/Attribute.pm index 1c99219..c1065aa 100644 --- a/lib/MooseX/UndefTolerant/Attribute.pm +++ b/lib/MooseX/UndefTolerant/Attribute.pm @@ -1,12 +1,15 @@ package MooseX::UndefTolerant::Attribute; use Moose::Role; -around('initialize_instance_slot', sub{ +around('initialize_instance_slot', sub { my $orig = shift; my $self = shift; - # If the parameter passed in was undef, quietly do nothing but return - return unless defined($_->[2]); + my $ia = $self->init_arg; + + # $_[2] is the hashref of options passed to the constructor. If our + # parameter passed in was undef, quietly do nothing but return. + return unless exists($_[2]->{$ia}) && defined($_[2]->{$ia}); # If it was defined, call the real init slot method $self->$orig(@_) diff --git a/t/attribute.t b/t/attribute.t index db0215f..7458ff6 100644 --- a/t/attribute.t +++ b/t/attribute.t @@ -37,5 +37,10 @@ package main; ok(!$foo->has_bar); } +{ + my $foo = Foo2->new(bar => 1234); + cmp_ok($foo->bar, 'eq', 1234); + ok($foo->has_bar); +} -done_testing; \ No newline at end of file +done_testing;