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