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