X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F022-init-arg.t;h=9546e3dfc42f8c391eedf7493776e7e551b52c44;hb=de3f9ba5c62f6e2b1cf64d057ffef60224b4204a;hp=559c3b90bd39ee8b03feeb7d94f65ba4fa98ecf1;hpb=f3c1ccc818bb5c50c50e17b9141b91c09b077b04;p=gitmo%2FMouse.git diff --git a/t/022-init-arg.t b/t/022-init-arg.t index 559c3b9..9546e3d 100644 --- a/t/022-init-arg.t +++ b/t/022-init-arg.t @@ -1,7 +1,7 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 9; +use Test::More tests => 11; do { package Class; @@ -9,6 +9,7 @@ do { has name => ( is => 'rw', + isa => 'Str', init_arg => 'key', default => 'default', ); @@ -20,11 +21,30 @@ 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, 'name', 'attribute value is from name'); +is($object2->name, 'key', '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'); +is($object2->{name}, 'key', 'value is in key from name'); my $attr = $object2->meta->get_attribute('name'); ok($attr, 'got the attribute object by name (not init_arg)'); is($attr->name, 'name', 'name is name'); is($attr->init_arg, 'key', 'init_arg is key'); + +do { + package Foo; + use Mouse; + + has name => ( + is => 'rw', + init_arg => undef, + default => 'default', + ); +}; + +my $foo = Foo->new(name => 'joe'); +is($foo->name, 'default', 'init_arg => undef ignores attribute name in the constructor'); + +Foo->meta->make_immutable; + +my $bar = Foo->new(name => 'joe'); +is($bar->name, 'default', 'init_arg => undef ignores attribute name in the inlined constructor');