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;
10 $TODO = q{Mouse is not yet completed};
12 use Scalar::Util qw(blessed);
17 This test can be used as a basis for the runtime role composition.
18 Apparently it is not as simple as just making an anon class. One of
19 the problems is the way that anon classes are DESTROY-ed, which is
20 not very compatible with how instances are dealt with.
39 sub sleep { 'nite-nite' }
42 my $obj = My::Class->new;
43 isa_ok($obj, 'My::Class');
45 my $obj2 = My::Class->new;
46 isa_ok($obj2, 'My::Class');
49 ok(!$obj->can( 'talk' ), "... the role is not composed yet");
51 ok(!$obj->does('Bark'), '... we do not do any roles yet');
53 Bark->meta->apply($obj);
55 ok($obj->does('Bark'), '... we now do the Bark role');
56 ok(!My::Class->does('Bark'), '... the class does not do the Bark role');
58 isa_ok($obj, 'My::Class');
59 isnt(blessed($obj), 'My::Class', '... but it is no longer blessed into My::Class');
61 ok(!My::Class->can('talk'), "... the role is not composed at the class level");
62 ok($obj->can('talk'), "... the role is now composed at the object level");
64 is($obj->talk, 'woof', '... got the right return value for the newly composed method');
68 ok(!$obj2->does('Sleeper'), '... we do not do any roles yet');
70 Sleeper->meta->apply($obj2);
72 ok($obj2->does('Sleeper'), '... we now do the Sleeper role');
73 isnt(blessed($obj), blessed($obj2), '... they DO NOT share the same anon-class/role thing');
77 is($obj->sleep, 'nite-nite', '... the original method responds as expected');
79 ok(!$obj->does('Sleeper'), '... we do not do the Sleeper role');
81 Sleeper->meta->apply($obj);
83 ok($obj->does('Bark'), '... we still do the Bark role');
84 ok($obj->does('Sleeper'), '... we now do the Sleeper role too');
86 ok(!My::Class->does('Sleeper'), '... the class does not do the Sleeper role');
88 isnt(blessed($obj), blessed($obj2), '... they still don\'t share the same anon-class/role thing');
90 isa_ok($obj, 'My::Class');
92 is(My::Class->sleep, 'nite-nite', '... the original method still responds as expected');
94 is($obj->sleep, 'snore', '... got the right return value for the newly composed method');
95 is($obj->talk, 'zzz', '... got the right return value for the newly composed method');
99 ok(!$obj2->does('Bark'), '... we do not do Bark yet');
101 Bark->meta->apply($obj2);
103 ok($obj2->does('Bark'), '... we now do the Bark role');
104 isnt(blessed($obj), blessed($obj2), '... they still don\'t share the same anon-class/role thing');
107 # test that anon classes are equivalent after role composition in the same order
109 foreach ($obj, $obj2) {
111 Bark->meta->apply($_);
112 Sleeper->meta->apply($_);
114 is(blessed($obj), blessed($obj2), '... they now share the same anon-class/role thing');