summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-10-24 06:14:31 -0700
committerFather Chrysostomos <sprout@cpan.org>2011-10-24 06:15:07 -0700
commit93b2dae14541cd2bc39e2d4b1bb5f0cc2c0ef0c7 (patch)
treefcd31000dcf19da71fc0aba7ec82bbfb647e2707
parente27aa02b637769bf2276f7915bcaceba353e4a2e (diff)
downloadperl-93b2dae14541cd2bc39e2d4b1bb5f0cc2c0ef0c7.tar.gz
Make <~> work again under miniperl
Commit a3342be368 localised %ENV before calling csh for glob. But that causes <~> to stop working. So this commit clears out %ENV *except* for $ENV{HOME}. It relies on the way magic works: Before localising the %ENV hash, it retrieves its $ENV{HOME} element, which is a magical scalar. It calls get-magic to store the value in the scalar itself, localises %ENV, and then calls set-magic on the element, to signal (deceitfully) that an assignment has just happened. So the cached value in the magical sca- lar is used and assigned to the env var.
-rw-r--r--doio.c8
-rw-r--r--t/op/glob.t10
2 files changed, 15 insertions, 3 deletions
diff --git a/doio.c b/doio.c
index 06d9bcd18c..47b60ceb11 100644
--- a/doio.c
+++ b/doio.c
@@ -2379,7 +2379,13 @@ Perl_vms_start_glob
#endif
#endif /* !CSH */
#endif /* !DOSISH */
- save_hash(gv_fetchpvs("ENV", 0, SVt_PVHV));
+ {
+ GV * const envgv = gv_fetchpvs("ENV", 0, SVt_PVHV);
+ SV ** const home = hv_fetchs(GvHV(envgv), "HOME", 0);
+ if (home && *home) SvGETMAGIC(*home);
+ save_hash(gv_fetchpvs("ENV", 0, SVt_PVHV));
+ if (home && *home) SvSETMAGIC(*home);
+ }
(void)do_open(PL_last_in_gv, (char*)SvPVX_const(tmpcmd), SvCUR(tmpcmd),
FALSE, O_RDONLY, 0, NULL);
fp = IoIFP(io);
diff --git a/t/op/glob.t b/t/op/glob.t
index 6abcc75b3e..d5ddd9f84e 100644
--- a/t/op/glob.t
+++ b/t/op/glob.t
@@ -3,10 +3,10 @@
BEGIN {
chdir 't' if -d 't';
@INC = qw(. ../lib);
+ require 'test.pl';
}
-require 'test.pl';
-plan( tests => 13 );
+plan( tests => 14 );
@oops = @ops = <op/*>;
@@ -81,3 +81,9 @@ SKIP: {
}
cmp_ok(scalar(@oops),'>',0,'glob globbed something');
+
+# This test exists mainly for miniperl, to test that external calls to
+# csh, which clear %ENV first, leave $ENV{HOME}.
+# On Windows, external glob uses File::DosGlob which returns "~", so this
+# should pass anyway.
+ok <~>, '~ works';