Commit | Line | Data |
c3398f5b |
1 | #!/usr/bin/env perl |
2 | use strict; |
3 | use warnings; |
1f679986 |
4 | use Test::More tests => 10; |
c3398f5b |
5 | |
6 | do { |
7 | package Class; |
8 | use Mouse; |
9 | |
10 | has name => ( |
11 | is => 'rw', |
12 | init_arg => 'key', |
13 | default => 'default', |
14 | ); |
15 | }; |
16 | |
17 | my $object = Class->new; |
18 | is($object->name, 'default', 'accessor uses attribute name'); |
f3c1ccc8 |
19 | is($object->{key}, undef, 'nothing in object->{init_arg}!'); |
20 | is($object->{name}, 'default', 'value is in object->{name}'); |
c3398f5b |
21 | |
22 | my $object2 = Class->new(name => 'name', key => 'key'); |
384072a3 |
23 | is($object2->name, 'key', 'attribute value is from name'); |
f3c1ccc8 |
24 | is($object2->{key}, undef, 'no value for the init_arg'); |
384072a3 |
25 | is($object2->{name}, 'key', 'value is in key from name'); |
c3398f5b |
26 | |
27 | my $attr = $object2->meta->get_attribute('name'); |
28 | ok($attr, 'got the attribute object by name (not init_arg)'); |
29 | is($attr->name, 'name', 'name is name'); |
30 | is($attr->init_arg, 'key', 'init_arg is key'); |
1f679986 |
31 | |
32 | do { |
33 | package Foo; |
34 | use Mouse; |
35 | |
36 | has name => ( |
37 | is => 'rw', |
38 | init_arg => undef, |
39 | default => 'default', |
40 | ); |
41 | }; |
42 | |
43 | my $foo = Foo->new(name => 'joe'); |
44 | is($foo->name, 'default', 'init_arg => undef ignores attribute name in the constructor'); |
45 | |