Commit | Line | Data |
c3398f5b |
1 | #!/usr/bin/env perl |
2 | use strict; |
3 | use warnings; |
4 | use Test::More tests => 9; |
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'); |
19 | is($object->{name}, undef, 'nothing in object->{attribute name}!'); |
20 | is($object->{key}, 'default', 'value is in object->{init_arg}'); |
21 | |
22 | my $object2 = Class->new(name => 'name', key => 'key'); |
23 | is($object2->name, 'key', 'attribute value is from init_arg'); |
24 | is($object2->{name}, undef, 'no value for the attribute name'); |
25 | is($object2->{key}, 'key', 'value is from init_arg parameter'); |
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'); |