1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#!./perl
# Test || in weird situations.
BEGIN {
chdir 't' if -d 't';
@INC = '../lib';
}
package Countdown;
sub TIESCALAR {
my $class = shift;
my $instance = shift || undef;
return bless \$instance => $class;
}
sub FETCH {
print "# FETCH! ${$_[0]}\n";
return ${$_[0]}--;
}
package main;
require './test.pl';
plan( tests => 8 );
my ($a, $b, $c);
$! = 1;
$a = $!;
my $a_str = sprintf "%s", $a;
my $a_num = sprintf "%d", $a;
$c = $a || $b;
is($c, $a_str);
is($c+0, $a_num); # force numeric context.
$a =~ /./g or die "Match failed for some reason"; # Make $a magic
$c = $a || $b;
is($c, $a_str);
is($c+0, $a_num); # force numeric context.
my $val = 3;
$c = $val || $b;
is($c, 3);
tie $a, 'Countdown', $val;
$c = $a;
is($c, 3, 'Single FETCH on tied scalar');
$c = $a;
is($c, 2, ' $tied = $var');
$c = $a || $b;
{
local $TODO = 'Double FETCH';
is($c, 1, ' $tied || $var');
}
|