Class::C3 - 0.07 release;
[gitmo/Class-C3.git] / t / 32_next_method_edge_cases.t
CommitLineData
5d5c86d9 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 9;
7
8BEGIN {
9 use_ok('Class::C3');
10}
11
4e47d2a4 12use Sub::Name;
13
5d5c86d9 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
5d5c86d9 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}