Moose compat: init_arg is not used for the hash key, name is
[gitmo/Mouse.git] / t / 022-init-arg.t
CommitLineData
c3398f5b 1#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More tests => 9;
5
6do {
7 package Class;
8 use Mouse;
9
10 has name => (
11 is => 'rw',
12 init_arg => 'key',
13 default => 'default',
14 );
15};
16
17my $object = Class->new;
18is($object->name, 'default', 'accessor uses attribute name');
f3c1ccc8 19is($object->{key}, undef, 'nothing in object->{init_arg}!');
20is($object->{name}, 'default', 'value is in object->{name}');
c3398f5b 21
22my $object2 = Class->new(name => 'name', key => 'key');
f3c1ccc8 23is($object2->name, 'name', 'attribute value is from name');
24is($object2->{key}, undef, 'no value for the init_arg');
25is($object2->{name}, 'name', 'value is in key from name');
c3398f5b 26
27my $attr = $object2->meta->get_attribute('name');
28ok($attr, 'got the attribute object by name (not init_arg)');
29is($attr->name, 'name', 'name is name');
30is($attr->init_arg, 'key', 'init_arg is key');