adding in the ability to pass params to rebles when doing runtime roles
[gitmo/Moose.git] / t / 020_attributes / 015_attribute_traits.t
CommitLineData
d9bb6c63 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
3bb22459 6use Test::More tests => 6;
d9bb6c63 7use Test::Exception;
3bb22459 8use Test::Moose;
d9bb6c63 9
10BEGIN {
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
41my $c = My::Class->new(bar => 100);
42isa_ok($c, 'My::Class');
43
44is($c->bar, 100, '... got the right value for bar');
45
46can_ok($c, 'baz');
47is($c->baz, 100, '... got the right value for baz');
3bb22459 48
49does_ok($c->meta->get_attribute('bar'), 'My::Attribute::Trait');
50
51
52
53