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