X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FObject.pm;h=e72542c5aed460adb60d9872462b86b8a5c0a7f2;hb=f3c1ccc818bb5c50c50e17b9141b91c09b077b04;hp=dcb859018dccf16359d766ad3b51d68d8abfffc4;hpb=b17094cee3a42ff2669ee90b8393542de142633d;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Object.pm b/lib/Mouse/Object.pm index dcb8590..e72542c 100644 --- a/lib/Mouse/Object.pm +++ b/lib/Mouse/Object.pm @@ -12,15 +12,14 @@ sub new { my %args = @_; my $instance = bless {}, $class; - for my $attribute ($class->meta->attributes) { - my $key = $attribute->init_arg; + for my $attribute (values %{ $class->meta->get_attribute_map }) { + my $key = $attribute->name; my $default; if (!exists($args{$key})) { if ($attribute->has_default || $attribute->has_builder) { - my $default = $attribute->default; - unless ($attribute->is_lazy) { + my $default = $attribute->default; my $builder = $attribute->builder; my $value = $attribute->has_builder ? $instance->$builder @@ -34,12 +33,12 @@ sub new { $instance->{$key} = $value; weaken($instance->{$key}) - if $attribute->weak_ref; + if ref($instance->{$key}) && $attribute->is_weak_ref; } } else { if ($attribute->is_required) { - confess "Attribute '".$attribute->name."' is required"; + confess "Attribute (".$attribute->name.") is required"; } } } @@ -51,7 +50,7 @@ sub new { $instance->{$key} = $args{$key}; 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);