Commit | Line | Data |
5d5c86d9 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
ef29cd70 |
6 | use Test::More tests => 11; |
5d5c86d9 |
7 | |
8 | { |
9 | |
10 | { |
11 | package Foo; |
12 | use strict; |
13 | use warnings; |
14 | use Class::C3; |
15 | sub new { bless {}, $_[0] } |
16 | sub bar { 'Foo::bar' } |
17 | } |
18 | |
19 | # call the submethod in the direct instance |
20 | |
21 | my $foo = Foo->new(); |
22 | isa_ok($foo, 'Foo'); |
23 | |
24 | can_ok($foo, 'bar'); |
25 | is($foo->bar(), 'Foo::bar', '... got the right return value'); |
26 | |
27 | # fail calling it from a subclass |
28 | |
29 | { |
30 | package Bar; |
31 | use strict; |
32 | use warnings; |
33 | use Class::C3; |
34 | our @ISA = ('Foo'); |
2ffffc6d |
35 | } |
5d5c86d9 |
36 | |
5d5c86d9 |
37 | my $bar = Bar->new(); |
38 | isa_ok($bar, 'Bar'); |
08c29211 |
39 | isa_ok($bar, 'Foo'); |
40 | |
2ffffc6d |
41 | # test it working with with Sub::Name |
08c29211 |
42 | SKIP: { |
43 | eval 'use Sub::Name'; |
44 | skip "Sub::Name is required for this test", 3 if $@; |
45 | |
46 | my $m = sub { (shift)->next::method() }; |
47 | Sub::Name::subname('Bar::bar', $m); |
48 | { |
49 | no strict 'refs'; |
50 | *{'Bar::bar'} = $m; |
51 | } |
52 | |
2ffffc6d |
53 | Class::C3::initialize(); |
54 | |
08c29211 |
55 | can_ok($bar, 'bar'); |
56 | my $value = eval { $bar->bar() }; |
57 | ok(!$@, '... calling bar() succedded') || diag $@; |
58 | is($value, 'Foo::bar', '... got the right return value too'); |
59 | } |
2ffffc6d |
60 | |
61 | # test it failing without Sub::Name |
62 | { |
63 | package Baz; |
64 | use strict; |
65 | use warnings; |
66 | use Class::C3; |
67 | our @ISA = ('Foo'); |
68 | } |
69 | |
70 | my $baz = Baz->new(); |
71 | isa_ok($baz, 'Baz'); |
72 | isa_ok($baz, 'Foo'); |
73 | |
74 | { |
75 | my $m = sub { (shift)->next::method() }; |
76 | { |
77 | no strict 'refs'; |
78 | *{'Baz::bar'} = $m; |
79 | } |
80 | |
81 | Class::C3::initialize(); |
82 | |
83 | eval { $baz->bar() }; |
84 | ok($@, '... calling bar() with next::method failed') || diag $@; |
85 | } |
ef29cd70 |
86 | } |