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;
7 $TODO = q{Mouse is not yet completed};
12 package CustomApplication;
15 after apply_methods => sub {
16 my ( $self, $role, $other ) = @_;
17 $self->apply_custom( $role, $other );
22 push @applications, [@_];
27 package CustomApplication::ToClass;
30 with 'CustomApplication';
34 package CustomApplication::ToRole;
37 with 'CustomApplication';
41 package CustomApplication::ToInstance;
44 with 'CustomApplication';
48 package CustomApplication::Composite;
51 with 'CustomApplication';
53 around apply_custom => sub {
54 my ( $next, $self, $composite, $other ) = @_;
55 for my $role ( @{ $composite->get_roles } ) {
56 $self->$next( $role, $other );
62 package CustomApplication::Composite::ToClass;
65 with 'CustomApplication::Composite';
69 package CustomApplication::Composite::ToRole;
72 with 'CustomApplication::Composite';
76 package CustomApplication::Composite::ToInstance;
79 with 'CustomApplication::Composite';
83 package Role::Composite;
86 around apply_params => sub {
87 my ( $next, $self, @args ) = @_;
88 return Mouse::Util::MetaRole::apply_metaroles(
89 for => $self->$next(@args),
91 application_to_class =>
92 ['CustomApplication::Composite::ToClass'],
93 application_to_role =>
94 ['CustomApplication::Composite::ToRole'],
95 application_to_instance =>
96 ['CustomApplication::Composite::ToInstance'],
103 package Role::WithCustomApplication;
106 around composition_class_roles => sub {
107 my ($orig, $self) = @_;
108 return $self->$orig, 'Role::Composite';
114 Mouse::Exporter->setup_import_methods(
115 also => 'Mouse::Role',
119 my ( $self, %options ) = @_;
120 return Mouse::Util::MetaRole::apply_metaroles(
121 for => Mouse::Role->init_meta(%options),
123 role => ['Role::WithCustomApplication'],
124 application_to_class =>
125 ['CustomApplication::ToClass'],
126 application_to_role => ['CustomApplication::ToRole'],
127 application_to_instance =>
128 ['CustomApplication::ToInstance'],
135 package My::Role::Normal;
140 package My::Role::Special;
144 ok( My::Role::Normal->meta->isa('Mouse::Meta::Role'), "sanity check" );
145 ok( My::Role::Special->meta->isa('Mouse::Meta::Role'),
146 "using custom application roles does not change the role metaobject's class"
148 ok( My::Role::Special->meta->meta->does_role('Role::WithCustomApplication'),
149 "the role's metaobject has custom applications" );
150 is_deeply( [My::Role::Special->meta->composition_class_roles],
152 "the role knows about the specified composition class" );
159 with 'My::Role::Special';
161 ::is( @applications, 1, 'one role application' );
162 ::is( $applications[0]->[0]->name, 'My::Role::Special',
163 "the application's first role was My::Role::Special'" );
164 ::is( $applications[0]->[1]->name, 'Foo',
165 "the application provided an additional role" );
173 with 'My::Role::Special';
175 ::is( @applications, 1 );
176 ::is( $applications[0]->[0]->name, 'My::Role::Special' );
177 ::is( $applications[0]->[1]->name, 'Bar' );
186 My::Role::Special->meta->apply($i);
188 ::is( @applications, 1 );
189 ::is( $applications[0]->[0]->name, 'My::Role::Special' );
190 ::ok( $applications[0]->[1]->is_anon_class );
191 ::ok( $applications[0]->[1]->name->isa('Baz') );
199 with 'My::Role::Normal', 'My::Role::Special';
201 ::is( @applications, 2 );
202 ::is( $applications[0]->[0]->name, 'My::Role::Normal' );
203 ::is( $applications[0]->[1]->name, 'Corge' );
204 ::is( $applications[1]->[0]->name, 'My::Role::Special' );
205 ::is( $applications[1]->[1]->name, 'Corge' );
213 with 'My::Role::Normal', 'My::Role::Special';
215 ::is( @applications, 2 );
216 ::is( $applications[0]->[0]->name, 'My::Role::Normal' );
217 ::is( $applications[0]->[1]->name, 'Thud' );
218 ::is( $applications[1]->[0]->name, 'My::Role::Special' );
219 ::is( $applications[1]->[1]->name, 'Thud' );
228 Mouse::Meta::Role->combine(
229 [ 'My::Role::Normal' => undef ],
230 [ 'My::Role::Special' => undef ],
233 ::is( @applications, 2 );
234 ::is( $applications[0]->[0]->name, 'My::Role::Normal' );
235 ::ok( $applications[0]->[1]->is_anon_class );
236 ::ok( $applications[0]->[1]->name->isa('Garply') );
237 ::is( $applications[1]->[0]->name, 'My::Role::Special' );
238 ::ok( $applications[1]->[1]->is_anon_class );
239 ::ok( $applications[1]->[1]->name->isa('Garply') );