This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Revert change #31489.
[perl5.git] / t / mro / c3_with_overload.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 require 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
31 my $x = InheritingFromOverloadedTest->new();
32 isa_ok($x, 'InheritingFromOverloadedTest');
33
34 my $y = OverloadingTest->new();
35 isa_ok($y, 'OverloadingTest');
36
37 is("$x", 'InheritingFromOverloadedTest stringified', '... got the right value when stringifing');
38 is("$y", 'OverloadingTest stringified', '... got the right value when stringifing');
39
40 ok(($y eq 'OverloadingTest stringified'), '... eq was handled correctly');
41
42 my $result;
43 eval { 
44     $result = $x eq 'InheritingFromOverloadedTest stringified' 
45 };
46 ok(!$@, '... this should not throw an exception');
47 ok($result, '... and we should get the true value');