Future-proof init_arg => undef, that needs tests though
[gitmo/Mouse.git] / lib / Mouse / Attribute.pm
index 41a56df..325c24d 100644 (file)
@@ -9,7 +9,8 @@ sub new {
     my $class = shift;
     my %args  = @_;
 
-    $args{init_arg} ||= $args{name};
+    $args{init_arg} = $args{name}
+        unless exists $args{init_arg};
     $args{is} ||= '';
 
     bless \%args, $class;
@@ -127,6 +128,8 @@ sub create {
     my $attribute = $self->new(%args, name => $name, class => $class);
     my $meta = $class->meta;
 
+    $meta->add_attribute($attribute);
+
     # install an accessor
     if ($attribute->{is} eq 'rw' || $attribute->{is} eq 'ro') {
         my $accessor = $attribute->generate_accessor;
@@ -134,8 +137,6 @@ sub create {
         *{ $class . '::' . $name } = $accessor;
     }
 
-    $meta->add_attribute($attribute);
-
     for my $method (qw/predicate clearer/) {
         if (exists $attribute->{$method}) {
             my $generator = "generate_$method";