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