This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix NAME of perl5125delta.pod
[perl5.git] / t / mro / overload_c3.t
1 #!./perl
2
3 use strict;
4 use warnings;
5 BEGIN {
6     unless (-d 'blib') {
7         chdir 't' if -d 't';
8         @INC = '../lib';
9     }
10 }
11
12 require q(./test.pl); plan(tests => 7);
13
14 {
15     package BaseTest;
16     use strict;
17     use warnings;
18     use mro 'c3';
19     
20     package OverloadingTest;
21     use strict;
22     use warnings;
23     use mro 'c3';
24     use base 'BaseTest';        
25     use overload '""' => sub { ref(shift) . " stringified" },
26                  fallback => 1;
27     
28     sub new { bless {} => shift }    
29     
30     package InheritingFromOverloadedTest;
31     use strict;
32     use warnings;
33     use base 'OverloadingTest';
34     use mro 'c3';
35 }
36
37 my $x = InheritingFromOverloadedTest->new();
38 object_ok($x, 'InheritingFromOverloadedTest');
39
40 my $y = OverloadingTest->new();
41 object_ok($y, 'OverloadingTest');
42
43 is("$x", 'InheritingFromOverloadedTest stringified', '... got the right value when stringifing');
44 is("$y", 'OverloadingTest stringified', '... got the right value when stringifing');
45
46 ok(($y eq 'OverloadingTest stringified'), '... eq was handled correctly');
47
48 my $result;
49 eval { 
50     $result = $x eq 'InheritingFromOverloadedTest stringified' 
51 };
52 ok(!$@, '... this should not throw an exception');
53 ok($result, '... and we should get the true value');
54