Commit | Line | Data |
d9bb6c63 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
3bb22459 |
6 | use Test::More tests => 6; |
d9bb6c63 |
7 | use Test::Exception; |
3bb22459 |
8 | use Test::Moose; |
d9bb6c63 |
9 | |
10 | BEGIN { |
11 | use_ok('Moose'); |
12 | } |
13 | |
14 | { |
15 | package My::Attribute::Trait; |
16 | use Moose::Role; |
17 | |
18 | has 'alias_to' => (is => 'ro', isa => 'Str'); |
19 | |
20 | after 'install_accessors' => sub { |
21 | my $self = shift; |
22 | $self->associated_class->add_method( |
23 | $self->alias_to, |
24 | $self->get_read_method_ref |
25 | ); |
26 | }; |
27 | } |
28 | |
29 | { |
30 | package My::Class; |
31 | use Moose; |
32 | |
33 | has 'bar' => ( |
34 | traits => [qw/My::Attribute::Trait/], |
35 | is => 'ro', |
36 | isa => 'Int', |
37 | alias_to => 'baz', |
38 | ); |
39 | } |
40 | |
41 | my $c = My::Class->new(bar => 100); |
42 | isa_ok($c, 'My::Class'); |
43 | |
44 | is($c->bar, 100, '... got the right value for bar'); |
45 | |
46 | can_ok($c, 'baz'); |
47 | is($c->baz, 100, '... got the right value for baz'); |
3bb22459 |
48 | |
49 | does_ok($c->meta->get_attribute('bar'), 'My::Attribute::Trait'); |
50 | |
51 | |
52 | |
53 | |