Change 29939 by [EMAIL PROTECTED] on 2007/01/23 23:38:58
Integrate:
[ 26835]
Additional tests for RT #38207: "Useless localization of constant ($[)
in getopts.pl".
[ 27495]
Subject: [perl #38710] localised stash slice
From: Hugo van der Sanden (via RT) <[EMAIL PROTECTED]>
Date: Sat, 11 Mar 2006 02:47:56 -0800
Message-ID: <[EMAIL PROTECTED]>
(new TODO tests)
[ 27547]
Subject: [PATCH blead] Re: [perl #38710] localised stash slice
From: Rick Delaney <[EMAIL PROTECTED]>
Date: Sat, 18 Mar 2006 19:52:11 -0500
Message-ID: <[EMAIL PROTECTED]>
One can now localize slices.
[ 29938]
Add lib to @INC so that ./perl t/op/local.t works.
Affected files ...
... //depot/maint-5.8/perl/pp.c#118 integrate
... //depot/maint-5.8/perl/t/op/local.t#8 integrate
Differences ...
==== //depot/maint-5.8/perl/pp.c#118 (text) ====
Index: perl/pp.c
--- perl/pp.c#117~29929~ 2007-01-22 15:29:42.000000000 -0800
+++ perl/pp.c 2007-01-23 15:38:58.000000000 -0800
@@ -3943,15 +3943,19 @@
if (!svp || *svp == &PL_sv_undef) {
DIE(aTHX_ PL_no_helem_sv, keysv);
}
- if (localizing) {
- if (preeminent)
- save_helem(hv, keysv, svp);
- else {
- STRLEN keylen;
- const char * const key = SvPV_const(keysv, keylen);
- SAVEDELETE(hv, savepvn(key,keylen), keylen);
+ if (HvNAME_get(hv) && isGV(*svp))
+ save_gp((GV*)*svp, !(PL_op->op_flags & OPf_SPECIAL));
+ else {
+ if (localizing) {
+ if (preeminent)
+ save_helem(hv, keysv, svp);
+ else {
+ STRLEN keylen;
+ const char * const key = SvPV_const(keysv, keylen);
+ SAVEDELETE(hv, savepvn(key,keylen), keylen);
+ }
}
- }
+ }
}
*MARK = svp ? *svp : &PL_sv_undef;
}
==== //depot/maint-5.8/perl/t/op/local.t#8 (xtext) ====
Index: perl/t/op/local.t
--- perl/t/op/local.t#7~27928~ 2006-04-20 14:48:52.000000000 -0700
+++ perl/t/op/local.t 2007-01-23 15:38:58.000000000 -0800
@@ -2,9 +2,10 @@
BEGIN {
chdir 't' if -d 't';
+ @INC = qw(. ../lib);
require './test.pl';
}
-plan tests => 85;
+plan tests => 95;
my $list_assignment_supported = 1;
@@ -329,3 +330,42 @@
# The s/// adds 'g' magic to $_, but it should remain non-readonly
eval { for("a") { for $x (1,2) { local $_="b"; s/(.*)/+$1/ } } };
is($@, "");
+
+# Special local() behavior for $[
+# (see RT #38207 - Useless localization of constant ($[) in getopts.pl}
+{
+ local $[ = 1;
+ local $TODO = "local() not currently working correctly with \$[";
+ ok(1 == $[);
+ undef $TODO;
+ f();
+}
+
+sub f { ok(0 == $[); }
+
+# sub localisation
+{
+ package Other;
+
+ sub f1 { "f1" }
+ sub f2 { "f2" }
+
+ no warnings "redefine";
+ {
+ local *f1 = sub { "g1" };
+ ::ok(f1() eq "g1", "localised sub via glob");
+ }
+ ::ok(f1() eq "f1", "localised sub restored");
+ {
+ local $Other::{"f1"} = sub { "h1" };
+ ::ok(f1() eq "h1", "localised sub via stash");
+ }
+ ::ok(f1() eq "f1", "localised sub restored");
+ {
+ local @Other::{qw/ f1 f2 /} = (sub { "j1" }, sub { "j2" });
+ ::ok(f1() eq "j1", "localised sub via stash slice");
+ ::ok(f2() eq "j2", "localised sub via stash slice");
+ }
+ ::ok(f1() eq "f1", "localised sub restored");
+ ::ok(f2() eq "f2", "localised sub restored");
+}
End of Patch.