Commit | Line | Data |
e1a479c5 |
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 | |
5f5ae4a7 |
12 | require q(./test.pl); plan(tests => 7); |
e1a479c5 |
13 | |
14 | { |
15 | package BaseTest; |
16 | use strict; |
17 | use warnings; |
18 | use mro 'dfs'; |
19 | |
20 | package OverloadingTest; |
21 | use strict; |
22 | use warnings; |
23 | use mro 'dfs'; |
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 'dfs'; |
35 | } |
36 | |
37 | my $x = InheritingFromOverloadedTest->new(); |
38 | isa_ok($x, 'InheritingFromOverloadedTest'); |
39 | |
40 | my $y = OverloadingTest->new(); |
41 | isa_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 | |