From: Rafael Garcia-Suarez Date: Tue, 7 Jul 2009 09:04:13 +0000 (+0200) Subject: Fast enabling of strictures when version 5.11.0 is required X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5cc917d61a1b0b6683ece694d00cdb1abdf9c0d9;p=p5sagit%2Fp5-mst-13.2.git Fast enabling of strictures when version 5.11.0 is required We don't load strict.pm, we just manipulate the hint bits. Plus more tests. --- diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 878d206..2035795 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -6948,7 +6948,8 @@ Also, if the specified perl version is greater than or equal to 5.9.5, C will also load the C pragma and enable all features available in the requested version. See L. Similarly, if the specified perl version is greater than or equal to -5.11.0, strictures are enabled lexically as with C. +5.11.0, strictures are enabled lexically as with C (except +that the F file is not actually loaded). The C forces the C and C to happen at compile time. The C makes sure the module is loaded into memory if it hasn't been diff --git a/pp_ctl.c b/pp_ctl.c index 75d98dd..eab9624 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -3258,12 +3258,9 @@ PP(pp_require) /* If a version >= 5.11.0 is requested, strictures are on by default! */ if (PL_compcv && vcmp(sv, sv_2mortal(upg_version(newSVnv(5.011000), FALSE))) >= 0) { - ENTER; - Perl_load_module(aTHX_ 0, newSVpvs("strict"), NULL, NULL, NULL); - LEAVE; + PL_hints |= (HINT_STRICT_REFS | HINT_STRICT_SUBS | HINT_STRICT_VARS); } - RETPUSHYES; } name = SvPV_const(sv, len); diff --git a/t/comp/use.t b/t/comp/use.t index 30e41bb..8546123 100755 --- a/t/comp/use.t +++ b/t/comp/use.t @@ -6,7 +6,7 @@ BEGIN { $INC{"feature.pm"} = 1; # so we don't attempt to load feature.pm } -print "1..65\n"; +print "1..68\n"; # Can't require test.pl, as we're testing the use/require mechanism here. @@ -108,6 +108,15 @@ like ($@, qr/Perl v5.\d+.\d+ required--this is only \Q$^V\E, stopped/); # check that "use 5.11.0" (and higher) loads strictures eval 'use 5.11.0; ${"foo"} = "bar";'; like ($@, qr/Can't use string \("foo"\) as a SCALAR ref while "strict refs" in use/); +# but that they can be disabled +eval 'use 5.11.0; no strict "refs"; ${"foo"} = "bar";'; +is ($@, ""); +# and they are properly scoped +eval '{use 5.11.0;} ${"foo"} = "bar";'; +is ($@, ""); +# and this doesn't happen with require +eval 'require 5.11.0; ${"foo"} = "bar";'; +is ($@, ""); { use lib } # check that subparse saves pending tokens