1use warnings; 2use strict; 3 4BEGIN { 5 chdir 't' if -d 't'; 6 @INC = '../lib'; 7 require './test.pl'; 8 plan(tests => 4); 9} 10 11use overload '""' => sub { 'stringvalue' }, fallback => 1; 12 13BEGIN { 14my $x = bless {}, 'main'; 15ok ($x eq 'stringvalue', 'fallback worked'); 16} 17 18 19# NOTE: delete the next line and this test script will pass 20use overload '+' => sub { die "unused"; }; 21 22my $x = bless {}, 'main'; 23ok (eval {$x eq 'stringvalue'}, 'fallback worked again'); 24 25TODO: { 26 local $::TODO = 'RT #43356: Autogeneration of ++ is incorrect'; 27 fresh_perl_is(<<'EOC', '2', {}, 'RT #43356: Autogeneration of ++'); 28use overload 29 "0+" => sub { ${$_[0]} }, 30 "=" => sub { ${$_[0]} }, 31 fallback => 1; 32my $value = bless \(my $dummy = 1), __PACKAGE__; 33print ++$value; 34EOC 35} 36 37{ 38 my $warned = 0; 39 local $SIG{__WARN__} = sub { $warned++; }; 40 41 eval q{ 42 use overload '${}', 'fallback'; 43 no overload '${}', 'fallback'; 44 }; 45 46 ok($warned == 0, 'no overload should not warn'); 47} 48 49