Commit | Line | Data |
5d5c86d9 |
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 | |
5d5c86d9 |
41 | my $bar = Bar->new(); |
42 | isa_ok($bar, 'Bar'); |
08c29211 |
43 | isa_ok($bar, 'Foo'); |
44 | |
45 | SKIP: { |
46 | eval 'use Sub::Name'; |
47 | skip "Sub::Name is required for this test", 3 if $@; |
48 | |
49 | my $m = sub { (shift)->next::method() }; |
50 | Sub::Name::subname('Bar::bar', $m); |
51 | { |
52 | no strict 'refs'; |
53 | *{'Bar::bar'} = $m; |
54 | } |
55 | |
56 | can_ok($bar, 'bar'); |
57 | my $value = eval { $bar->bar() }; |
58 | ok(!$@, '... calling bar() succedded') || diag $@; |
59 | is($value, 'Foo::bar', '... got the right return value too'); |
60 | } |
5d5c86d9 |
61 | } |