From: Shawn M Moore Date: Tue, 10 Jun 2008 03:59:32 +0000 (+0000) Subject: Moose compat: init_arg is not used for the hash key, name is X-Git-Tag: 0.04~55 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f3c1ccc818bb5c50c50e17b9141b91c09b077b04;p=gitmo%2FMouse.git Moose compat: init_arg is not used for the hash key, name is --- diff --git a/lib/Mouse/Attribute.pm b/lib/Mouse/Attribute.pm index 0265e1d..7d3c380 100644 --- a/lib/Mouse/Attribute.pm +++ b/lib/Mouse/Attribute.pm @@ -44,7 +44,7 @@ sub generate_accessor { my $attribute = shift; my $name = $attribute->name; - my $key = $attribute->init_arg; + my $key = $name; my $default = $attribute->default; my $trigger = $attribute->trigger; my $type = $attribute->type_constraint; @@ -101,7 +101,7 @@ sub generate_accessor { sub generate_predicate { my $attribute = shift; - my $key = $attribute->init_arg; + my $key = $attribute->name; my $predicate = 'sub { exists($_[0]->{$key}) }'; @@ -110,7 +110,7 @@ sub generate_predicate { sub generate_clearer { my $attribute = shift; - my $key = $attribute->init_arg; + my $key = $attribute->name; my $predicate = 'sub { delete($_[0]->{$key}) }'; diff --git a/lib/Mouse/Object.pm b/lib/Mouse/Object.pm index fbd19ed..e72542c 100644 --- a/lib/Mouse/Object.pm +++ b/lib/Mouse/Object.pm @@ -13,7 +13,7 @@ sub new { my $instance = bless {}, $class; for my $attribute (values %{ $class->meta->get_attribute_map }) { - my $key = $attribute->init_arg; + my $key = $attribute->name; my $default; if (!exists($args{$key})) { diff --git a/t/022-init-arg.t b/t/022-init-arg.t index 0bfc783..559c3b9 100644 --- a/t/022-init-arg.t +++ b/t/022-init-arg.t @@ -16,13 +16,13 @@ do { my $object = Class->new; is($object->name, 'default', 'accessor uses attribute name'); -is($object->{name}, undef, 'nothing in object->{attribute name}!'); -is($object->{key}, 'default', 'value is in object->{init_arg}'); +is($object->{key}, undef, 'nothing in object->{init_arg}!'); +is($object->{name}, 'default', 'value is in object->{name}'); my $object2 = Class->new(name => 'name', key => 'key'); -is($object2->name, 'key', 'attribute value is from init_arg'); -is($object2->{name}, undef, 'no value for the attribute name'); -is($object2->{key}, 'key', 'value is from init_arg parameter'); +is($object2->name, 'name', 'attribute value is from name'); +is($object2->{key}, undef, 'no value for the init_arg'); +is($object2->{name}, 'name', 'value is in key from name'); my $attr = $object2->meta->get_attribute('name'); ok($attr, 'got the attribute object by name (not init_arg)');