Commit | Line | Data |
7a6a85bf |
1 | #!./perl |
2 | |
3 | # $Id: tied_items.t,v 0.7.1.2 2000/08/14 07:20:35 ram Exp $ |
4 | # |
5 | # Copyright (c) 1995-2000, Raphael Manfredi |
6 | # |
7 | # You may redistribute only under the terms of the Artistic License, |
8 | # as specified in the README file that comes with the distribution. |
9 | # |
10 | # $Log: tied_items.t,v $ |
11 | # Revision 0.7.1.2 2000/08/14 07:20:35 ram |
12 | # patch2: removed spurious dependency to Devel::Peek, used for testing only |
13 | # |
14 | # Revision 0.7.1.1 2000/08/13 20:10:31 ram |
15 | # patch1: created |
16 | # |
17 | |
18 | # |
19 | # Tests ref to items in tied hash/array structures. |
20 | # |
21 | |
22 | sub BEGIN { |
23 | chdir('t') if -d 't'; |
20822f61 |
24 | @INC = '.'; |
25 | push @INC, '../lib'; |
9f233367 |
26 | require Config; import Config; |
27 | if ($Config{'extensions'} !~ /\bStorable\b/) { |
28 | print "1..0 # Skip: Storable was not built\n"; |
29 | exit 0; |
30 | } |
7a6a85bf |
31 | require 'lib/st-dump.pl'; |
32 | } |
33 | |
34 | sub ok; |
35 | $^W = 0; |
36 | |
37 | print "1..8\n"; |
38 | |
39 | use Storable qw(dclone); |
40 | |
41 | $h_fetches = 0; |
42 | |
43 | sub H::TIEHASH { bless \(my $x), "H" } |
44 | sub H::FETCH { $h_fetches++; $_[1] - 70 } |
45 | |
46 | tie %h, "H"; |
47 | |
48 | $ref = \$h{77}; |
49 | $ref2 = dclone $ref; |
50 | |
51 | ok 1, $h_fetches == 0; |
52 | ok 2, $$ref2 eq $$ref; |
53 | ok 3, $$ref2 == 7; |
54 | ok 4, $h_fetches == 2; |
55 | |
56 | $a_fetches = 0; |
57 | |
58 | sub A::TIEARRAY { bless \(my $x), "A" } |
59 | sub A::FETCH { $a_fetches++; $_[1] - 70 } |
60 | |
61 | tie @a, "A"; |
62 | |
63 | $ref = \$a[78]; |
64 | $ref2 = dclone $ref; |
65 | |
66 | ok 5, $a_fetches == 0; |
67 | ok 6, $$ref2 eq $$ref; |
68 | ok 7, $$ref2 == 8; |
69 | # I don't understand why it's 3 and not 2 |
70 | ok 8, $a_fetches == 3; |
71 | |