1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6require q(./test.pl); plan(tests => 7);
7
8{
9    package BaseTest;
10    use strict;
11    use warnings;
12    use mro 'c3';
13
14    package OverloadingTest;
15    use strict;
16    use warnings;
17    use mro 'c3';
18    use base 'BaseTest';
19    use overload '""' => sub { ref(shift) . " stringified" },
20                 fallback => 1;
21
22    sub new { bless {} => shift }
23
24    package InheritingFromOverloadedTest;
25    use strict;
26    use warnings;
27    use base 'OverloadingTest';
28    use mro 'c3';
29}
30
31my $x = InheritingFromOverloadedTest->new();
32object_ok($x, 'InheritingFromOverloadedTest');
33
34my $y = OverloadingTest->new();
35object_ok($y, 'OverloadingTest');
36
37is("$x", 'InheritingFromOverloadedTest stringified', '... got the right value when stringifing');
38is("$y", 'OverloadingTest stringified', '... got the right value when stringifing');
39
40ok(($y eq 'OverloadingTest stringified'), '... eq was handled correctly');
41
42my $result;
43eval {
44    $result = $x eq 'InheritingFromOverloadedTest stringified'
45};
46ok(!$@, '... this should not throw an exception');
47ok($result, '... and we should get the true value');
48