X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FObject.pm;h=265787a5074be89f0286b112ab4c9c9f46988673;hb=2230a6a3776852f5d73e634c9ddd909d95ca4d7d;hp=4af0f3957d5d6f1f5342c90a21e61e831bfdd909;hpb=f89acace2fa0fd5e6b8c4ac40ab1794f1ca62887;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Object.pm b/lib/Mouse/Object.pm index 4af0f39..265787a 100644 --- a/lib/Mouse/Object.pm +++ b/lib/Mouse/Object.pm @@ -13,10 +13,11 @@ sub new { my $instance = bless {}, $class; for my $attribute (values %{ $class->meta->get_attribute_map }) { - my $key = $attribute->init_arg; + my $from = $attribute->init_arg; + my $key = $attribute->name; my $default; - if (!exists($args{$key})) { + if (!exists($args{$from})) { if ($attribute->has_default || $attribute->has_builder) { unless ($attribute->is_lazy) { my $default = $attribute->default; @@ -33,7 +34,7 @@ sub new { $instance->{$key} = $value; weaken($instance->{$key}) - if $attribute->weak_ref; + if ref($instance->{$key}) && $attribute->is_weak_ref; } } else { @@ -43,17 +44,17 @@ sub new { } } - if (exists($args{$key})) { - $attribute->verify_type_constraint($args{$key}) + if (exists($args{$from})) { + $attribute->verify_type_constraint($args{$from}) if $attribute->has_type_constraint; - $instance->{$key} = $args{$key}; + $instance->{$key} = $args{$from}; weaken($instance->{$key}) - if $attribute->weak_ref; + if ref($instance->{$key}) && $attribute->is_weak_ref; if ($attribute->has_trigger) { - $attribute->trigger->($instance, $args{$key}, $attribute); + $attribute->trigger->($instance, $args{$from}, $attribute); } } } @@ -73,7 +74,7 @@ sub BUILDALL { no strict 'refs'; - for my $class ($self->meta->linearized_isa) { + for my $class (reverse $self->meta->linearized_isa) { my $code = *{ $class . '::BUILD' }{CODE} or next; $code->($self, @_);