diff options
author | Father Chrysostomos <sprout@cpan.org> | 2011-10-25 17:56:32 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2011-10-26 18:22:18 -0700 |
commit | d67594ff366291f164fb41e4dcc791494ec4bb0e (patch) | |
tree | 3ec3aa27ad2ba46ff773fe14e6a18e31c4882b07 /t/op | |
parent | 1bb8785ab1af03172a3a220f8948d33bdc3dd374 (diff) | |
download | perl-d67594ff366291f164fb41e4dcc791494ec4bb0e.tar.gz |
Fix CORE::glob
This commit makes CORE::glob bypassing glob overrides.
A side effect of the fix is that, with the default glob implementa-
tion, undefining *CORE::GLOBAL::glob no longer results in an ‘unde-
fined subroutine’ error.
Another side effect is that compilation of a glob op no longer assumes
that the loading of File::Glob will create the *CORE::GLOB::glob type-
glob. ‘++$INC{"File/Glob.pm"}; sub File::Glob::csh_glob; eval '<*>';’
used to crash.
This is accomplished using a mechanism similar to lock() and
threads::shared. There is a new PL_globhook interpreter varia-
ble that pp_glob calls when there is no override present. Thus,
File::Glob (which is supposed to be transparent, as it *is* the
built-in implementation) no longer interferes with the user mechanism
for overriding glob.
This removes one tier from the five or so hacks that constitute glob’s
implementation, and which work together to make it one of the buggiest
and most inconsistent areas of Perl.
Diffstat (limited to 't/op')
-rw-r--r-- | t/op/glob.t | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/t/op/glob.t b/t/op/glob.t index f26d7b3ade..3c64353736 100644 --- a/t/op/glob.t +++ b/t/op/glob.t @@ -6,7 +6,7 @@ BEGIN { require 'test.pl'; } -plan( tests => 14 ); +plan( tests => 17 ); @oops = @ops = <op/*>; @@ -60,6 +60,19 @@ cmp_ok($i,'==',2,'remove File::Glob stash'); eval "<.>"; ok(!length($@),"remove File::Glob stash *and* CORE::GLOBAL::glob"); } +# Also try undeffing the typeglob itself, instead of hiding it +{ + local *CORE::GLOBAL::glob; + ok eval { glob("0"); 1 }, + 'undefined *CORE::GLOBAL::glob{CODE} at run time'; +} +# And hide the typeglob without hiding File::Glob (crashes from 5.8 +# to 5.15.4) +{ + local %CORE::GLOBAL::; + ok eval q{ glob("0"); 1 }, + 'undefined *CORE::GLOBAL::glob{CODE} at compile time'; +} # ... while ($var = glob(...)) should test definedness not truth @@ -87,3 +100,10 @@ cmp_ok(scalar(@oops),'>',0,'glob globbed something'); # On Windows, external glob uses File::DosGlob which returns "~", so this # should pass anyway. ok <~>, '~ works'; + +{ + my $called; + local *CORE::GLOBAL::glob = sub { ++$called }; + eval 'CORE::glob("0")'; + ok !$called, 'CORE::glob bypasses overrides'; +} |