9 if(eval{ require Class::Method::Modifiers::Fast } || eval{ require Class::Method::Modifiers }){
13 plan skip_all => 'This test requires Class::Method::Modifiers(::Fast)?';
22 package My::Attribute::Trait;
25 has 'alias_to' => (is => 'ro', isa => 'Str');
27 has foo => ( is => "ro", default => "blah" );
29 after 'install_accessors' => sub {
31 my $reader = $self->get_read_method;
33 $self->associated_class->add_method(
35 sub { shift->$reader(@_) },
45 traits => [qw/My::Attribute::Trait/],
58 my $c = My::Class->new(bar => 100);
59 isa_ok($c, 'My::Class');
61 is($c->bar, 100, '... got the right value for bar');
62 is($c->gorch, 10, '... got the right value for gorch');
65 is($c->baz, 100, '... got the right value for baz');
67 my $bar_attr = $c->meta->get_attribute('bar');
69 does_ok($bar_attr, 'My::Attribute::Trait');
70 ok($bar_attr->has_applied_traits, '... got the applied traits');
71 is_deeply($bar_attr->applied_traits, [qw/My::Attribute::Trait/], '... got the applied traits');
72 is($bar_attr->foo, "blah", "attr initialized");
74 my $gorch_attr = $c->meta->get_attribute('gorch');
75 ok(!$gorch_attr->does('My::Attribute::Trait'), '... gorch doesnt do the trait');
76 ok(!$gorch_attr->has_applied_traits, '... no traits applied');
77 is($gorch_attr->applied_traits, undef, '... no traits applied');