Mouse::Util::does_role() respects $thing->does() method
[gitmo/Mouse.git] / t / 100_bugs / 009_augment_recursion_bug.t
1 #!/usr/bin/perl
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;
5
6 use strict;
7 use warnings;
8
9 use Test::More;
10
11
12 {
13     package Foo;
14     use Mouse;
15
16     sub foo { 'Foo::foo(' . (inner() || '') . ')' };
17
18     package Bar;
19     use Mouse;
20
21     extends 'Foo';
22
23     package Baz;
24     use Mouse;
25
26     extends 'Foo';
27
28     my $foo_call_counter;
29     augment 'foo' => sub {
30         die "infinite loop on Baz::foo" if $foo_call_counter++ > 1;
31         return 'Baz::foo and ' . Bar->new->foo;
32     };
33 }
34
35 my $baz = Baz->new();
36 isa_ok($baz, 'Baz');
37 isa_ok($baz, 'Foo');
38
39 =pod
40
41 When a subclass which augments foo(), calls a subclass which does not augment
42 foo(), there is a chance for some confusion. If Mouse does not realize that
43 Bar does not augment foo(), because it is in the call flow of Baz which does,
44 then we may have an infinite loop.
45
46 =cut
47
48 is($baz->foo,
49   'Foo::foo(Baz::foo and Foo::foo())',
50   '... got the right value for 1 augmented subclass calling non-augmented subclass');
51
52 done_testing;