11 package My::Attribute::Trait;
14 has 'alias_to' => (is => 'ro', isa => 'Str');
16 has foo => ( is => "ro", default => "blah" );
18 after 'install_accessors' => sub {
20 $self->associated_class->add_method(
22 $self->get_read_method_ref
32 traits => [qw/My::Attribute::Trait/],
45 my $c = My::Class->new(bar => 100);
46 isa_ok($c, 'My::Class');
48 is($c->bar, 100, '... got the right value for bar');
49 is($c->gorch, 10, '... got the right value for gorch');
52 is($c->baz, 100, '... got the right value for baz');
54 my $bar_attr = $c->meta->get_attribute('bar');
55 does_ok($bar_attr, 'My::Attribute::Trait');
56 ok($bar_attr->has_applied_traits, '... got the applied traits');
57 is_deeply($bar_attr->applied_traits, [qw/My::Attribute::Trait/], '... got the applied traits');
58 is($bar_attr->foo, "blah", "attr initialized");
60 my $gorch_attr = $c->meta->get_attribute('gorch');
61 ok(!$gorch_attr->does('My::Attribute::Trait'), '... gorch doesnt do the trait');
62 ok(!$gorch_attr->has_applied_traits, '... no traits applied');
63 is($gorch_attr->applied_traits, undef, '... no traits applied');