6 use Test::More tests => 13;
15 package My::Attribute::Trait;
18 has 'alias_to' => (is => 'ro', isa => 'Str');
20 after 'install_accessors' => sub {
22 $self->associated_class->add_method(
24 $self->get_read_method_ref
28 package Moose::Meta::Attribute::Custom::Trait::Aliased;
29 sub register_implementation { 'My::Attribute::Trait' }
33 package My::Other::Attribute::Trait;
40 after 'install_accessors' => sub {
42 $self->associated_class->add_method(
48 package Moose::Meta::Attribute::Custom::Trait::Other;
49 sub register_implementation { 'My::Other::Attribute::Trait' }
57 traits => [qw/Aliased/],
65 package My::Derived::Class;
71 traits => [qw/Other/],
75 my $c = My::Class->new(bar => 100);
76 isa_ok($c, 'My::Class');
78 is($c->bar, 100, '... got the right value for bar');
81 is($c->baz, 100, '... got the right value for baz');
83 does_ok($c->meta->get_attribute('bar'), 'My::Attribute::Trait');
85 my $quux = My::Derived::Class->new(bar => 1000);
87 is($quux->bar, 1000, '... got the right value for bar');
90 is($quux->baz, 1000, '... got the right value for baz');
91 ok($quux->meta->get_attribute('bar')->does('My::Attribute::Trait'));
94 local $TODO = 'These do not pass - bug?';
96 skip 'no additional_method, so cannot test its value', 1 if !can_ok($quux, 'additional_method');
97 is($quux->additional_method, 42, '... got the right value for additional_method');
99 ok($quux->meta->get_attribute('bar')->does('My::Other::Attribute::Trait'));