This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update Encode to CPAN version 2.78
[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();
bbce3ca6 32object_ok($x, 'InheritingFromOverloadedTest');
e1a479c5
BB
33
34my $y = OverloadingTest->new();
bbce3ca6 35object_ok($y, 'OverloadingTest');
e1a479c5
BB
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');