3 # Add new tests to the end with format:
9 # Warn or die msgs (if any) at - line 1234
18 run_multiple_progs('', \*DATA);
24 # standard behaviour, without any extra references
30 # SKIP !defined &DynaLoader::boot_DynaLoader && !eval 'require base'
31 # (skip under miniperl if base.pm is not in lib/ yet)
33 # standard behaviour, without any extra references
35 {package Tie::HashUntie;
36 use base 'Tie::StdHash';
42 tie %h, Tie::HashUntie;
48 # standard behaviour, with 1 extra reference
50 $a = tie %h, Tie::StdHash;
55 # standard behaviour, with 1 extra reference via tied
63 # standard behaviour, with 1 extra reference which is destroyed
65 $a = tie %h, Tie::StdHash;
71 # standard behaviour, with 1 extra reference via tied which is destroyed
80 # strict behaviour, without any extra references
88 # strict behaviour, with 1 extra references generating an error
91 $a = tie %h, Tie::StdHash;
94 untie attempted while 1 inner references still exist at - line 6.
97 # strict behaviour, with 1 extra references via tied generating an error
100 tie %h, Tie::StdHash;
104 untie attempted while 1 inner references still exist at - line 7.
107 # strict behaviour, with 1 extra references which are destroyed
108 use warnings 'untie';
110 $a = tie %h, Tie::StdHash;
116 # strict behaviour, with extra 1 references via tied which are destroyed
117 use warnings 'untie';
119 tie %h, Tie::StdHash;
126 # strict error behaviour, with 2 extra references
127 use warnings 'untie';
129 $a = tie %h, Tie::StdHash;
133 untie attempted while 2 inner references still exist at - line 7.
136 # strict behaviour, check scope of strictness.
139 $A = tie %H, Tie::StdHash;
142 use warnings 'untie';
144 tie %h, Tie::StdHash;
151 # Forbidden aggregate self-ties
152 sub Self::TIEHASH { bless $_[1], $_[0] }
158 Self-ties of arrays and hashes are not supported at - line 6.
161 # Allowed scalar self-ties
163 sub Self::TIESCALAR { bless $_[1], $_[0] }
164 sub Self::DESTROY { $destroyed = 1; }
169 die "self-tied scalar not DESTROYed" unless $destroyed == 1;
173 # Allowed glob self-ties
176 sub Self2::TIEHANDLE { bless $_[1], $_[0] }
177 sub Self2::DESTROY { $destroyed = 1; }
178 sub Self2::PRINT { $printed = 1; }
182 tie *$c, 'Self2', $c;
185 die "self-tied glob not PRINTed" unless $printed == 1;
186 die "self-tied glob not DESTROYed" unless $destroyed == 1;
190 # Allowed IO self-ties
192 sub Self3::TIEHANDLE { bless $_[1], $_[0] }
193 sub Self3::DESTROY { $destroyed = 1; }
194 sub Self3::PRINT { $printed = 1; }
196 use Symbol 'geniosym';
198 tie *$c, 'Self3', $c;
201 die "self-tied IO not PRINTed" unless $printed == 1;
202 die "self-tied IO not DESTROYed" unless $destroyed == 1;
206 # TODO IO "self-tie" via TEMP glob
208 sub Self3::TIEHANDLE { bless $_[1], $_[0] }
209 sub Self3::DESTROY { $destroyed = 1; }
210 sub Self3::PRINT { $printed = 1; }
212 use Symbol 'geniosym';
214 tie *$c, 'Self3', \*$c;
217 die "IO tied to TEMP glob not PRINTed" unless $printed == 1;
218 die "IO tied to TEMP glob not DESTROYed" unless $destroyed == 1;
222 # Interaction of tie and vec
226 tie $a,Tie::StdScalar or die;
235 # correct unlocalisation of tied hashes (patch #16431)
237 tie %tied, Tie::StdHash;
238 { local $hash{'foo'} } warn "plain hash bad unlocalize" if exists $hash{'foo'};
239 { local $tied{'foo'} } warn "tied hash bad unlocalize" if exists $tied{'foo'};
240 { local $ENV{'foo'} } warn "%ENV bad unlocalize" if exists $ENV{'foo'};
244 # An attempt at lvalueable barewords broke this
247 Can't modify constant item in tie at - line 3, near "'main';"
248 Execution of - aborted due to compilation errors.
251 # localizing tied hash slices
254 print exists $ENV{FooA} ? 1 : 0, "\n";
255 print exists $ENV{FooB} ? 2 : 0, "\n";
256 print exists $ENV{FooC} ? 3 : 0, "\n";
258 local @ENV{qw(FooA FooC)};
259 print exists $ENV{FooA} ? 4 : 0, "\n";
260 print exists $ENV{FooB} ? 5 : 0, "\n";
261 print exists $ENV{FooC} ? 6 : 0, "\n";
263 print exists $ENV{FooA} ? 7 : 0, "\n";
264 print exists $ENV{FooB} ? 8 : 0, "\n";
265 print exists $ENV{FooC} ? 9 : 0, "\n"; # this should not exist
278 # FETCH freeing tie'd SV still works
279 sub TIESCALAR { bless [] }
280 sub FETCH { *a = \1; 2 }
287 # [20020716.007] - nested FETCHES
289 sub F1::TIEARRAY { bless [], 'F1' }
294 sub F2::TIEARRAY { bless [2], 'F2' }
295 sub F2::FETCH { my $self = shift; my $x = $f1[3]; $self }
299 print $f2[4][0],"\n";
301 sub F3::TIEHASH { bless [], 'F3' }
306 sub F4::TIEHASH { bless [3], 'F4' }
307 sub F4::FETCH { my $self = shift; my $x = $f3{3}; $self }
311 print $f4{'foo'}[0],"\n";
317 # test untie() from within FETCH
319 sub TIESCALAR { my $pkg = shift; return bless [@_], $pkg; }
322 my ($obj, $field) = @$self;
323 untie $obj->{$field};
324 $obj->{$field} = "Bar";
327 tie $a->{foo}, "Foo", $a, "foo";
328 my $s = $a->{foo}; # access once
329 # the hash element should not be tied anymore
330 print defined tied $a->{foo} ? "not ok" : "ok";
334 # the tmps returned by FETCH should appear to be SCALAR
335 # (even though they are now implemented using PVLVs.)
337 sub TIEHASH { bless {} }
338 sub TIEARRAY { bless {} }
345 my $s = "$r1 ". ref($r1) . " $r2 " . ref($r2);
349 SCALAR SCALAR SCALAR SCALAR
351 # [perl #23287] segfault in untie
352 sub TIESCALAR { bless $_[1], $_[0] }
354 tie $var, 'main', \$var;
358 # Test case from perlmonks by runrig
359 # http://www.perlmonks.org/index.pl?node_id=273490
360 # "Here is what I tried. I think its similar to what you've tried
361 # above. Its odd but convenient that after untie'ing you are left with
362 # a variable that has the same value as was last returned from
363 # FETCH. (At least on my perl v5.6.1). So you don't need to pass a
364 # reference to the variable in order to set it after the untie (here it
365 # is accessed through a closure)."
370 my ($class,$code) = @_;
380 tie $var, 'MyTied', sub { untie $var; 4 };
396 # [perl #22297] cannot untie scalar from within tied FETCH
400 tie $x, 'Overlay', $ref, $x;
406 #print "WILL EXTERNAL UNTIE $ref\n";
412 #print "counter = $counter\n";
414 print (($counter == 1) ? "ok\n" : "not ok\n");
421 my ($ref, $val) = @_;
422 return bless [ $ref, $val ], $pkg;
428 my ($ref, $val) = @$self;
429 #print "WILL INTERNAL UNITE $ref\n";
438 # [perl #948] cannot meaningfully tie $,
439 package TieDollarComma;
443 return bless \my $x, $pkg;
449 print "STORE set '$$self'\n";
459 tie $,, 'TieDollarComma';
461 print "join", "things", "up\n";
464 join<FETCH>BOBBINSthings<FETCH>BOBBINSup
476 $_[0]->{$_[1]} = $_[2];
489 return 0 if ! keys %{$_[0]};
490 sprintf "%i/%i", scalar keys %{$_[0]}, scalar keys %{$_[0]};
494 tie my %h => "TieScalar";
497 print scalar %h, "\n"
498 if %h; # this should also call SCALAR but implicitly
500 print scalar %h, "\n"
501 if !%h; # this should also call SCALAR but implicitly
511 # test scalar on tied hash when no SCALAR method has been given
519 $_[0]->{$_[1]} = $_[2];
528 my $a = keys %{ $_[0] };
534 tie my %h => "TieScalar";
543 print "not empty\n" if %h;
544 print "not empty\n" if %h;
546 my ($k,$v) = each %h;
548 print "not empty\n" if %h;
550 print "empty\n" if ! %h;
565 sub TIESCALAR { bless {} }
566 sub FETCH { my $x = 3.3; 1 if 0+$x; $x }
572 sub TIESCALAR { bless {} }
573 sub FETCH { shift()->{i} ++ }
579 # Bug 53482 (and maybe others)
580 sub TIESCALAR { my $foo = $_[1]; bless \$foo, $_[0] }
581 sub FETCH { ${$_[0]} }
582 tie my $x1, "main", 2;
583 tie my $y1, "main", 8;
586 tie my $x2, "main", "2";
587 tie my $y2, "main", "8";
594 sub TIEHASH { bless {}, $_[0] }
595 sub STORE { $_[0]->{$_[1]} = $_[2] }
596 sub FIRSTKEY { my $a = scalar keys %{$_[0]}; each %{$_[0]} }
597 sub NEXTKEY { each %{$_[0]} }
598 sub DELETE { delete $_[0]->{$_[1]} }
599 sub CLEAR { %{$_[0]} = () }
602 print scalar keys %h, "\n";
607 print scalar keys %h, "\n";
613 sub foo::TIESCALAR { bless {value => $_[1]}, $_[0] }
614 sub foo::FETCH { $_[0]->{value} }
615 tie my $VAR, 'foo', '42';
616 foreach my $var ($VAR) {
617 print +($var eq $VAR) ? "yes\n" : "no\n";
622 sub TIEARRAY { bless [], 'main' }
627 print "tied\n" if tied @a;
630 sub TIEHASH { bless [], 'main' }
635 print "tied\n" if tied %h;
638 # RT 20727: PL_defoutgv is left as a tied element
639 sub TIESCALAR { return bless {}, 'main' }
644 select(); # this used to coredump or assert fail
650 # RT 23810: eval in die in FETCH can corrupt context stack
652 my $file = 'rt23810.pm';
658 my ($str, $eval) = @_;
659 open my $fh, '>', $file or die "Can't create $file: $!\n";
664 eval { require $pm; $s .= '-ENDE' }
674 sub TIEHASH { bless {} }
677 # 10 or more syntax errors makes yyparse croak()
678 my $bad = q{$x+;$x+;$x+;$x+;$x+;$x+;$x+;$x+;$x+$x+;$x+;$x+;$x+;$x+;;$x+;};
680 if ($_[1] eq 'eval') {
682 eval q[BEGIN { die; $s .= '-X1' }];
684 eval q[BEGIN { $x+ }];
688 $s .= '-S1' while $@ =~ /syntax error at/g;
691 $s .= '-S2' while $@ =~ /syntax error at/g;
693 elsif ($_[1] eq 'require') {
696 q[BEGIN { die; $s .= '-X1' }],
701 for my $i (0..$#text) {
703 do_require($txt[$i], 0) if $e;;
704 do_require($txt[$i], 1);
707 elsif ($_[1] eq 'exit') {
708 eval q[exit(0); print "overshot eval\n"];
711 print "unknown key: '$_[1]'\n";
718 for my $action(qw(eval require)) {
719 $s = ''; $e = 0; $s .= main->FETCH($action); print "$action: s0=$s\n";
720 $s = ''; $e = 1; eval { $s .= main->FETCH($action)}; print "$action: s1=$s\n";
721 $s = ''; $e = 0; $s .= $foo{$action}; print "$action: s2=$s\n";
722 $s = ''; $e = 1; eval { $s .= $foo{$action}}; print "$action: s3=$s\n";
724 1 while unlink $file;
727 print "overshot main\n"; # shouldn't reach here
730 eval: s0=EVAL-BD-BS-E1-S1-E2-S2-S2-S2-S2-S2-S2-S2-S2-S2-S2-R
731 eval: s1=EVAL-BD-BS-E1-S1-E2-S2-S2-S2-S2-S2-S2-S2-S2-S2-S2-R
732 eval: s2=EVAL-BD-BS-E1-S1-E2-S2-S2-S2-S2-S2-S2-S2-S2-S2-S2-R
733 eval: s3=EVAL-BD-BS-E1-S1-E2-S2-S2-S2-S2-S2-S2-S2-S2-S2-S2-R
734 require: s0=REQUIRE-0-ERQ-ENDRQ-1-ERQ-ENDRQ-2-ERQ-ENDRQ-3-ERQ-ENDRQ-R
735 require: s1=REQUIRE-0-RQ
736 require: s2=REQUIRE-0-ERQ-ENDRQ-1-ERQ-ENDRQ-2-ERQ-ENDRQ-3-ERQ-ENDRQ-R
737 require: s3=REQUIRE-0-RQ
739 # RT 8857: STORE incorrectly invoked for local($_) on aliased tied array
742 sub TIEARRAY { bless [], $_[0] }
743 sub TIEHASH { bless [], $_[0] }
744 sub FETCH { $_[0]->[$_[1]] }
745 sub STORE { $_[0]->[$_[1]] = $_[2] }
754 foreach ($a[0], $h{a}) {
757 # on failure, chucks up 'premature free' etc messages
761 # the initial fix for this bug caused tied scalar FETCH to be called
762 # multiple times when that scalar was an element in an array. Check it
763 # only gets called once now.
765 sub TIESCALAR { bless [], $_[0] }
767 sub FETCH { $c++; 0 }
769 sub STORE { $c += 100; 0 }
777 my $x = $a[0] + $h{foo} + $a[$i] + (@a)[0];
782 # Bug 68192 - numeric ops not calling mg_get when tied scalar holds a ref
783 sub TIESCALAR { bless {}, __PACKAGE__ };
786 print "fetching... "; # make sure FETCH is called once per op
790 tie $foo, __PACKAGE__;
793 print "+ ", 0 + $foo, "\n";
794 print "** ", $foo**1, "\n";
795 print "* ", $foo*1, "\n";
796 print "/ ", $foo*1, "\n";
797 print "% ", $foo%123457, "\n";
798 print "- ", $foo-0, "\n";
799 print "neg ", - -$foo, "\n";
800 print "int ", int $foo, "\n";
801 print "abs ", abs $foo, "\n";
802 print "== ", 123456 == $foo, "\n";
803 print "< ", 123455 < $foo, "\n";
804 print "> ", 123457 > $foo, "\n";
805 print "<= ", 123456 <= $foo, "\n";
806 print ">= ", 123456 >= $foo, "\n";
807 print "!= ", 0 != $foo, "\n";
808 print "<=> ", 123457 <=> $foo, "\n";
811 fetching... ** 123456
816 fetching... neg 123456
817 fetching... int 123456
818 fetching... abs 123456
827 # Ties returning overloaded objects
831 '*{}' => sub { print '*{}'; \*100 },
832 '@{}' => sub { print '@{}'; \@100 },
833 '%{}' => sub { print '%{}'; \%100 },
834 '${}' => sub { print '${}'; \$100 },
837 $_ => sub { print "$op"; 100 }
838 } qw< 0+ "" + ** * / % - neg int abs == < > <= >= != <=> <> >
840 $o = bless [], overloaded;
842 sub TIESCALAR { bless {}, "" }
843 sub FETCH { print "fetching... "; $o }
847 $ghew=undef; 1+$ghew; print "\n";
848 $ghew=undef; $ghew**1; print "\n";
849 $ghew=undef; $ghew*1; print "\n";
850 $ghew=undef; $ghew/1; print "\n";
851 $ghew=undef; $ghew%1; print "\n";
852 $ghew=undef; $ghew-1; print "\n";
853 $ghew=undef; -$ghew; print "\n";
854 $ghew=undef; int $ghew; print "\n";
855 $ghew=undef; abs $ghew; print "\n";
856 $ghew=undef; 1 == $ghew; print "\n";
857 $ghew=undef; $ghew<1; print "\n";
858 $ghew=undef; $ghew>1; print "\n";
859 $ghew=undef; $ghew<=1; print "\n";
860 $ghew=undef; $ghew >=1; print "\n";
861 $ghew=undef; $ghew != 1; print "\n";
862 $ghew=undef; $ghew<=>1; print "\n";
863 $ghew=undef; <$ghew>; print "\n";
864 $ghew=\*shrext; *$ghew; print "\n";
865 $ghew=\@spled; @$ghew; print "\n";
866 $ghew=\%frit; %$ghew; print "\n";
867 $ghew=\$drile; $$ghew; print "\n";
891 # RT 51636: segmentation fault with array ties
895 print "ok\n"; # if we got here we didn't crash
899 sub TIEARRAY { bless {} }
900 sub STORE { tie my @b, 'T' }
907 # RT 8438: Tied scalars don't call FETCH when subref is dereferenced
909 sub TIESCALAR { bless {} }
913 sub FETCH { $fetch++; sub { $called++ } }
917 print "fetch=$fetch\ncalled=$called\n";
923 # tie mustn't attempt to call methods on bareword filehandles.
924 sub IO::File::TIEARRAY {
925 die "Did not want to invoke IO::File::TIEARRAY";
927 fileno FOO; tie @a, "FOO"
929 Can't locate object method "TIEARRAY" via package "FOO" at - line 5.
932 # STORE freeing tie'd AV
933 sub TIEARRAY { bless [] }
934 sub STORE { *a = []; 1 }
942 # CLEAR freeing tie'd AV
943 sub TIEARRAY { bless [] }
944 sub CLEAR { *a = []; 1 }
953 # FETCHSIZE freeing tie'd AV
954 sub TIEARRAY { bless [] }
955 sub FETCHSIZE { *a = []; 100 }
965 # [perl #86328] Crash when freeing tie magic that can increment the refcnt
967 eval { require Scalar::Util } or print("ok\n"), exit;
972 *TIEARRAY = *TIEHASH;
981 Scalar::Util::weaken($o->[0] = $a);
986 Scalar::Util::weaken($p->[0] = $b);
989 # Done setting up the evil data structures
999 # Localising a tied COW scalar should not make it read-only.
1001 sub TIESCALAR { bless [] }
1002 sub FETCH { __PACKAGE__ }
1015 # Nor should it be impossible to tie COW scalars that are already PVMGs.
1017 sub TIESCALAR { bless [] }
1019 undef $x; # downgrade to PVMG
1020 $x = __PACKAGE__; # PVMG + COW
1023 print STDERR "ok\n";
1025 # However, one should not be able to tie read-only glob copies, which look
1026 # a bit like kine internally (FAKE + READONLY).
1028 Internals::SvREADONLY($y,1);
1033 Modification of a read-only value attempted at - line 16.
1036 # And one should not be able to tie read-only COWs
1037 for(__PACKAGE__) { tie $_, "" }
1038 sub TIESCALAR {bless []}
1040 Modification of a read-only value attempted at - line 3.
1043 # Similarly, read-only regexps cannot be tied.
1044 sub TIESCALAR { bless [] }
1046 Internals::SvREADONLY($y,1);
1050 Modification of a read-only value attempted at - line 6.
1053 # tied() should still work on tied scalars after glob assignment
1054 sub TIESCALAR {bless[]}
1056 sub f::TIEHANDLE{bless[],f}
1059 [$rin]; # call FETCH
1060 print ref tied $rin, "\n";
1061 print ref tied *$rin, "\n";
1067 # (un)tie $glob_copy vs (un)tie *$glob_copy
1068 sub TIESCALAR { print "TIESCALAR\n"; bless [] }
1069 sub TIEHANDLE{ print "TIEHANDLE\n"; bless [] }
1070 sub FETCH { print "never called\n" }
1075 print "ok 1\n" if !tied $f;
1076 () = $f; # should not call FETCH
1078 print "ok 2\n" if !tied *foo;
1086 # RT #8611 mustn't goto outside the magic stack
1087 sub TIESCALAR { warn "tiescalar\n"; bless [] }
1088 sub FETCH { warn "fetch()\n"; goto FOO; }
1090 warn "before fetch\n";
1092 warn "before FOO\n";
1099 Can't find label FOO at - line 4.
1102 # RT #8611 mustn't goto outside the magic stack
1103 sub TIEHANDLE { warn "tiehandle\n"; bless [] }
1104 sub PRINT { warn "print()\n"; goto FOO; }
1106 warn "before print\n";
1108 warn "before FOO\n";
1115 Can't find label FOO at - line 4.
1118 # \&$tied with $tied holding a reference before the fetch (but not after)
1120 sub TIESCALAR {bless[]}
1131 # \&$tied with $tied holding a PVLV glob before the fetch (but not after)
1133 sub TIEARRAY {bless[]}
1139 print &{\&$$elem}, "\n";
1144 # \&$tied with $tied holding a PVGV glob before the fetch (but not after)
1145 local *72 = sub { 73 };
1146 sub TIESCALAR {bless[]}
1151 print &{\&$x}, "\n";
1156 # Lexicals should not be visible to magic methods on scope exit
1157 BEGIN { unless (defined &DynaLoader::boot_DynaLoader) {
1158 print "HASH\nHASH\nARRAY\nARRAY\n"; exit;
1160 use Scalar::Util 'weaken';
1162 sub TIEHASH { Scalar::Util::weaken($_[1]); bless \$_[1], xoufghd:: }
1163 *TIEARRAY = *TIEHASH;
1165 bless ${$_[0]} || return, 0;
1168 # hashes: ties before backrefs
1172 tie %hash, xoufghd::, \%hash;
1175 # hashes: backrefs before ties
1179 weaken(my $x = \%hash);
1180 tie %hash, xoufghd::, \%hash;
1183 # arrays: ties before backrefs
1187 tie @array, xoufghd::, \@array;
1190 # arrays: backrefs before ties
1194 weaken(my $x = \@array);
1195 tie @array, xoufghd::, \@array;
1210 # Localising a tied variable with a typeglob in it should copy magic
1211 sub TIESCALAR{bless[]}
1212 sub FETCH{warn "fetching\n"; *foo}
1226 # tied returns same value as tie
1227 sub TIESCALAR{bless[]}
1228 $tyre = \tie $tied, "";
1229 print "ok\n" if \tied $tied == $tyre;
1234 # tied arrays should always be AvREAL
1236 sub TIEARRAY{bless[]}
1239 \@_; # used to produce: av_reify called on tied array at - line 7.
1244 # [perl #67490] scalar-tying elements of magic hashes
1245 sub TIESCALAR{bless[]}
1256 # [perl #35865, #43011] autovivification should call FETCH after STORE
1257 # because perl does not know that the FETCH would have returned the same
1258 # thing that was just stored.
1260 # This package never likes to take ownership of other people’s refs. It
1261 # always makes its own copies. (For simplicity, it only accepts hashes.)
1263 sub TIEHASH { bless {} }
1264 sub FETCH { $_[0]{$_[1]} }
1265 sub STORE { $_[0]{$_[1]} = { %{ $_[2] } } }
1267 tie my %h, copier::;
1269 print $h{i}{j}, "\n";
1274 # [perl #8931] FETCH for tied $" called an odd number of times.
1277 sub A::TIESCALAR {bless [] => 'A'}
1278 sub A::FETCH {print ++ $i, "\n"}
1279 my @a = ("", "", "");
1292 # [perl #9391] return value from 'tied' not discarded soon enough
1299 sub T::TIEARRAY { my $s; bless \$s => "T" }
1303 # NAME Test that tying a hash does not leak a deleted iterator
1304 # This produced unbalanced string table warnings under
1305 # PERL_DESTRUCT_LEVEL=2.
1307 sub TIEHASH{bless[]}
1316 # NAME EXISTS on arrays
1317 sub TIEARRAY{bless[]};
1318 sub FETCHSIZE { 50 }
1319 sub EXISTS { print "does $_[1] exist?\n" }
1323 $NEGATIVE_INDICES=1;
1331 # Crash when using negative index on array tied to non-object
1332 sub TIEARRAY{bless[]};
1333 ${\tie @a, ""} = undef;
1334 eval { $_ = $a[-1] }; print $@;
1335 eval { $a[-1] = '' }; print $@;
1336 eval { delete $a[-1] }; print $@;
1337 eval { exists $a[-1] }; print $@;
1340 Can't call method "FETCHSIZE" on an undefined value at - line 5.
1341 Can't call method "FETCHSIZE" on an undefined value at - line 6.
1342 Can't call method "FETCHSIZE" on an undefined value at - line 7.
1343 Can't call method "FETCHSIZE" on an undefined value at - line 8.
1346 # Crash when reading negative index when NEGATIVE_INDICES stub exists
1347 sub NEGATIVE_INDICES;
1348 sub TIEARRAY{bless[]};
1351 print "ok\n" if ! defined $a[-1];
1356 # Assigning vstrings to tied scalars
1357 sub TIESCALAR{bless[]};
1358 sub STORE { print ref \$_[1], "\n" }
1359 tie $x, ""; $x = v3;
1364 # [perl #27010] Tying deferred elements
1366 sub TIESCALAR{bless[]};
1369 print ref tied $h{k};
1371 print ref tied $_[1];
1373 print tied $_[0] // 'undef';
1375 print tied $h{l} // 'undef';
1376 # check that tied and untie do not autovivify
1377 # XXX should they autovivify?
1379 print exists $h{m} ? "yes" : "no";
1381 print exists $h{m} ? "yes" : "no";
1382 }->($h{k}, $h{l}, $h{m});
1392 # [perl #78194] Passing op return values to tie constructors
1394 print \$_[1] == \$_[1] ? "ok\n" : "not ok\n";
1401 # Scalar-tied locked hash keys and copy-on-write
1403 tie $h{foo}, Tie::StdScalar;
1404 tie $h{bar}, Tie::StdScalar;
1405 $h{foo} = __PACKAGE__; # COW
1406 $h{bar} = 1; # not COW
1407 # Moral equivalent of Hash::Util::lock_whatever, but miniperl-compatible
1408 Internals::SvREADONLY($h{foo},1);
1409 Internals::SvREADONLY($h{bar},1);
1410 print $h{foo}, "\n"; # should not croak
1411 # Whether the value is COW should make no difference here (whether the
1412 # behaviour is ultimately correct is another matter):
1415 print "ok\n" if (eval{ $h{foo} = 1 }||$@) eq (eval{ $h{bar} = 1 }||$@);
1421 # &xsub and goto &xsub with tied @_
1423 tie @_, Tie::StdArray;
1426 printf "%x\n", $_ for map ord, split //, $_[0];
1429 & {sub { goto &utf8::encode }};
1430 printf "%x\n", $_ for map ord, split //, $_[0];
1439 # Defelem pointing to nonexistent element of tied array
1442 # This sub is called with a deferred element. Inside the sub, $_[0] pros-
1443 # pectively points to element 10000 of @a.
1445 tie @a, "Tie::StdArray"; # now @a is tied
1446 $#a = 20000; # and FETCHSIZE/AvFILL will now return a big number
1447 $a[10000] = "crumpets\n";
1448 $_ = "$_[0]"; # but defelems don’t expect tied arrays and try to read
1449 # AvARRAY[10000], which crashes