Save some work, thanks Chip.
[gitmo/MooseX-UndefTolerant.git] / lib / MooseX / UndefTolerant / Attribute.pm
index 1c99219..97ad7ea 100644 (file)
@@ -1,14 +1,17 @@
 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;
 
-    # If it was defined, call the real init slot method
+    # $_[2] is the hashref of options passed to the constructor. If our
+    # parameter passed in was undef, pop it off the args...
+    pop unless (defined $ia && defined($_[2]->{$ia}));
+
+    # Invoke the real init, as the above line cleared the unef
     $self->$orig(@_)
 });
 
@@ -16,7 +19,7 @@ around('initialize_instance_slot', sub{
 
 =head1 NAME
 
-MooseX::UndefTolerant::Attribute - Make your attribute tolerant to undef intitialization
+MooseX::UndefTolerant::Attribute - Make your attribute(s) tolerant to undef intitialization
 
 =head1 SYNOPSIS
 
@@ -42,8 +45,8 @@ MooseX::UndefTolerant::Attribute - Make your attribute tolerant to undef intitia
 
 Applying this trait to your attribute makes it's initialization tolerant of
 of undef.  If you specify the value of undef to any of the attributes they
-will not be initialized.  Effectively behaving as if you had not provided a
-value at all.
+will not be initialized (or will be set to the default, if applicable). 
+Effectively behaving as if you had not provided a value at all.
 
 =head1 AUTHOR