4f85e74dd0d464bd0748bf70198aa652758642cb
[gitmo/Class-C3.git] / t / 32_next_method_edge_cases.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 9;
7
8 BEGIN {   
9     use_ok('Class::C3');
10 }
11
12 {
13
14     {
15         package Foo;
16         use strict;
17         use warnings;
18         use Class::C3;
19         sub new { bless {}, $_[0] }
20         sub bar { 'Foo::bar' }
21     }
22
23     # call the submethod in the direct instance
24
25     my $foo = Foo->new();
26     isa_ok($foo, 'Foo');
27
28     can_ok($foo, 'bar');
29     is($foo->bar(), 'Foo::bar', '... got the right return value');    
30
31     # fail calling it from a subclass
32
33     {
34         package Bar;
35         use strict;
36         use warnings;
37         use Class::C3;
38         our @ISA = ('Foo');
39     }
40     
41     use Sub::Name;
42     
43     my $m = sub { (shift)->next::method() };
44     subname('Bar::bar', $m);
45     {
46         no strict 'refs';
47         *{'Bar::bar'} = $m;
48     }
49
50     my $bar = Bar->new();
51     isa_ok($bar, 'Bar');
52     isa_ok($bar, 'Foo');
53
54     can_ok($bar, 'bar');
55     my $value = eval { $bar->bar() };
56     ok(!$@, '... calling bar() succedded') || diag $@;
57     is($value, 'Foo::bar', '... got the right return value too');
58 }