Do not try to load a feature bundle when doing "no VERSION"
[p5sagit/p5-mst-13.2.git] / dist / Storable / t / tied_items.t
1 #!./perl
2 #
3 #  Copyright (c) 1995-2000, Raphael Manfredi
4 #  
5 #  You may redistribute only under the same terms as Perl 5, as specified
6 #  in the README file that comes with the distribution.
7 #
8
9 #
10 # Tests ref to items in tied hash/array structures.
11 #
12
13 sub BEGIN {
14     unshift @INC, 't';
15     require Config; import Config;
16     if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
17         print "1..0 # Skip: Storable was not built\n";
18         exit 0;
19     }
20     require 'st-dump.pl';
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 # a bug in 5.12 and earlier caused an extra FETCH
59 ok 8, $a_fetches == 2 || $a_fetches == 3 ;