Commit | Line | Data |
680100b1 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
030b48e2 |
6 | use Test::More tests => 9; |
680100b1 |
7 | |
8 | BEGIN { |
9 | use_ok('Class::C3'); |
10 | } |
11 | |
12 | { |
13 | package BaseTest; |
14 | use strict; |
15 | use warnings; |
16 | use Class::C3; |
17 | |
18 | package OverloadingTest; |
19 | use strict; |
20 | use warnings; |
21 | use Class::C3; |
22 | use base 'BaseTest'; |
23 | use overload '""' => sub { ref(shift) . " stringified" }, |
24 | fallback => 1; |
25 | |
26 | sub new { bless {} => shift } |
27 | |
28 | package InheritingFromOverloadedTest; |
29 | use strict; |
30 | use warnings; |
31 | use base 'OverloadingTest'; |
32 | use Class::C3; |
030b48e2 |
33 | |
34 | package BaseTwo; |
35 | use overload ( |
36 | q{fallback} => 1, |
37 | q{""} => 'str', ### character |
38 | ); |
39 | sub str { |
40 | return 'BaseTwo str'; |
41 | } |
42 | |
43 | package OverloadInheritTwo; |
44 | use Class::C3; |
45 | use base qw/BaseTwo/; |
46 | |
680100b1 |
47 | } |
48 | |
2ffffc6d |
49 | Class::C3::initialize(); |
50 | |
680100b1 |
51 | my $x = InheritingFromOverloadedTest->new(); |
52 | isa_ok($x, 'InheritingFromOverloadedTest'); |
53 | |
54 | my $y = OverloadingTest->new(); |
55 | isa_ok($y, 'OverloadingTest'); |
56 | |
57 | is("$x", 'InheritingFromOverloadedTest stringified', '... got the right value when stringifing'); |
58 | is("$y", 'OverloadingTest stringified', '... got the right value when stringifing'); |
59 | |
60 | ok(($y eq 'OverloadingTest stringified'), '... eq was handled correctly'); |
61 | |
62 | my $result; |
63 | eval { |
64 | $result = $x eq 'InheritingFromOverloadedTest stringified' |
65 | }; |
66 | ok(!$@, '... this should not throw an exception'); |
67 | ok($result, '... and we should get the true value'); |
68 | |
030b48e2 |
69 | eval { |
70 | my $obj = bless {}, 'OverloadInheritTwo'; |
71 | }; |
72 | is($@, '', "Overloading to method name string"); |
73 | |
680100b1 |
74 | #use Data::Dumper; |
75 | #diag Dumper { Class::C3::_dump_MRO_table } |