17 my ($class,@val) = @_;
18 return bless \@val,$class;
24 return $#{$ob} = $sz-1;
35 return scalar(@{$_[0]});
46 my ($ob,$id,$val) = @_;
86 my $off = @_ ? shift : 0;
87 my $len = @_ ? shift : @$ob-1;
88 return splice(@$ob,$off,$len,@_);
91 package NegIndex; # 20020220 MJD
94 # simulate indices -2 .. 2
96 $NegIndex::NEGATIVE_INDICES = 1;
100 #print "# FETCH @_\n";
106 my ($ob,$id,$value) = @_;
107 #print "# STORE @_\n";
114 #print "# DELETE @_\n";
121 #print "# EXISTS @_\n";
127 # Returning -1 from FETCHSIZE used to get casted to U32 causing a
131 package NegFetchsize;
133 sub TIEARRAY { bless [] }
141 $seen{'DESTROY'} = 0;
145 my $ob = tie @ary,'Implement',3,2,1;
152 is(join(':',@ary), '3:2:1');
153 cmp_ok($seen{'FETCH'}, '>=', 3);
157 cmp_ok($seen{'STORE'}, '>=', 3);
158 is(join(':',@ary), '1:2:3');
162 is(join(':',@thing), '1:2:3');
164 tie @thing,'Implement';
166 is(join(':',@thing), '1:2:3');
168 is($seen{'DESTROY'}, 1, "thing freed");
172 is(join(':',@ary), '1:2');
175 is($seen{'PUSH'}, 1);
176 is(join(':',@ary), '1:2:4');
178 my @x = splice(@ary,1,1,7);
180 is($seen{'SPLICE'}, 1);
183 is(join(':',@ary), '1:7:4');
186 is($seen{'SHIFT'}, 1);
187 is(join(':',@ary), '7:4');
189 my $n = unshift(@ary,5,6);
190 is($seen{'UNSHIFT'}, 1);
192 is(join(':',@ary), '5:6:7:4');
194 @ary = split(/:/,'1:2:3');
195 is(join(':',@ary), '1:2:3');
202 # (30-33) 20020303 mjd-perl-patch+@plover.com
205 pop @ary; # this didn't used to call POP at all
208 shift @ary; # this didn't used to call SHIFT at all
211 my $got = push @ary; # this didn't used to call PUSH at all
215 $got = unshift @ary; # this didn't used to call UNSHIFT at all
217 is($seen{UNSHIFT}, 1);
220 is(join(':',@ary), '3:2:1');
223 is($seen{'STORESIZE'}, 1, 'seen STORESIZE');
224 is(join(':',@ary), '3:2');
226 sub arysize :lvalue { $#ary }
228 is($seen{'STORESIZE'}, 2, 'seen STORESIZE');
229 is(join(':',@ary), '3');
233 is($seen{'DESTROY'}, 2, "ary freed");
235 # 20020401 mjd-perl-patch+@plover.com
236 # Thanks to Dave Mitchell for the small test case and the fix
240 sub X::TIEARRAY { bless {}, 'X' }
249 # If we survived this far.
253 # 20020220 mjd-perl-patch+@plover.com
255 $seen{'DESTROY'} = 0;
258 tie @n => 'NegIndex', ('A' .. 'E');
283 is(defined($n[$_]), '');
284 is(exists($n[$_]), '');
287 is($seen{'DESTROY'}, 1, "n freed");
290 tie my @dummy, "NegFetchsize";
292 like($@, qr/^FETCHSIZE returned a negative value/,
293 " - croak on negative FETCHSIZE");
297 # check that a tied element assigned to an array doesn't remain tied
303 sub TIEARRAY { bless [1] }
304 sub TIEHASH { bless [1] }
307 sub STORE { $_[0][0] = $_[1]; }
316 is ($b[0], 10, "Magical array fetch 1");
318 is ($b[0], 100, "Magical array fetch 2");
323 is ($b{0}, 11, "Magical hash fetch 1");
325 is ($b{0}, 100, "Magical hash fetch 2");