Import tests for attribute from Mouse's tests
[gitmo/Mouse.git] / t / 020_attributes / failing / 024_attribute_traits_parameterized.t
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use Test::More tests => 5;
5
6 {
7     package My::Attribute::Trait;
8     use Mouse::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 Mouse;
19
20     has foo => (
21         traits => [
22             'My::Attribute::Trait' => {
23                 -alias => {
24                     reversed_name => 'eman',
25                 },
26             },
27         ],
28         is => 'bare',
29     );
30 }
31
32 {
33     package My::Other::Class;
34     use Mouse;
35
36     has foo => (
37         traits => [
38             'My::Attribute::Trait' => {
39                 -alias => {
40                     reversed_name => 'reversed',
41                 },
42                 -excludes => 'reversed_name',
43             },
44         ],
45         is => 'bare',
46     );
47 }
48
49 my $attr = My::Class->meta->get_attribute('foo');
50 is($attr->eman, 'oof', 'the aliased method is in the attribute');
51 ok(!$attr->can('reversed'), "the method was not installed under the other class' alias");
52
53 my $other_attr = My::Other::Class->meta->get_attribute('foo');
54 is($other_attr->reversed, 'oof', 'the aliased method is in the attribute');
55 ok(!$other_attr->can('enam'), "the method was not installed under the other class' alias");
56 ok(!$other_attr->can('reversed_name'), "the method was not installed under the original name when that was excluded");
57