Commit | Line | Data |
85a83bed |
1 | #!/usr/bin/perl |
1f5ce14a |
2 | # This is automatically generated by author/import-moose-test.pl. |
3 | # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! |
4 | use t::lib::MooseCompat; |
85a83bed |
5 | |
6 | use strict; |
7 | use warnings; |
8 | |
1f5ce14a |
9 | use Test::More; |
85a83bed |
10 | use Test::Exception; |
11 | use Test::Mouse; |
12 | |
73e9153a |
13 | |
85a83bed |
14 | { |
15 | package My::Attribute::Trait; |
16 | use Mouse::Role; |
17 | |
18 | has 'alias_to' => (is => 'ro', isa => 'Str'); |
19 | |
20 | has foo => ( is => "ro", default => "blah" ); |
21 | |
22 | after 'install_accessors' => sub { |
23 | my $self = shift; |
85a83bed |
24 | $self->associated_class->add_method( |
25 | $self->alias_to, |
4060c871 |
26 | $self->get_read_method_ref |
85a83bed |
27 | ); |
28 | }; |
29 | } |
30 | |
31 | { |
32 | package My::Class; |
33 | use Mouse; |
34 | |
35 | has 'bar' => ( |
36 | traits => [qw/My::Attribute::Trait/], |
37 | is => 'ro', |
38 | isa => 'Int', |
39 | alias_to => 'baz', |
40 | ); |
41 | |
42 | has 'gorch' => ( |
43 | is => 'ro', |
44 | isa => 'Int', |
45 | default => sub { 10 } |
46 | ); |
47 | } |
48 | |
49 | my $c = My::Class->new(bar => 100); |
50 | isa_ok($c, 'My::Class'); |
51 | |
52 | is($c->bar, 100, '... got the right value for bar'); |
53 | is($c->gorch, 10, '... got the right value for gorch'); |
54 | |
55 | can_ok($c, 'baz'); |
56 | is($c->baz, 100, '... got the right value for baz'); |
57 | |
58 | my $bar_attr = $c->meta->get_attribute('bar'); |
85a83bed |
59 | does_ok($bar_attr, 'My::Attribute::Trait'); |
60 | ok($bar_attr->has_applied_traits, '... got the applied traits'); |
61 | is_deeply($bar_attr->applied_traits, [qw/My::Attribute::Trait/], '... got the applied traits'); |
62 | is($bar_attr->foo, "blah", "attr initialized"); |
63 | |
64 | my $gorch_attr = $c->meta->get_attribute('gorch'); |
65 | ok(!$gorch_attr->does('My::Attribute::Trait'), '... gorch doesnt do the trait'); |
66 | ok(!$gorch_attr->has_applied_traits, '... no traits applied'); |
67 | is($gorch_attr->applied_traits, undef, '... no traits applied'); |
68 | |
1f5ce14a |
69 | done_testing; |