Commit | Line | Data |
a73f0dc7 |
1 | #!/usr/bin/env perl |
2 | use strict; |
3 | use warnings; |
48ee5dc5 |
4 | use Test::More tests => 4; |
a73f0dc7 |
5 | |
6 | { |
7 | package My::Attribute::Trait; |
8 | use Moose::Role; |
9 | |
10 | sub reversed_name { |
11 | my $self = shift; |
12 | scalar reverse $self->name; |
13 | } |
14 | } |
15 | |
16 | { |
17 | package My::Class; |
18 | use Moose; |
19 | |
20 | has foo => ( |
21 | traits => [ |
22 | 'My::Attribute::Trait' => { |
23 | alias => { |
24 | reversed_name => 'eman', |
25 | }, |
26 | }, |
27 | ], |
28 | ); |
147c4844 |
29 | } |
30 | |
31 | { |
32 | package My::Other::Class; |
33 | use Moose; |
a73f0dc7 |
34 | |
147c4844 |
35 | has foo => ( |
36 | traits => [ |
37 | 'My::Attribute::Trait' => { |
38 | alias => { |
39 | reversed_name => 'reversed', |
40 | }, |
41 | }, |
42 | ], |
43 | ); |
a73f0dc7 |
44 | } |
45 | |
46 | my $attr = My::Class->meta->get_attribute('foo'); |
47 | is($attr->eman, 'oof', 'the aliased method is in the attribute'); |
147c4844 |
48 | ok(!$attr->can('reversed'), "the method was not installed under the other class' alias"); |
49 | |
50 | my $other_attr = My::Other::Class->meta->get_attribute('foo'); |
51 | is($other_attr->reversed, 'oof', 'the aliased method is in the attribute'); |
147c4844 |
52 | ok(!$other_attr->can('enam'), "the method was not installed under the other class' alias"); |
a73f0dc7 |
53 | |