1#!./perl 2 3use strict; 4use warnings; 5BEGIN { 6 unless (-d 'blib') { 7 chdir 't' if -d 't'; 8 @INC = '../lib'; 9 } 10} 11 12require q(./test.pl); plan(tests => 7); 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 37my $x = InheritingFromOverloadedTest->new(); 38object_ok($x, 'InheritingFromOverloadedTest'); 39 40my $y = OverloadingTest->new(); 41object_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 55