cleaning up the traits things
[gitmo/Moose.git] / t / 020_attributes / 016_attribute_traits_registered.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 6;
7 use Test::Exception;
8 use Test::Moose;
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     package Moose::Meta::Attribute::Custom::Trait::Aliased;
29     sub register_implementation { 'My::Attribute::Trait' }
30 }
31
32 {
33     package My::Class;
34     use Moose;
35     
36     has 'bar' => (
37         traits   => [qw/Aliased/],
38         is       => 'ro',
39         isa      => 'Int',
40         alias_to => 'baz',
41     );
42 }
43
44 my $c = My::Class->new(bar => 100);
45 isa_ok($c, 'My::Class');
46
47 is($c->bar, 100, '... got the right value for bar');
48
49 can_ok($c, 'baz');
50 is($c->baz, 100, '... got the right value for baz');
51
52 does_ok($c->meta->get_attribute('bar'), 'My::Attribute::Trait');