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