[perl #76814] FETCH called twice - ||
authorFather Chrysostomos <sprout@cpan.org>
Sun, 27 Feb 2011 08:50:08 +0000 (00:50 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 27 Feb 2011 08:50:08 +0000 (00:50 -0800)
The || case in t/op/tie_fetch_count.t is not a bug, as there are two
separate operators operating on it in the test script. In

  $dummy = $x || $y

The || does mg_get($x). If it’s true it returns it and the = does
mg_get($x). If $x is false, then $y is returned, so magic is called
once on each of $x and $y. Similarly, && will seemingly call
mg_get($x) twice if $x is false.

If you just write:

  $x || $y

then magic is only called once on $x.

This patch corrects the test.

t/op/tie_fetch_count.t

index a5e652e..6e93452 100644 (file)
@@ -13,8 +13,6 @@ BEGIN {
 use strict;
 use warnings;
 
-my $TODO = "Bug 76814";
-
 my $count = 0;
 
 sub TIESCALAR {bless \do {my $var = $_ [1]} => $_ [0];}
@@ -84,11 +82,9 @@ $dummy  = ~$var         ; check_count '~';
 
 # Logical operators
 $dummy  = !$var         ; check_count '!';
-TODO: {
-    local $::TODO = $TODO;
-    $dummy  =  $var  ||   1 ; check_count '||';
-    $dummy  = ($var  or   1); check_count 'or';
-}
+tie my $v_1, "main", 0;
+$dummy  =  $v_1  ||   1 ; check_count '||';
+$dummy  = ($v_1  or   1); check_count 'or';
 $dummy  =  $var  &&   1 ; check_count '&&';
 $dummy  = ($var and   1); check_count 'and';
 $dummy  = ($var xor   1); check_count 'xor';