3 # This test was originally for pseudo-hashes. It now exists to ensure
4 # they were properly removed in 5.9.
13 package Tie::BasicArray;
15 sub TIEARRAY { bless [], $_[0] }
16 sub STORE { $_[0]->[$_[1]] = $_[2] }
17 sub FETCH { $_[0]->[$_[1]] }
18 sub FETCHSIZE { scalar(@{$_[0]})}
19 sub STORESIZE { $#{$_[0]} = $_[1]+1 }
26 # Helper function to check the typical error message.
29 like( $err, qr/^Not a HASH reference / ) ||
30 printf STDERR "# at %s line %d.\n", (caller)[1,2];
33 # Something to place inside if blocks and while loops that won't get
75 while( my($k,$v) = each %$a ) {
82 # quick check with tied array
83 tie @fake, 'Tie::StdArray';
93 if ($a->{'abc'} eq 'ABC') { no_op(23) } else { no_op(42) }
97 # quick check with tied array
98 tie @fake, 'Tie::BasicArray';
108 if ($a->{'abc'} eq 'ABC') { no_op(23) } else { no_op(42) }
112 # quick check with tied array & tied hash
114 tie %fake, Tie::StdHash;
124 if ($a->{'abc'} eq 'ABC') { no_op(23) } else { no_op(42) }
131 my $slice = join('', 'x',@$a{'abc','def'},'x');
136 # evaluation in scalar context
151 eval { $a = %$avhv };
154 $avhv = [{foo=>1, bar=>2}];
156 %$avhv =~ m,^\d+/\d+,;
160 # check if defelem magic works
162 print "not " unless $_[0] eq 'a';
166 $a = [{key => 1}, 'a'];
172 # check if exists() is behaving properly
173 $avhv = [{foo=>1,bar=>2,pants=>3}];
175 no_op if exists $avhv->{bar};
180 $avhv->{pants} = undef;
185 no_op if exists $avhv->{pants};
190 no_op if exists $avhv->{bar};
200 no_op unless exists $avhv->{bar} and $avhv->{bar} == 10;
205 $v = delete $avhv->{bar};
210 no_op if exists $avhv->{bar};
215 $avhv->{foo} = 'xxx';
219 $avhv->{bar} = 'yyy';
223 $avhv->{pants} = 'zzz';
227 @x = delete @{$avhv}{'foo','pants'};
231 no_op unless "$avhv->{bar}" eq "yyy";
247 %$avhv = (foo => 29, pants => 2, bar => 0);
254 ($extra, %$avhv) = ("moo", foo => 42, pants => 53, bar => "HIKE!");
260 (%$avhv, $extra) = (foo => 42, pants => 53, bar => "HIKE!");
265 @extra = qw(whatever and stuff);
270 (%$avhv, @extra) = (foo => 42, pants => 53, bar => "HIKE!");
275 (@extra, %$avhv) = (foo => 42, pants => 53, bar => "HIKE!");
279 # Check hash slices (BUG ID 20010423.002)
280 $avhv = [{foo=>1, bar=>2}];
282 @$avhv{"foo", "bar"} = (42, 53);