1# -*- mode: Perl; buffer-read-only: t -*- 2# !!!!!!! DO NOT EDIT THIS FILE !!!!!!! 3# This file is built by regen/warnings.pl. 4# Any changes made here will be lost! 5 6package warnings; 7 8our $VERSION = "1.70"; 9 10# Verify that we're called correctly so that warnings will work. 11# Can't use Carp, since Carp uses us! 12# String regexps because constant folding = smaller optree = less memory vs regexp literal 13# see also strict.pm. 14die sprintf "Incorrect use of pragma '%s' at %s line %d.\n", __PACKAGE__, +(caller)[1,2] 15 if __FILE__ !~ ( '(?x) \b '.__PACKAGE__.' \.pmc? \z' ) 16 && __FILE__ =~ ( '(?x) \b (?i:'.__PACKAGE__.') \.pmc? \z' ); 17 18our %Offsets = ( 19 # Warnings Categories added in Perl 5.008 20 'all' => 0, 21 'closure' => 2, 22 'deprecated' => 4, 23 'exiting' => 6, 24 'glob' => 8, 25 'io' => 10, 26 'closed' => 12, 27 'exec' => 14, 28 'layer' => 16, 29 'newline' => 18, 30 'pipe' => 20, 31 'unopened' => 22, 32 'misc' => 24, 33 'numeric' => 26, 34 'once' => 28, 35 'overflow' => 30, 36 'pack' => 32, 37 'portable' => 34, 38 'recursion' => 36, 39 'redefine' => 38, 40 'regexp' => 40, 41 'severe' => 42, 42 'debugging' => 44, 43 'inplace' => 46, 44 'internal' => 48, 45 'malloc' => 50, 46 'signal' => 52, 47 'substr' => 54, 48 'syntax' => 56, 49 'ambiguous' => 58, 50 'bareword' => 60, 51 'digit' => 62, 52 'parenthesis' => 64, 53 'precedence' => 66, 54 'printf' => 68, 55 'prototype' => 70, 56 'qw' => 72, 57 'reserved' => 74, 58 'semicolon' => 76, 59 'taint' => 78, 60 'threads' => 80, 61 'uninitialized' => 82, 62 'unpack' => 84, 63 'untie' => 86, 64 'utf8' => 88, 65 'void' => 90, 66 67 # Warnings Categories added in Perl 5.011 68 'imprecision' => 92, 69 'illegalproto' => 94, 70 71 # Warnings Categories added in Perl 5.011003 72 'deprecated::goto_construct' => 96, 73 'deprecated::unicode_property_name' => 98, 74 75 # Warnings Categories added in Perl 5.013 76 'non_unicode' => 100, 77 'nonchar' => 102, 78 'surrogate' => 104, 79 80 # Warnings Categories added in Perl 5.017 81 'experimental' => 106, 82 'experimental::regex_sets' => 108, 83 84 # Warnings Categories added in Perl 5.019 85 'syscalls' => 110, 86 87 # Warnings Categories added in Perl 5.021 88 'experimental::re_strict' => 112, 89 'experimental::refaliasing' => 114, 90 'locale' => 116, 91 'missing' => 118, 92 'redundant' => 120, 93 94 # Warnings Categories added in Perl 5.025 95 'experimental::declared_refs' => 122, 96 97 # Warnings Categories added in Perl 5.025011 98 'deprecated::dot_in_inc' => 124, 99 100 # Warnings Categories added in Perl 5.027 101 'shadow' => 126, 102 103 # Warnings Categories added in Perl 5.029 104 'experimental::private_use' => 128, 105 'experimental::uniprop_wildcards' => 130, 106 'experimental::vlb' => 132, 107 108 # Warnings Categories added in Perl 5.033 109 'experimental::try' => 134, 110 111 # Warnings Categories added in Perl 5.035 112 'experimental::args_array_with_signatures'=> 136, 113 'experimental::builtin' => 138, 114 'experimental::defer' => 140, 115 'experimental::extra_paired_delimiters'=> 142, 116 'scalar' => 144, 117 118 # Warnings Categories added in Perl 5.035009 119 'deprecated::version_downgrade' => 146, 120 121 # Warnings Categories added in Perl 5.03501 122 'deprecated::delimiter_will_be_paired'=> 148, 123 124 # Warnings Categories added in Perl 5.037 125 'experimental::class' => 150, 126 127 # Warnings Categories added in Perl 5.037009 128 'deprecated::apostrophe_as_package_separator'=> 152, 129 130 # Warnings Categories added in Perl 5.03701 131 'deprecated::smartmatch' => 154, 132 133 # Warnings Categories added in Perl 5.039002 134 'deprecated::missing_import_called_with_args'=> 156, 135 136 # Warnings Categories added in Perl 5.039008 137 'deprecated::subsequent_use_version'=> 158, 138); 139 140our %Bits = ( 141 'all' => "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55", # [0..79] 142 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [29] 143 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [30] 144 'closed' => "\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6] 145 'closure' => "\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1] 146 'debugging' => "\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [22] 147 'deprecated' => "\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x10\x00\x00\x14\x55", # [2,48,49,62,73,74,76..79] 148 'deprecated::apostrophe_as_package_separator'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", # [76] 149 'deprecated::delimiter_will_be_paired'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00", # [74] 150 'deprecated::dot_in_inc' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00", # [62] 151 'deprecated::goto_construct' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00", # [48] 152 'deprecated::missing_import_called_with_args'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10", # [78] 153 'deprecated::smartmatch' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04", # [77] 154 'deprecated::subsequent_use_version'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40", # [79] 155 'deprecated::unicode_property_name' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00", # [49] 156 'deprecated::version_downgrade' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00", # [73] 157 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [31] 158 'exec' => "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7] 159 'exiting' => "\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3] 160 'experimental' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x14\x05\x04\x55\x55\x40\x00", # [53,54,56,57,61,64..71,75] 161 'experimental::args_array_with_signatures'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00", # [68] 162 'experimental::builtin' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00", # [69] 163 'experimental::class' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00", # [75] 164 'experimental::declared_refs' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00", # [61] 165 'experimental::defer' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00", # [70] 166 'experimental::extra_paired_delimiters'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00", # [71] 167 'experimental::private_use' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00", # [64] 168 'experimental::re_strict' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00", # [56] 169 'experimental::refaliasing' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00", # [57] 170 'experimental::regex_sets' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00", # [54] 171 'experimental::try' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00", # [67] 172 'experimental::uniprop_wildcards' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00", # [65] 173 'experimental::vlb' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00", # [66] 174 'glob' => "\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4] 175 'illegalproto' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00", # [47] 176 'imprecision' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00", # [46] 177 'inplace' => "\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [23] 178 'internal' => "\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [24] 179 'io' => "\x00\x54\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00", # [5..11,55] 180 'layer' => "\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8] 181 'locale' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00", # [58] 182 'malloc' => "\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [25] 183 'misc' => "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [12] 184 'missing' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00", # [59] 185 'newline' => "\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9] 186 'non_unicode' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00", # [50] 187 'nonchar' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00", # [51] 188 'numeric' => "\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [13] 189 'once' => "\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [14] 190 'overflow' => "\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [15] 191 'pack' => "\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [16] 192 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [32] 193 'pipe' => "\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10] 194 'portable' => "\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [17] 195 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [33] 196 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [34] 197 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [35] 198 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [36] 199 'recursion' => "\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [18] 200 'redefine' => "\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [19] 201 'redundant' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00", # [60] 202 'regexp' => "\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [20] 203 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [37] 204 'scalar' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00", # [72] 205 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [38] 206 'severe' => "\x00\x00\x00\x00\x00\x54\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [21..25] 207 'shadow' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00", # [63] 208 'signal' => "\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [26] 209 'substr' => "\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [27] 210 'surrogate' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00", # [52] 211 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\x55\x55\x15\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00", # [28..38,47] 212 'syscalls' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00", # [55] 213 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [39] 214 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [40] 215 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [41] 216 'unopened' => "\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11] 217 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [42] 218 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [43] 219 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x50\x01\x00\x00\x00\x00\x00\x00", # [44,50..52] 220 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00", # [45] 221); 222 223our %DeadBits = ( 224 'all' => "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", # [0..79] 225 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [29] 226 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [30] 227 'closed' => "\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6] 228 'closure' => "\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1] 229 'debugging' => "\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [22] 230 'deprecated' => "\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0a\x00\x00\x20\x00\x00\x28\xaa", # [2,48,49,62,73,74,76..79] 231 'deprecated::apostrophe_as_package_separator'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02", # [76] 232 'deprecated::delimiter_will_be_paired'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00", # [74] 233 'deprecated::dot_in_inc' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00", # [62] 234 'deprecated::goto_construct' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", # [48] 235 'deprecated::missing_import_called_with_args'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20", # [78] 236 'deprecated::smartmatch' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08", # [77] 237 'deprecated::subsequent_use_version'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80", # [79] 238 'deprecated::unicode_property_name' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00", # [49] 239 'deprecated::version_downgrade' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00", # [73] 240 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [31] 241 'exec' => "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7] 242 'exiting' => "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3] 243 'experimental' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x28\x0a\x08\xaa\xaa\x80\x00", # [53,54,56,57,61,64..71,75] 244 'experimental::args_array_with_signatures'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00", # [68] 245 'experimental::builtin' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00", # [69] 246 'experimental::class' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00", # [75] 247 'experimental::declared_refs' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00", # [61] 248 'experimental::defer' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00", # [70] 249 'experimental::extra_paired_delimiters'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00", # [71] 250 'experimental::private_use' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00", # [64] 251 'experimental::re_strict' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00", # [56] 252 'experimental::refaliasing' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00", # [57] 253 'experimental::regex_sets' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00", # [54] 254 'experimental::try' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00", # [67] 255 'experimental::uniprop_wildcards' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00", # [65] 256 'experimental::vlb' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00", # [66] 257 'glob' => "\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4] 258 'illegalproto' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00", # [47] 259 'imprecision' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00", # [46] 260 'inplace' => "\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [23] 261 'internal' => "\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [24] 262 'io' => "\x00\xa8\xaa\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00", # [5..11,55] 263 'layer' => "\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8] 264 'locale' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00", # [58] 265 'malloc' => "\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [25] 266 'misc' => "\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [12] 267 'missing' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00", # [59] 268 'newline' => "\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9] 269 'non_unicode' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00", # [50] 270 'nonchar' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00", # [51] 271 'numeric' => "\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [13] 272 'once' => "\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [14] 273 'overflow' => "\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [15] 274 'pack' => "\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [16] 275 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [32] 276 'pipe' => "\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10] 277 'portable' => "\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [17] 278 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [33] 279 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [34] 280 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [35] 281 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [36] 282 'recursion' => "\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [18] 283 'redefine' => "\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [19] 284 'redundant' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00", # [60] 285 'regexp' => "\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [20] 286 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [37] 287 'scalar' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00", # [72] 288 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [38] 289 'severe' => "\x00\x00\x00\x00\x00\xa8\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [21..25] 290 'shadow' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00", # [63] 291 'signal' => "\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [26] 292 'substr' => "\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [27] 293 'surrogate' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00", # [52] 294 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\xaa\xaa\x2a\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00", # [28..38,47] 295 'syscalls' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00", # [55] 296 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [39] 297 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [40] 298 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [41] 299 'unopened' => "\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11] 300 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [42] 301 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [43] 302 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\xa0\x02\x00\x00\x00\x00\x00\x00", # [44,50..52] 303 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00", # [45] 304); 305 306our %NoOp = ( 307 'experimental::alpha_assertions' => 1, 308 'experimental::bitwise' => 1, 309 'experimental::const_attr' => 1, 310 'experimental::for_list' => 1, 311 'experimental::isa' => 1, 312 'experimental::lexical_subs' => 1, 313 'experimental::postderef' => 1, 314 'experimental::script_run' => 1, 315 'experimental::signatures' => 1, 316 'experimental::smartmatch' => 1, 317); 318 319# These are used by various things, including our own tests 320our $NONE = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; 321our $DEFAULT = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x05\x00\x15\x14\x55\x55\x54\x55"; # [2,4,22,23,25,48,49,56..58,61,62,64..71,73..79] 322our $LAST_BIT = 160 ; 323our $BYTES = 20 ; 324 325sub Croaker 326{ 327 require Carp; # this initializes %CarpInternal 328 local $Carp::CarpInternal{'warnings'}; 329 delete $Carp::CarpInternal{'warnings'}; 330 Carp::croak(@_); 331} 332 333sub _expand_bits { 334 my $bits = shift; 335 my $want_len = ($LAST_BIT + 7) >> 3; 336 my $len = length($bits); 337 if ($len != $want_len) { 338 if ($bits eq "") { 339 $bits = "\x00" x $want_len; 340 } elsif ($len > $want_len) { 341 substr $bits, $want_len, $len-$want_len, ""; 342 } else { 343 my $x = vec($bits, $Offsets{all} >> 1, 2); 344 $x |= $x << 2; 345 $x |= $x << 4; 346 $bits .= chr($x) x ($want_len - $len); 347 } 348 } 349 return $bits; 350} 351 352sub _bits { 353 my $mask = shift ; 354 my $catmask ; 355 my $fatal = 0 ; 356 my $no_fatal = 0 ; 357 358 $mask = _expand_bits($mask); 359 foreach my $word ( @_ ) { 360 next if $NoOp{$word}; 361 if ($word eq 'FATAL') { 362 $fatal = 1; 363 $no_fatal = 0; 364 } 365 elsif ($word eq 'NONFATAL') { 366 $fatal = 0; 367 $no_fatal = 1; 368 } 369 elsif ($catmask = $Bits{$word}) { 370 $mask |= $catmask ; 371 $mask |= $DeadBits{$word} if $fatal ; 372 $mask = ~(~$mask | $DeadBits{$word}) if $no_fatal ; 373 } 374 else 375 { Croaker("Unknown warnings category '$word'")} 376 } 377 378 return $mask ; 379} 380 381sub bits 382{ 383 # called from B::Deparse.pm 384 push @_, 'all' unless @_ ; 385 return _bits("", @_) ; 386} 387 388sub import 389{ 390 my $invocant = shift; 391 392 # append 'all' when implied (empty import list or after a lone 393 # "FATAL" or "NONFATAL") 394 push @_, 'all' 395 if !@_ || (@_==1 && ($_[0] eq 'FATAL' || $_[0] eq 'NONFATAL')); 396 397 my @fatal = (); 398 foreach my $warning (@_) { 399 if($warning =~ /^(NON)?FATAL$/) { 400 @fatal = ($warning); 401 } elsif(substr($warning, 0, 1) ne '-') { 402 my $mask = ${^WARNING_BITS} // ($^W ? $Bits{all} : $DEFAULT) ; 403 ${^WARNING_BITS} = _bits($mask, @fatal, $warning); 404 } else { 405 $invocant->unimport(substr($warning, 1)); 406 } 407 } 408} 409 410sub unimport 411{ 412 shift; 413 414 my $catmask ; 415 my $mask = ${^WARNING_BITS} // ($^W ? $Bits{all} : $DEFAULT) ; 416 417 # append 'all' when implied (empty import list or after a lone "FATAL") 418 push @_, 'all' if !@_ || @_==1 && $_[0] eq 'FATAL'; 419 420 $mask = _expand_bits($mask); 421 foreach my $word ( @_ ) { 422 next if $NoOp{$word}; 423 if ($word eq 'FATAL') { 424 next; 425 } 426 elsif ($catmask = $Bits{$word}) { 427 $mask = ~(~$mask | $catmask | $DeadBits{$word}); 428 } 429 else 430 { Croaker("Unknown warnings category '$word'")} 431 } 432 433 ${^WARNING_BITS} = $mask ; 434} 435 436my %builtin_type; @builtin_type{qw(SCALAR ARRAY HASH CODE REF GLOB LVALUE Regexp)} = (); 437 438sub LEVEL () { 8 }; 439sub MESSAGE () { 4 }; 440sub FATAL () { 2 }; 441sub NORMAL () { 1 }; 442 443sub __chk 444{ 445 my $category ; 446 my $offset ; 447 my $isobj = 0 ; 448 my $wanted = shift; 449 my $has_message = $wanted & MESSAGE; 450 my $has_level = $wanted & LEVEL ; 451 452 if ($has_level) { 453 if (@_ != ($has_message ? 3 : 2)) { 454 my $sub = (caller 1)[3]; 455 my $syntax = $has_message 456 ? "category, level, 'message'" 457 : 'category, level'; 458 Croaker("Usage: $sub($syntax)"); 459 } 460 } 461 elsif (not @_ == 1 || @_ == ($has_message ? 2 : 0)) { 462 my $sub = (caller 1)[3]; 463 my $syntax = $has_message ? "[category,] 'message'" : '[category]'; 464 Croaker("Usage: $sub($syntax)"); 465 } 466 467 my $message = pop if $has_message; 468 469 if (@_) { 470 # check the category supplied. 471 $category = shift ; 472 if (my $type = ref $category) { 473 Croaker("not an object") 474 if exists $builtin_type{$type}; 475 $category = $type; 476 $isobj = 1 ; 477 } 478 $offset = $Offsets{$category}; 479 Croaker("Unknown warnings category '$category'") 480 unless defined $offset; 481 } 482 else { 483 $category = caller(1); 484 $offset = $Offsets{$category}; 485 Croaker("package '$category' not registered for warnings") 486 unless defined $offset ; 487 } 488 489 my $i; 490 491 if ($isobj) { 492 my $pkg; 493 $i = 2; 494 while (do { { package DB; $pkg = (caller($i++))[0] } } ) { 495 last unless @DB::args && $DB::args[0] =~ /^$category=/ ; 496 } 497 $i -= 2 ; 498 } 499 elsif ($has_level) { 500 $i = 2 + shift; 501 } 502 else { 503 $i = _error_loc(); # see where Carp will allocate the error 504 } 505 506 # Default to 0 if caller returns nothing. Default to $DEFAULT if it 507 # explicitly returns undef. 508 my(@callers_bitmask) = (caller($i))[9] ; 509 my $callers_bitmask = 510 @callers_bitmask ? $callers_bitmask[0] // $DEFAULT : 0 ; 511 length($callers_bitmask) > ($offset >> 3) or $offset = $Offsets{all}; 512 513 my @results; 514 foreach my $type (FATAL, NORMAL) { 515 next unless $wanted & $type; 516 517 push @results, vec($callers_bitmask, $offset + $type - 1, 1); 518 } 519 520 # &enabled and &fatal_enabled 521 return $results[0] unless $has_message; 522 523 # &warnif, and the category is neither enabled as warning nor as fatal 524 return if ($wanted & (NORMAL | FATAL | MESSAGE)) 525 == (NORMAL | FATAL | MESSAGE) 526 && !($results[0] || $results[1]); 527 528 # If we have an explicit level, bypass Carp. 529 if ($has_level and @callers_bitmask) { 530 # logic copied from util.c:mess_sv 531 my $stuff = " at " . join " line ", (caller $i)[1,2]; 532 $stuff .= sprintf ", <%s> %s %d", 533 *${^LAST_FH}{NAME}, 534 ($/ eq "\n" ? "line" : "chunk"), $. 535 if $. && ${^LAST_FH}; 536 die "$message$stuff.\n" if $results[0]; 537 return warn "$message$stuff.\n"; 538 } 539 540 require Carp; 541 Carp::croak($message) if $results[0]; 542 # will always get here for &warn. will only get here for &warnif if the 543 # category is enabled 544 Carp::carp($message); 545} 546 547sub _mkMask 548{ 549 my ($bit) = @_; 550 my $mask = ""; 551 552 vec($mask, $bit, 1) = 1; 553 return $mask; 554} 555 556sub register_categories 557{ 558 my @names = @_; 559 560 for my $name (@names) { 561 if (! defined $Bits{$name}) { 562 $Offsets{$name} = $LAST_BIT; 563 $Bits{$name} = _mkMask($LAST_BIT++); 564 $DeadBits{$name} = _mkMask($LAST_BIT++); 565 if (length($Bits{$name}) > length($Bits{all})) { 566 $Bits{all} .= "\x55"; 567 $DeadBits{all} .= "\xaa"; 568 } 569 } 570 } 571} 572 573sub _error_loc { 574 require Carp; 575 goto &Carp::short_error_loc; # don't introduce another stack frame 576} 577 578sub enabled 579{ 580 return __chk(NORMAL, @_); 581} 582 583sub fatal_enabled 584{ 585 return __chk(FATAL, @_); 586} 587 588sub warn 589{ 590 return __chk(FATAL | MESSAGE, @_); 591} 592 593sub warnif 594{ 595 return __chk(NORMAL | FATAL | MESSAGE, @_); 596} 597 598sub enabled_at_level 599{ 600 return __chk(NORMAL | LEVEL, @_); 601} 602 603sub fatal_enabled_at_level 604{ 605 return __chk(FATAL | LEVEL, @_); 606} 607 608sub warn_at_level 609{ 610 return __chk(FATAL | MESSAGE | LEVEL, @_); 611} 612 613sub warnif_at_level 614{ 615 return __chk(NORMAL | FATAL | MESSAGE | LEVEL, @_); 616} 617 618# These are not part of any public interface, so we can delete them to save 619# space. 620delete @warnings::{qw(NORMAL FATAL MESSAGE LEVEL)}; 621 6221; 623__END__ 624 625=head1 NAME 626 627warnings - Perl pragma to control optional warnings 628 629=head1 SYNOPSIS 630 631 use warnings; 632 no warnings; 633 634 # Standard warnings are enabled by use v5.35 or above 635 use v5.35; 636 637 use warnings "all"; 638 no warnings "uninitialized"; 639 640 # or equivalent to those last two ... 641 use warnings qw(all -uninitialized); 642 643 use warnings::register; 644 if (warnings::enabled()) { 645 warnings::warn("some warning"); 646 } 647 648 if (warnings::enabled("void")) { 649 warnings::warn("void", "some warning"); 650 } 651 652 if (warnings::enabled($object)) { 653 warnings::warn($object, "some warning"); 654 } 655 656 warnings::warnif("some warning"); 657 warnings::warnif("void", "some warning"); 658 warnings::warnif($object, "some warning"); 659 660=head1 DESCRIPTION 661 662The C<warnings> pragma gives control over which warnings are enabled in 663which parts of a Perl program. It's a more flexible alternative for 664both the command line flag B<-w> and the equivalent Perl variable, 665C<$^W>. 666 667This pragma works just like the C<strict> pragma. 668This means that the scope of the warning pragma is limited to the 669enclosing block. It also means that the pragma setting will not 670leak across files (via C<use>, C<require> or C<do>). This allows 671authors to independently define the degree of warning checks that will 672be applied to their module. 673 674By default, optional warnings are disabled, so any legacy code that 675doesn't attempt to control the warnings will work unchanged. 676 677All warnings are enabled in a block by either of these: 678 679 use warnings; 680 use warnings 'all'; 681 682Similarly all warnings are disabled in a block by either of these: 683 684 no warnings; 685 no warnings 'all'; 686 687For example, consider the code below: 688 689 use warnings; 690 my @x; 691 { 692 no warnings; 693 my $y = @x[0]; 694 } 695 my $z = @x[0]; 696 697The code in the enclosing block has warnings enabled, but the inner 698block has them disabled. In this case that means the assignment to the 699scalar C<$z> will trip the C<"Scalar value @x[0] better written as $x[0]"> 700warning, but the assignment to the scalar C<$y> will not. 701 702All warnings are enabled automatically within the scope of 703a C<L<use v5.35|perlfunc/use VERSION>> (or higher) declaration. 704 705=head2 Default Warnings and Optional Warnings 706 707Before the introduction of lexical warnings, Perl had two classes of 708warnings: mandatory and optional. 709 710As its name suggests, if your code tripped a mandatory warning, you 711would get a warning whether you wanted it or not. 712For example, the code below would always produce an C<"isn't numeric"> 713warning about the "2:". 714 715 my $x = "2:" + 3; 716 717With the introduction of lexical warnings, mandatory warnings now become 718I<default> warnings. The difference is that although the previously 719mandatory warnings are still enabled by default, they can then be 720subsequently enabled or disabled with the lexical warning pragma. For 721example, in the code below, an C<"isn't numeric"> warning will only 722be reported for the C<$x> variable. 723 724 my $x = "2:" + 3; 725 no warnings; 726 my $y = "2:" + 3; 727 728Note that neither the B<-w> flag or the C<$^W> can be used to 729disable/enable default warnings. They are still mandatory in this case. 730 731=head2 "Negative warnings" 732 733As a convenience, you can (as of Perl 5.34) pass arguments to the 734C<import()> method both positively and negatively. Negative warnings 735are those with a C<-> sign prepended to their names; positive warnings 736are anything else. This lets you turn on some warnings and turn off 737others in one command. So, assuming that you've already turned on a 738bunch of warnings but want to tweak them a bit in some block, you can 739do this: 740 741 { 742 use warnings qw(uninitialized -redefine); 743 ... 744 } 745 746which is equivalent to: 747 748 { 749 use warnings qw(uninitialized); 750 no warnings qw(redefine); 751 ... 752 } 753 754The argument list is processed in the order you specify. So, for example, if you 755don't want to be warned about use of experimental features, except for C<somefeature> 756that you really dislike, you can say this: 757 758 use warnings qw(all -experimental experimental::somefeature); 759 760which is equivalent to: 761 762 use warnings 'all'; 763 no warnings 'experimental'; 764 use warnings 'experimental::somefeature'; 765 766As experimental features become regular features of Perl, 767the corresponding warnings are not printed anymore. 768They also stop being listed in the L</Category Hierarchy> below. 769 770It is still possible to request turning on or off these warnings, 771but doing so has no effect. 772 773=head2 What's wrong with B<-w> and C<$^W> 774 775Although very useful, the big problem with using B<-w> on the command 776line to enable warnings is that it is all or nothing. Take the typical 777scenario when you are writing a Perl program. Parts of the code you 778will write yourself, but it's very likely that you will make use of 779pre-written Perl modules. If you use the B<-w> flag in this case, you 780end up enabling warnings in pieces of code that you haven't written. 781 782Similarly, using C<$^W> to either disable or enable blocks of code is 783fundamentally flawed. For a start, say you want to disable warnings in 784a block of code. You might expect this to be enough to do the trick: 785 786 { 787 local ($^W) = 0; 788 my $x =+ 2; 789 my $y; chop $y; 790 } 791 792When this code is run with the B<-w> flag, a warning will be produced 793for the C<$x> line: C<"Reversed += operator">. 794 795The problem is that Perl has both compile-time and run-time warnings. To 796disable compile-time warnings you need to rewrite the code like this: 797 798 { 799 BEGIN { $^W = 0 } 800 my $x =+ 2; 801 my $y; chop $y; 802 } 803 804And note that unlike the first example, this will permanently set C<$^W> 805since it cannot both run during compile-time and be localized to a 806run-time block. 807 808The other big problem with C<$^W> is the way you can inadvertently 809change the warning setting in unexpected places in your code. For example, 810when the code below is run (without the B<-w> flag), the second call 811to C<doit> will trip a C<"Use of uninitialized value"> warning, whereas 812the first will not. 813 814 sub doit 815 { 816 my $y; chop $y; 817 } 818 819 doit(); 820 821 { 822 local ($^W) = 1; 823 doit() 824 } 825 826This is a side-effect of C<$^W> being dynamically scoped. 827 828Lexical warnings get around these limitations by allowing finer control 829over where warnings can or can't be tripped. 830 831=head2 Controlling Warnings from the Command Line 832 833There are three Command Line flags that can be used to control when 834warnings are (or aren't) produced: 835 836=over 5 837 838=item B<-w> 839X<-w> 840 841This is the existing flag. If the lexical warnings pragma is B<not> 842used in any of your code, or any of the modules that you use, this flag 843will enable warnings everywhere. See L</Backward Compatibility> for 844details of how this flag interacts with lexical warnings. 845 846=item B<-W> 847X<-W> 848 849If the B<-W> flag is used on the command line, it will enable all warnings 850throughout the program regardless of whether warnings were disabled 851locally using C<no warnings> or C<$^W =0>. 852This includes all files that get 853included via C<use>, C<require> or C<do>. 854Think of it as the Perl equivalent of the "lint" command. 855 856=item B<-X> 857X<-X> 858 859Does the exact opposite to the B<-W> flag, i.e. it disables all warnings. 860 861=back 862 863=head2 Backward Compatibility 864 865If you are used to working with a version of Perl prior to the 866introduction of lexically scoped warnings, or have code that uses both 867lexical warnings and C<$^W>, this section will describe how they interact. 868 869How Lexical Warnings interact with B<-w>/C<$^W>: 870 871=over 5 872 873=item 1. 874 875If none of the three command line flags (B<-w>, B<-W> or B<-X>) that 876control warnings is used and neither C<$^W> nor the C<warnings> pragma 877are used, then default warnings will be enabled and optional warnings 878disabled. 879This means that legacy code that doesn't attempt to control the warnings 880will work unchanged. 881 882=item 2. 883 884The B<-w> flag just sets the global C<$^W> variable as in 5.005. This 885means that any legacy code that currently relies on manipulating C<$^W> 886to control warning behavior will still work as is. 887 888=item 3. 889 890Apart from now being a boolean, the C<$^W> variable operates in exactly 891the same horrible uncontrolled global way, except that it cannot 892disable/enable default warnings. 893 894=item 4. 895 896If a piece of code is under the control of the C<warnings> pragma, 897both the C<$^W> variable and the B<-w> flag will be ignored for the 898scope of the lexical warning. 899 900=item 5. 901 902The only way to override a lexical warnings setting is with the B<-W> 903or B<-X> command line flags. 904 905=back 906 907The combined effect of 3 & 4 is that it will allow code which uses 908the C<warnings> pragma to control the warning behavior of $^W-type 909code (using a C<local $^W=0>) if it really wants to, but not vice-versa. 910 911=head2 Category Hierarchy 912X<warning, categories> 913 914A hierarchy of "categories" have been defined to allow groups of warnings 915to be enabled/disabled in isolation. 916 917The current hierarchy is: 918 919 all -+ 920 | 921 +- closure 922 | 923 +- deprecated ----+ 924 | | 925 | +- deprecated::apostrophe_as_package_separator 926 | | 927 | +- deprecated::delimiter_will_be_paired 928 | | 929 | +- deprecated::dot_in_inc 930 | | 931 | +- deprecated::goto_construct 932 | | 933 | +- deprecated::missing_import_called_with_args 934 | | 935 | +- deprecated::smartmatch 936 | | 937 | +- deprecated::subsequent_use_version 938 | | 939 | +- deprecated::unicode_property_name 940 | | 941 | +- deprecated::version_downgrade 942 | 943 +- exiting 944 | 945 +- experimental --+ 946 | | 947 | +- experimental::args_array_with_signatures 948 | | 949 | +- experimental::builtin 950 | | 951 | +- experimental::class 952 | | 953 | +- experimental::declared_refs 954 | | 955 | +- experimental::defer 956 | | 957 | +- experimental::extra_paired_delimiters 958 | | 959 | +- experimental::private_use 960 | | 961 | +- experimental::re_strict 962 | | 963 | +- experimental::refaliasing 964 | | 965 | +- experimental::regex_sets 966 | | 967 | +- experimental::try 968 | | 969 | +- experimental::uniprop_wildcards 970 | | 971 | +- experimental::vlb 972 | 973 +- glob 974 | 975 +- imprecision 976 | 977 +- io ------------+ 978 | | 979 | +- closed 980 | | 981 | +- exec 982 | | 983 | +- layer 984 | | 985 | +- newline 986 | | 987 | +- pipe 988 | | 989 | +- syscalls 990 | | 991 | +- unopened 992 | 993 +- locale 994 | 995 +- misc 996 | 997 +- missing 998 | 999 +- numeric 1000 | 1001 +- once 1002 | 1003 +- overflow 1004 | 1005 +- pack 1006 | 1007 +- portable 1008 | 1009 +- recursion 1010 | 1011 +- redefine 1012 | 1013 +- redundant 1014 | 1015 +- regexp 1016 | 1017 +- scalar 1018 | 1019 +- severe --------+ 1020 | | 1021 | +- debugging 1022 | | 1023 | +- inplace 1024 | | 1025 | +- internal 1026 | | 1027 | +- malloc 1028 | 1029 +- shadow 1030 | 1031 +- signal 1032 | 1033 +- substr 1034 | 1035 +- syntax --------+ 1036 | | 1037 | +- ambiguous 1038 | | 1039 | +- bareword 1040 | | 1041 | +- digit 1042 | | 1043 | +- illegalproto 1044 | | 1045 | +- parenthesis 1046 | | 1047 | +- precedence 1048 | | 1049 | +- printf 1050 | | 1051 | +- prototype 1052 | | 1053 | +- qw 1054 | | 1055 | +- reserved 1056 | | 1057 | +- semicolon 1058 | 1059 +- taint 1060 | 1061 +- threads 1062 | 1063 +- uninitialized 1064 | 1065 +- unpack 1066 | 1067 +- untie 1068 | 1069 +- utf8 ----------+ 1070 | | 1071 | +- non_unicode 1072 | | 1073 | +- nonchar 1074 | | 1075 | +- surrogate 1076 | 1077 +- void 1078 1079Just like the "strict" pragma any of these categories can be combined 1080 1081 use warnings qw(void redefine); 1082 no warnings qw(io syntax untie); 1083 1084Also like the "strict" pragma, if there is more than one instance of the 1085C<warnings> pragma in a given scope the cumulative effect is additive. 1086 1087 use warnings qw(void); # only "void" warnings enabled 1088 ... 1089 use warnings qw(io); # only "void" & "io" warnings enabled 1090 ... 1091 no warnings qw(void); # only "io" warnings enabled 1092 1093To determine which category a specific warning has been assigned to see 1094L<perldiag>. 1095 1096Note: Before Perl 5.8.0, the lexical warnings category "deprecated" was a 1097sub-category of the "syntax" category. It is now a top-level category 1098in its own right. 1099 1100Note: Before 5.21.0, the "missing" lexical warnings category was 1101internally defined to be the same as the "uninitialized" category. It 1102is now a top-level category in its own right. 1103 1104=head2 Fatal Warnings 1105X<warning, fatal> 1106 1107The presence of the word "FATAL" in the category list will escalate 1108warnings in those categories into fatal errors in that lexical scope. 1109 1110B<NOTE:> FATAL warnings should be used with care, particularly 1111C<< FATAL => 'all' >>. 1112 1113Libraries using L<warnings::warn|/FUNCTIONS> for custom warning categories 1114generally don't expect L<warnings::warn|/FUNCTIONS> to be fatal and can wind up 1115in an unexpected state as a result. For XS modules issuing categorized 1116warnings, such unanticipated exceptions could also expose memory leak bugs. 1117 1118Moreover, the Perl interpreter itself has had serious bugs involving 1119fatalized warnings. For a summary of resolved and unresolved problems as 1120of January 2015, please see 1121L<this perl5-porters post|http://www.nntp.perl.org/group/perl.perl5.porters/2015/01/msg225235.html>. 1122 1123While some developers find fatalizing some warnings to be a useful 1124defensive programming technique, using C<< FATAL => 'all' >> to fatalize 1125all possible warning categories -- including custom ones -- is particularly 1126risky. Therefore, the use of C<< FATAL => 'all' >> is 1127L<discouraged|perlpolicy/discouraged>. 1128 1129The L<strictures|strictures/VERSION-2> module on CPAN offers one example of 1130a warnings subset that the module's authors believe is relatively safe to 1131fatalize. 1132 1133B<NOTE:> Users of FATAL warnings, especially those using 1134C<< FATAL => 'all' >>, should be fully aware that they are risking future 1135portability of their programs by doing so. Perl makes absolutely no 1136commitments to not introduce new warnings or warnings categories in the 1137future; indeed, we explicitly reserve the right to do so. Code that may 1138not warn now may warn in a future release of Perl if the Perl5 development 1139team deems it in the best interests of the community to do so. Should code 1140using FATAL warnings break due to the introduction of a new warning we will 1141NOT consider it an incompatible change. Users of FATAL warnings should 1142take special caution during upgrades to check to see if their code triggers 1143any new warnings and should pay particular attention to the fine print of 1144the documentation of the features they use to ensure they do not exploit 1145features that are documented as risky, deprecated, or unspecified, or where 1146the documentation says "so don't do that", or anything with the same sense 1147and spirit. Use of such features in combination with FATAL warnings is 1148ENTIRELY AT THE USER'S RISK. 1149 1150The following documentation describes how to use FATAL warnings but the 1151perl5 porters strongly recommend that you understand the risks before doing 1152so, especially for library code intended for use by others, as there is no 1153way for downstream users to change the choice of fatal categories. 1154 1155In the code below, the use of C<time>, C<length> 1156and C<join> can all produce a C<"Useless use of xxx in void context"> 1157warning. 1158 1159 use warnings; 1160 1161 time; 1162 1163 { 1164 use warnings FATAL => qw(void); 1165 length "abc"; 1166 } 1167 1168 join "", 1,2,3; 1169 1170 print "done\n"; 1171 1172When run it produces this output 1173 1174 Useless use of time in void context at fatal line 3. 1175 Useless use of length in void context at fatal line 7. 1176 1177The scope where C<length> is used has escalated the C<void> warnings 1178category into a fatal error, so the program terminates immediately when it 1179encounters the warning. 1180 1181To explicitly turn off a "FATAL" warning you just disable the warning 1182it is associated with. So, for example, to disable the "void" warning 1183in the example above, either of these will do the trick: 1184 1185 no warnings qw(void); 1186 no warnings FATAL => qw(void); 1187 1188If you want to downgrade a warning that has been escalated into a fatal 1189error back to a normal warning, you can use the "NONFATAL" keyword. For 1190example, the code below will promote all warnings into fatal errors, 1191except for those in the "syntax" category. 1192 1193 use warnings FATAL => 'all', NONFATAL => 'syntax'; 1194 1195As of Perl 5.20, instead of C<< use warnings FATAL => 'all'; >> you can 1196use: 1197 1198 use v5.20; # Perl 5.20 or greater is required for the following 1199 use warnings 'FATAL'; # short form of "use warnings FATAL => 'all';" 1200 1201However, you should still heed the guidance earlier in this section against 1202using C<< use warnings FATAL => 'all'; >>. 1203 1204If you want your program to be compatible with versions of Perl before 12055.20, you must use C<< use warnings FATAL => 'all'; >> instead. (In 1206previous versions of Perl, the behavior of the statements 1207C<< use warnings 'FATAL'; >>, C<< use warnings 'NONFATAL'; >> and 1208C<< no warnings 'FATAL'; >> was unspecified; they did not behave as if 1209they included the C<< => 'all' >> portion. As of 5.20, they do.) 1210 1211=head2 Reporting Warnings from a Module 1212X<warning, reporting> X<warning, registering> 1213 1214The C<warnings> pragma provides a number of functions that are useful for 1215module authors. These are used when you want to report a module-specific 1216warning to a calling module that has enabled warnings via the C<warnings> 1217pragma. 1218 1219Consider the module C<MyMod::Abc> below. 1220 1221 package MyMod::Abc; 1222 1223 use warnings::register; 1224 1225 sub open { 1226 my $path = shift; 1227 if ($path !~ m#^/#) { 1228 warnings::warn("changing relative path to /var/abc") 1229 if warnings::enabled(); 1230 $path = "/var/abc/$path"; 1231 } 1232 } 1233 1234 1; 1235 1236The call to C<warnings::register> will create a new warnings category 1237called "MyMod::Abc", i.e. the new category name matches the current 1238package name. The C<open> function in the module will display a warning 1239message if it gets given a relative path as a parameter. This warning 1240will only be displayed if the code that uses C<MyMod::Abc> has actually 1241enabled them with the C<warnings> pragma as below - note that a plain 1242C<use warnings> enables even warnings that have not yet been registered. 1243 1244 use warnings; 1245 use MyMod::Abc; 1246 ... 1247 abc::open("../fred.txt"); 1248 1249The specific warning can be enabled or disabled, but only after the module 1250has been imported: 1251 1252 # no warnings 'MyMod::Abc'; # error, unknown category before 1253 # the module is loaded 1254 use MyMod::Abc; 1255 no warnings 'MyMod::Abc'; # ok after the module is loaded 1256 ... 1257 abc::open("../fred.txt"); 1258 1259It is also possible to test whether the pre-defined warnings categories are 1260set in the calling module with the C<warnings::enabled> function. Consider 1261this snippet of code: 1262 1263 package MyMod::Abc; 1264 1265 sub open2 { 1266 if (warnings::enabled("deprecated")) { 1267 warnings::warn("deprecated", 1268 "open2 is deprecated, use open instead"); 1269 } 1270 open(@_); 1271 } 1272 1273 sub open 1274 ... 1275 1; 1276 1277The function C<open2> has been deprecated, so code has been included to 1278display a warning message whenever the calling module has (at least) the 1279"deprecated" warnings category enabled. Something like this, say. 1280 1281 use warnings 'deprecated'; 1282 use MyMod::Abc; 1283 ... 1284 MyMod::Abc::open2($filename); 1285 1286Either the C<warnings::warn> or C<warnings::warnif> function should be 1287used to actually display the warnings message. This is because they can 1288make use of the feature that allows warnings to be escalated into fatal 1289errors. So in this case 1290 1291 use MyMod::Abc; 1292 use warnings FATAL => 'MyMod::Abc'; 1293 ... 1294 MyMod::Abc::open('../fred.txt'); 1295 1296the C<warnings::warnif> function will detect this and die after 1297displaying the warning message. 1298 1299The three warnings functions, C<warnings::warn>, C<warnings::warnif> 1300and C<warnings::enabled> can optionally take an object reference in place 1301of a category name. In this case the functions will use the class name 1302of the object as the warnings category. 1303 1304Consider this example: 1305 1306 package Original; 1307 1308 no warnings; 1309 use warnings::register; 1310 1311 sub new 1312 { 1313 my $class = shift; 1314 bless [], $class; 1315 } 1316 1317 sub check 1318 { 1319 my $self = shift; 1320 my $value = shift; 1321 1322 if ($value % 2 && warnings::enabled($self)) 1323 { warnings::warn($self, "Odd numbers are unsafe") } 1324 } 1325 1326 sub doit 1327 { 1328 my $self = shift; 1329 my $value = shift; 1330 $self->check($value); 1331 # ... 1332 } 1333 1334 1; 1335 1336 package Derived; 1337 1338 use warnings::register; 1339 use Original; 1340 our @ISA = qw( Original ); 1341 sub new 1342 { 1343 my $class = shift; 1344 bless [], $class; 1345 } 1346 1347 1348 1; 1349 1350The code below makes use of both modules, but it only enables warnings from 1351C<Derived>. 1352 1353 use Original; 1354 use Derived; 1355 use warnings 'Derived'; 1356 my $x = Original->new(); 1357 $x->doit(1); 1358 my $y = Derived->new(); 1359 $x->doit(1); 1360 1361When this code is run only the C<Derived> object, C<$y>, will generate 1362a warning. 1363 1364 Odd numbers are unsafe at main.pl line 7 1365 1366Notice also that the warning is reported at the line where the object is first 1367used. 1368 1369When registering new categories of warning, you can supply more names to 1370warnings::register like this: 1371 1372 package MyModule; 1373 use warnings::register qw(format precision); 1374 1375 ... 1376 1377 warnings::warnif('MyModule::format', '...'); 1378 1379=head1 FUNCTIONS 1380 1381Note: The functions with names ending in C<_at_level> were added in Perl 13825.28. 1383 1384=over 4 1385 1386=item use warnings::register 1387 1388Creates a new warnings category with the same name as the package where 1389the call to the pragma is used. 1390 1391=item warnings::enabled() 1392 1393Use the warnings category with the same name as the current package. 1394 1395Return TRUE if that warnings category is enabled in the calling module. 1396Otherwise returns FALSE. 1397 1398=item warnings::enabled($category) 1399 1400Return TRUE if the warnings category, C<$category>, is enabled in the 1401calling module. 1402Otherwise returns FALSE. 1403 1404=item warnings::enabled($object) 1405 1406Use the name of the class for the object reference, C<$object>, as the 1407warnings category. 1408 1409Return TRUE if that warnings category is enabled in the first scope 1410where the object is used. 1411Otherwise returns FALSE. 1412 1413=item warnings::enabled_at_level($category, $level) 1414 1415Like C<warnings::enabled>, but $level specifies the exact call frame, 0 1416being the immediate caller. 1417 1418=item warnings::fatal_enabled() 1419 1420Return TRUE if the warnings category with the same name as the current 1421package has been set to FATAL in the calling module. 1422Otherwise returns FALSE. 1423 1424=item warnings::fatal_enabled($category) 1425 1426Return TRUE if the warnings category C<$category> has been set to FATAL in 1427the calling module. 1428Otherwise returns FALSE. 1429 1430=item warnings::fatal_enabled($object) 1431 1432Use the name of the class for the object reference, C<$object>, as the 1433warnings category. 1434 1435Return TRUE if that warnings category has been set to FATAL in the first 1436scope where the object is used. 1437Otherwise returns FALSE. 1438 1439=item warnings::fatal_enabled_at_level($category, $level) 1440 1441Like C<warnings::fatal_enabled>, but $level specifies the exact call frame, 14420 being the immediate caller. 1443 1444=item warnings::warn($message) 1445 1446Print C<$message> to STDERR. 1447 1448Use the warnings category with the same name as the current package. 1449 1450If that warnings category has been set to "FATAL" in the calling module 1451then die. Otherwise return. 1452 1453=item warnings::warn($category, $message) 1454 1455Print C<$message> to STDERR. 1456 1457If the warnings category, C<$category>, has been set to "FATAL" in the 1458calling module then die. Otherwise return. 1459 1460=item warnings::warn($object, $message) 1461 1462Print C<$message> to STDERR. 1463 1464Use the name of the class for the object reference, C<$object>, as the 1465warnings category. 1466 1467If that warnings category has been set to "FATAL" in the scope where C<$object> 1468is first used then die. Otherwise return. 1469 1470=item warnings::warn_at_level($category, $level, $message) 1471 1472Like C<warnings::warn>, but $level specifies the exact call frame, 14730 being the immediate caller. 1474 1475=item warnings::warnif($message) 1476 1477Equivalent to: 1478 1479 if (warnings::enabled()) 1480 { warnings::warn($message) } 1481 1482=item warnings::warnif($category, $message) 1483 1484Equivalent to: 1485 1486 if (warnings::enabled($category)) 1487 { warnings::warn($category, $message) } 1488 1489=item warnings::warnif($object, $message) 1490 1491Equivalent to: 1492 1493 if (warnings::enabled($object)) 1494 { warnings::warn($object, $message) } 1495 1496=item warnings::warnif_at_level($category, $level, $message) 1497 1498Like C<warnings::warnif>, but $level specifies the exact call frame, 14990 being the immediate caller. 1500 1501=item warnings::register_categories(@names) 1502 1503This registers warning categories for the given names and is primarily for 1504use by the warnings::register pragma. 1505 1506=back 1507 1508See also L<perlmodlib/Pragmatic Modules> and L<perldiag>. 1509 1510=cut 1511 1512# ex: set ro ft=perl: 1513