This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Optimise mro_get_linear_isa_c3() when there is a single parent. 40% speed up.
[perl5.git] / t / mro / c3_with_overload.t
CommitLineData
e1a479c5
BB
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
5f5ae4a7 6require q(./test.pl); plan(tests => 7);
e1a479c5
BB
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();
32isa_ok($x, 'InheritingFromOverloadedTest');
33
34my $y = OverloadingTest->new();
35isa_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');