7 use Test::More tests => 12;
15 package My::Attribute::Trait;
18 has 'alias_to' => (is => 'ro', isa => 'Str');
20 has foo => ( is => "ro", default => "blah" );
22 after 'install_accessors' => sub {
24 my $reader = $self->get_read_method;
26 $self->associated_class->add_method(
28 sub { shift->$reader(@_) },
38 traits => [qw/My::Attribute::Trait/],
51 my $c = My::Class->new(bar => 100);
52 isa_ok($c, 'My::Class');
54 is($c->bar, 100, '... got the right value for bar');
55 is($c->gorch, 10, '... got the right value for gorch');
58 is($c->baz, 100, '... got the right value for baz');
60 my $bar_attr = $c->meta->get_attribute('bar');
62 does_ok($bar_attr, 'My::Attribute::Trait');
63 ok($bar_attr->has_applied_traits, '... got the applied traits');
64 is_deeply($bar_attr->applied_traits, [qw/My::Attribute::Trait/], '... got the applied traits');
65 is($bar_attr->foo, "blah", "attr initialized");
67 my $gorch_attr = $c->meta->get_attribute('gorch');
68 ok(!$gorch_attr->does('My::Attribute::Trait'), '... gorch doesnt do the trait');
69 ok(!$gorch_attr->has_applied_traits, '... no traits applied');
70 is($gorch_attr->applied_traits, undef, '... no traits applied');