Commit | Line | Data |
a72478f2 |
1 | #!/usr/bin/perl |
fde8e43f |
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; |
a72478f2 |
5 | |
6 | use strict; |
7 | use warnings; |
8 | |
fde8e43f |
9 | use Test::More; |
10 | $TODO = q{Mouse is not yet completed}; |
a72478f2 |
11 | use Test::Exception; |
ad087d11 |
12 | use Test::Mouse; |
a72478f2 |
13 | |
4060c871 |
14 | |
a72478f2 |
15 | { |
16 | package My::Attribute::Trait; |
ad087d11 |
17 | use Mouse::Role; |
a72478f2 |
18 | |
19 | has 'alias_to' => (is => 'ro', isa => 'Str'); |
20 | |
21 | has foo => ( is => "ro", default => "blah" ); |
22 | |
23 | after 'install_accessors' => sub { |
24 | my $self = shift; |
25 | $self->associated_class->add_method( |
26 | $self->alias_to, |
27 | $self->get_read_method_ref |
28 | ); |
29 | }; |
30 | |
ad087d11 |
31 | package Mouse::Meta::Attribute::Custom::Trait::Aliased; |
a72478f2 |
32 | sub register_implementation { 'My::Attribute::Trait' } |
33 | } |
34 | |
35 | { |
36 | package My::Other::Attribute::Trait; |
ad087d11 |
37 | use Mouse::Role; |
a72478f2 |
38 | |
39 | my $method = sub { |
40 | 42; |
41 | }; |
42 | |
43 | has the_other_attr => ( isa => "Str", is => "rw", default => "oink" ); |
44 | |
45 | after 'install_accessors' => sub { |
46 | my $self = shift; |
47 | $self->associated_class->add_method( |
48 | 'additional_method', |
49 | $method |
50 | ); |
51 | }; |
52 | |
ad087d11 |
53 | package Mouse::Meta::Attribute::Custom::Trait::Other; |
a72478f2 |
54 | sub register_implementation { 'My::Other::Attribute::Trait' } |
55 | } |
56 | |
57 | { |
58 | package My::Class; |
ad087d11 |
59 | use Mouse; |
a72478f2 |
60 | |
61 | has 'bar' => ( |
62 | traits => [qw/Aliased/], |
63 | is => 'ro', |
64 | isa => 'Int', |
65 | alias_to => 'baz', |
66 | ); |
67 | } |
68 | |
69 | { |
70 | package My::Derived::Class; |
ad087d11 |
71 | use Mouse; |
a72478f2 |
72 | |
73 | extends 'My::Class'; |
74 | |
75 | has '+bar' => ( |
76 | traits => [qw/Other/], |
77 | ); |
78 | } |
79 | |
80 | my $c = My::Class->new(bar => 100); |
81 | isa_ok($c, 'My::Class'); |
82 | |
83 | is($c->bar, 100, '... got the right value for bar'); |
84 | |
85 | can_ok($c, 'baz') and |
86 | is($c->baz, 100, '... got the right value for baz'); |
87 | |
88 | my $bar_attr = $c->meta->get_attribute('bar'); |
89 | does_ok($bar_attr, 'My::Attribute::Trait'); |
90 | is($bar_attr->foo, "blah", "attr initialized"); |
91 | |
92 | ok(!$bar_attr->meta->does_role('Aliased'), "does_role ignores aliases for sanity"); |
4060c871 |
93 | ok($bar_attr->does('Aliased'), "attr->does uses aliases"); |
a72478f2 |
94 | ok(!$bar_attr->meta->does_role('Fictional'), "does_role returns false for nonexistent roles"); |
95 | ok(!$bar_attr->does('Fictional'), "attr->does returns false for nonexistent roles"); |
96 | |
97 | my $quux = My::Derived::Class->new(bar => 1000); |
98 | |
99 | is($quux->bar, 1000, '... got the right value for bar'); |
100 | |
101 | can_ok($quux, 'baz'); |
102 | is($quux->baz, 1000, '... got the right value for baz'); |
103 | |
104 | my $derived_bar_attr = $quux->meta->get_attribute("bar"); |
105 | does_ok($derived_bar_attr, 'My::Attribute::Trait' ); |
106 | |
107 | is( $derived_bar_attr->foo, "blah", "attr initialized" ); |
108 | |
109 | does_ok($derived_bar_attr, 'My::Other::Attribute::Trait' ); |
110 | |
111 | is($derived_bar_attr->the_other_attr, "oink", "attr initialized" ); |
112 | |
113 | ok(!$derived_bar_attr->meta->does_role('Aliased'), "does_role ignores aliases for sanity"); |
4060c871 |
114 | ok($derived_bar_attr->does('Aliased'), "attr->does uses aliases"); |
a72478f2 |
115 | ok(!$derived_bar_attr->meta->does_role('Fictional'), "does_role returns false for nonexistent roles"); |
116 | ok(!$derived_bar_attr->does('Fictional'), "attr->does returns false for nonexistent roles"); |
117 | |
118 | can_ok($quux, 'additional_method'); |
119 | is(eval { $quux->additional_method }, 42, '... got the right value for additional_method'); |
120 | |
fde8e43f |
121 | done_testing; |