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 { |
48c887dd |
14 | unshift @INC, 't'; |
9f233367 |
15 | require Config; import Config; |
0c384302 |
16 | if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) { |
9f233367 |
17 | print "1..0 # Skip: Storable was not built\n"; |
18 | exit 0; |
19 | } |
372cb964 |
20 | require 'st-dump.pl'; |
7a6a85bf |
21 | } |
22 | |
23 | sub ok; |
24 | $^W = 0; |
25 | |
26 | print "1..8\n"; |
27 | |
28 | use Storable qw(dclone); |
29 | |
30 | $h_fetches = 0; |
31 | |
32 | sub H::TIEHASH { bless \(my $x), "H" } |
33 | sub H::FETCH { $h_fetches++; $_[1] - 70 } |
34 | |
35 | tie %h, "H"; |
36 | |
37 | $ref = \$h{77}; |
38 | $ref2 = dclone $ref; |
39 | |
40 | ok 1, $h_fetches == 0; |
41 | ok 2, $$ref2 eq $$ref; |
42 | ok 3, $$ref2 == 7; |
43 | ok 4, $h_fetches == 2; |
44 | |
45 | $a_fetches = 0; |
46 | |
47 | sub A::TIEARRAY { bless \(my $x), "A" } |
48 | sub A::FETCH { $a_fetches++; $_[1] - 70 } |
49 | |
50 | tie @a, "A"; |
51 | |
52 | $ref = \$a[78]; |
53 | $ref2 = dclone $ref; |
54 | |
55 | ok 5, $a_fetches == 0; |
56 | ok 6, $$ref2 eq $$ref; |
57 | ok 7, $$ref2 == 8; |
58 | # I don't understand why it's 3 and not 2 |
59 | ok 8, $a_fetches == 3; |