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