This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
OS2-Process/Process.pm: Fix broken pod links
[perl5.git] / t / mro / overload_c3.t
CommitLineData
e1a479c5
BB
1#!./perl
2
3use strict;
4use warnings;
5BEGIN {
6 unless (-d 'blib') {
7 chdir 't' if -d 't';
8 @INC = '../lib';
9 }
10}
11
5f5ae4a7 12require q(./test.pl); plan(tests => 7);
e1a479c5
BB
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
37my $x = InheritingFromOverloadedTest->new();
38isa_ok($x, 'InheritingFromOverloadedTest');
39
40my $y = OverloadingTest->new();
41isa_ok($y, 'OverloadingTest');
42
43is("$x", 'InheritingFromOverloadedTest stringified', '... got the right value when stringifing');
44is("$y", 'OverloadingTest stringified', '... got the right value when stringifing');
45
46ok(($y eq 'OverloadingTest stringified'), '... eq was handled correctly');
47
48my $result;
49eval {
50 $result = $x eq 'InheritingFromOverloadedTest stringified'
51};
52ok(!$@, '... this should not throw an exception');
53ok($result, '... and we should get the true value');
54