diff options
-rw-r--r-- | t/op/tie.t | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/t/op/tie.t b/t/op/tie.t index bd3f2e50f7..5db6cfb859 100644 --- a/t/op/tie.t +++ b/t/op/tie.t @@ -790,3 +790,98 @@ my $x = $a[0] + $h{foo} + $a[$i] + (@a)[0]; print "x=$x c=$c\n"; EXPECT x=0 c=4 +######## +# Bug 68192 - numeric ops not calling mg_get when tied scalar holds a ref +sub TIESCALAR { bless {}, __PACKAGE__ }; +sub STORE {}; +sub FETCH { + print "fetching... "; # make sure FETCH is called once per op + 123456 +}; +my $foo; +tie $foo, __PACKAGE__; +my $a = [1234567]; +$foo = $a; +print "+ ", 0 + $foo, "\n"; +print "** ", $foo**1, "\n"; +print "* ", $foo*1, "\n"; +print "/ ", $foo*1, "\n"; +print "% ", $foo%123457, "\n"; +print "- ", $foo-0, "\n"; +print "neg ", - -$foo, "\n"; +print "int ", int $foo, "\n"; +print "abs ", abs $foo, "\n"; +print "== ", 123456 == $foo, "\n"; +print "< ", 123455 < $foo, "\n"; +print "> ", 123457 > $foo, "\n"; +print "<= ", 123456 <= $foo, "\n"; +print ">= ", 123456 >= $foo, "\n"; +print "!= ", 0 != $foo, "\n"; +print "<=> ", 123457 <=> $foo, "\n"; +EXPECT +fetching... + 123456 +fetching... ** 123456 +fetching... * 123456 +fetching... / 123456 +fetching... % 123456 +fetching... - 123456 +fetching... neg 123456 +fetching... int 123456 +fetching... abs 123456 +fetching... == 1 +fetching... < 1 +fetching... > 1 +fetching... <= 1 +fetching... >= 1 +fetching... != 1 +fetching... <=> 1 +######## +# Ties returning overloaded objects +{ + package overloaded; + use overload + map { + my $op = $_; + $_ => sub { print "$op"; 100 } + } qw< 0+ "" + ** * / % - neg int abs == < > <= >= != <=> > +} +$o = bless [], overloaded; + +sub TIESCALAR { bless {}, "" } +sub FETCH { print "fetching... "; $o } +sub STORE{} +tie $ghew, ""; + +$ghew=undef; 1+$ghew; print "\n"; +$ghew=undef; $ghew**1; print "\n"; +$ghew=undef; $ghew*1; print "\n"; +$ghew=undef; $ghew/1; print "\n"; +$ghew=undef; $ghew%1; print "\n"; +$ghew=undef; $ghew-1; print "\n"; +$ghew=undef; -$ghew; print "\n"; +$ghew=undef; int $ghew; print "\n"; +$ghew=undef; abs $ghew; print "\n"; +$ghew=undef; 1 == $ghew; print "\n"; +$ghew=undef; $ghew<1; print "\n"; +$ghew=undef; $ghew>1; print "\n"; +$ghew=undef; $ghew<=1; print "\n"; +$ghew=undef; $ghew >=1; print "\n"; +$ghew=undef; $ghew != 1; print "\n"; +$ghew=undef; $ghew<=>1; print "\n"; +EXPECT +fetching... + +fetching... ** +fetching... * +fetching... / +fetching... % +fetching... - +fetching... neg +fetching... int +fetching... abs +fetching... == +fetching... < +fetching... > +fetching... <= +fetching... >= +fetching... != +fetching... <=> |