X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FObject.pm;h=5b7d17ea07906a79d3a90f279c12d67d12688051;hb=ddd4992c86d379ec9b013bdbb6e070d939ee18f0;hp=bec65195b79e96227d013746fcbbfa9463bf1e8d;hpb=da4cb9138f328819fed3e779b4b03cdd9294ce24;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Object.pm b/lib/Mouse/Object.pm index bec6519..5b7d17e 100644 --- a/lib/Mouse/Object.pm +++ b/lib/Mouse/Object.pm @@ -23,12 +23,25 @@ sub new { my $instance = bless {}, $class; - for my $attribute (values %{ $class->meta->get_attribute_map }) { + for my $attribute ($class->meta->compute_all_applicable_attributes) { my $from = $attribute->init_arg; my $key = $attribute->name; my $default; - if (!exists($args{$from})) { + if (defined($from) && exists($args{$from})) { + $attribute->verify_type_constraint($args{$from}) + if $attribute->has_type_constraint; + + $instance->{$key} = $args{$from}; + + weaken($instance->{$key}) + if ref($instance->{$key}) && $attribute->is_weak_ref; + + if ($attribute->has_trigger) { + $attribute->trigger->($instance, $args{$from}, $attribute); + } + } + else { if ($attribute->has_default || $attribute->has_builder) { unless ($attribute->is_lazy) { my $default = $attribute->default; @@ -54,20 +67,6 @@ sub new { } } } - - if (exists($args{$from})) { - $attribute->verify_type_constraint($args{$from}) - if $attribute->has_type_constraint; - - $instance->{$key} = $args{$from}; - - weaken($instance->{$key}) - if ref($instance->{$key}) && $attribute->is_weak_ref; - - if ($attribute->has_trigger) { - $attribute->trigger->($instance, $args{$from}, $attribute); - } - } } $instance->BUILDALL(\%args);