diff options
author | Father Chrysostomos <sprout@cpan.org> | 2012-09-13 23:46:46 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-09-14 22:29:45 -0700 |
commit | 7fc874e826a059bd024f1cbd568e1021c5731f35 (patch) | |
tree | 87c39161aa48a5e51e147ab2d5d8aabbd6abf775 /lib/warnings.pm | |
parent | f07626add3eda6dfda7c5f6fe05cbe1c9293ccd2 (diff) | |
download | perl-7fc874e826a059bd024f1cbd568e1021c5731f35.tar.gz |
Stop lexical warnings from turning off deprecations
Some warnings, such as deprecation warnings, are on by default:
$ perl5.16.0 -e '$*'
$* is no longer supported at -e line 1.
But turning *on* other warnings will turn them off:
$ perl5.16.0 -e 'use warnings "void"; $*'
Useless use of a variable in void context at -e line 1.
Either all warnings in any given scope are controlled by lexical
hints, or none of them are.
When a single warnings category is turned on or off, if the warn-
ings were controlled by $^W, then all warnings are first turned on
lexically if $^W is 1 and all warnings are turned off lexically
if $^W is 0.
That has the unfortunate affect of turning off warnings when it was
only requested that warnings be turned on.
These categories contain default warnings:
ambiguous
debugging
deprecated
inplace
internal
io
malloc
utf8
redefine
syntax
glob
inplace
overflow
precedence
prototype
threads
misc
Most also contain regular warnings, but these contain *only*
default warnings:
debugging
deprecated
glob
inplace
malloc
So we can treat $^W==0 as equivalent to qw(debugging deprecated glob
inplace malloc) when enabling lexical warnings.
While this means that some default warnings will still be turned off
by ‘use warnings "void"’, it won’t be as many as before. So at least
this is a step in the right direction.
(The real solution, of course, is to allow each warning to be turned
off or on on its own.)
Diffstat (limited to 'lib/warnings.pm')
-rw-r--r-- | lib/warnings.pm | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/warnings.pm b/lib/warnings.pm index 3b2d87dc82..934bdd49f5 100644 --- a/lib/warnings.pm +++ b/lib/warnings.pm @@ -336,6 +336,7 @@ our %DeadBits = ( ); $NONE = "\0\0\0\0\0\0\0\0\0\0\0\0\0"; +$DEFAULT = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x00", # [2,4,22,23,25] $LAST_BIT = 102 ; $BYTES = 13 ; @@ -387,7 +388,7 @@ sub import { shift; - my $mask = ${^WARNING_BITS} // ($^W ? $Bits{all} : $NONE) ; + my $mask = ${^WARNING_BITS} // ($^W ? $Bits{all} : $DEFAULT) ; if (vec($mask, $Offsets{'all'}, 1)) { $mask |= $Bits{'all'} ; @@ -403,7 +404,7 @@ sub unimport shift; my $catmask ; - my $mask = ${^WARNING_BITS} // ($^W ? $Bits{all} : $NONE) ; + my $mask = ${^WARNING_BITS} // ($^W ? $Bits{all} : $DEFAULT) ; if (vec($mask, $Offsets{'all'}, 1)) { $mask |= $Bits{'all'} ; @@ -482,8 +483,11 @@ sub __chk $i = _error_loc(); # see where Carp will allocate the error } - # Defaulting this to 0 reduces complexity in code paths below. - my $callers_bitmask = (caller($i))[9] || 0 ; + # Default to 0 if caller returns nothing. Default to $DEFAULT if it + # explicitly returns undef. + my(@callers_bitmask) = (caller($i))[9] ; + my $callers_bitmask = + @callers_bitmask ? $callers_bitmask[0] // $DEFAULT : 0 ; my @results; foreach my $type (FATAL, NORMAL) { |