Backward portability from Dan Kogai.
[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#
10# $Log: tied_items.t,v $
9e21b3d0 11# Revision 1.0 2000/09/01 19:40:42 ram
12# Baseline for first official release.
7a6a85bf 13#
14
15#
16# Tests ref to items in tied hash/array structures.
17#
18
19sub BEGIN {
0c384302 20 if ($ENV{PERL_CORE}){
21 chdir('t') if -d 't';
22 @INC = '.';
23 push @INC, '../lib';
24 }
9f233367 25 require Config; import Config;
0c384302 26 if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
9f233367 27 print "1..0 # Skip: Storable was not built\n";
28 exit 0;
29 }
7a6a85bf 30 require 'lib/st-dump.pl';
31}
32
33sub ok;
34$^W = 0;
35
36print "1..8\n";
37
38use Storable qw(dclone);
39
40$h_fetches = 0;
41
42sub H::TIEHASH { bless \(my $x), "H" }
43sub H::FETCH { $h_fetches++; $_[1] - 70 }
44
45tie %h, "H";
46
47$ref = \$h{77};
48$ref2 = dclone $ref;
49
50ok 1, $h_fetches == 0;
51ok 2, $$ref2 eq $$ref;
52ok 3, $$ref2 == 7;
53ok 4, $h_fetches == 2;
54
55$a_fetches = 0;
56
57sub A::TIEARRAY { bless \(my $x), "A" }
58sub A::FETCH { $a_fetches++; $_[1] - 70 }
59
60tie @a, "A";
61
62$ref = \$a[78];
63$ref2 = dclone $ref;
64
65ok 5, $a_fetches == 0;
66ok 6, $$ref2 eq $$ref;
67ok 7, $$ref2 == 8;
68# I don't understand why it's 3 and not 2
69ok 8, $a_fetches == 3;
70