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