0e5e913552b571efffb4ef068bce5872677ce664
[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 use Sub::Name;
13
14 {
15
16     {
17         package Foo;
18         use strict;
19         use warnings;
20         use Class::C3;
21         sub new { bless {}, $_[0] }
22         sub bar { 'Foo::bar' }
23     }
24
25     # call the submethod in the direct instance
26
27     my $foo = Foo->new();
28     isa_ok($foo, 'Foo');
29
30     can_ok($foo, 'bar');
31     is($foo->bar(), 'Foo::bar', '... got the right return value');    
32
33     # fail calling it from a subclass
34
35     {
36         package Bar;
37         use strict;
38         use warnings;
39         use Class::C3;
40         our @ISA = ('Foo');
41     }
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 }