FileHandle also accepts IO::Handle objects
[gitmo/Moose.git] / t / 020_attributes / 015_attribute_traits.t
CommitLineData
d9bb6c63 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 5;
7use Test::Exception;
8
9BEGIN {
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
40my $c = My::Class->new(bar => 100);
41isa_ok($c, 'My::Class');
42
43is($c->bar, 100, '... got the right value for bar');
44
45can_ok($c, 'baz');
46is($c->baz, 100, '... got the right value for baz');