Commit | Line | Data |
7a6a85bf |
1 | #!./perl |
7a6a85bf |
2 | # |
3 | # Copyright (c) 1995-2000, Raphael Manfredi |
4 | # |
9e21b3d0 |
5 | # You may redistribute only under the same terms as Perl 5, as specified |
6 | # in the README file that comes with the distribution. |
7a6a85bf |
7 | # |
7a6a85bf |
8 | |
9 | # |
10 | # Tests ref to items in tied hash/array structures. |
11 | # |
12 | |
13 | sub BEGIN { |
0c384302 |
14 | if ($ENV{PERL_CORE}){ |
15 | chdir('t') if -d 't'; |
7dadce44 |
16 | @INC = ('.', '../lib', '../ext/Storable/t'); |
372cb964 |
17 | } else { |
18 | unshift @INC, 't'; |
0c384302 |
19 | } |
9f233367 |
20 | require Config; import Config; |
0c384302 |
21 | if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) { |
9f233367 |
22 | print "1..0 # Skip: Storable was not built\n"; |
23 | exit 0; |
24 | } |
372cb964 |
25 | require 'st-dump.pl'; |
7a6a85bf |
26 | } |
27 | |
28 | sub ok; |
29 | $^W = 0; |
30 | |
31 | print "1..8\n"; |
32 | |
33 | use Storable qw(dclone); |
34 | |
35 | $h_fetches = 0; |
36 | |
37 | sub H::TIEHASH { bless \(my $x), "H" } |
38 | sub H::FETCH { $h_fetches++; $_[1] - 70 } |
39 | |
40 | tie %h, "H"; |
41 | |
42 | $ref = \$h{77}; |
43 | $ref2 = dclone $ref; |
44 | |
45 | ok 1, $h_fetches == 0; |
46 | ok 2, $$ref2 eq $$ref; |
47 | ok 3, $$ref2 == 7; |
48 | ok 4, $h_fetches == 2; |
49 | |
50 | $a_fetches = 0; |
51 | |
52 | sub A::TIEARRAY { bless \(my $x), "A" } |
53 | sub A::FETCH { $a_fetches++; $_[1] - 70 } |
54 | |
55 | tie @a, "A"; |
56 | |
57 | $ref = \$a[78]; |
58 | $ref2 = dclone $ref; |
59 | |
60 | ok 5, $a_fetches == 0; |
61 | ok 6, $$ref2 eq $$ref; |
62 | ok 7, $$ref2 == 8; |
63 | # I don't understand why it's 3 and not 2 |
64 | ok 8, $a_fetches == 3; |