Commit | Line | Data |
---|---|---|
37442d52 | 1 | # -*- 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 | |
f809440b | 8 | our $VERSION = '1.29'; |
f2c3e829 RGS |
9 | |
10 | # Verify that we're called correctly so that warnings will work. | |
11 | # see also strict.pm. | |
5108dc18 | 12 | unless ( __FILE__ =~ /(^|[\/\\])\Q${\__PACKAGE__}\E\.pmc?$/ ) { |
f2c3e829 | 13 | my (undef, $f, $l) = caller; |
5108dc18 | 14 | die("Incorrect use of pragma '${\__PACKAGE__}' at $f line $l.\n"); |
f2c3e829 | 15 | } |
0ca4541c | 16 | |
effd17dc DD |
17 | our %Offsets = ( |
18 | ||
19 | # Warnings Categories added in Perl 5.008 | |
20 | ||
21 | 'all' => 0, | |
22 | 'closure' => 2, | |
23 | 'deprecated' => 4, | |
24 | 'exiting' => 6, | |
25 | 'glob' => 8, | |
26 | 'io' => 10, | |
27 | 'closed' => 12, | |
28 | 'exec' => 14, | |
29 | 'layer' => 16, | |
30 | 'newline' => 18, | |
31 | 'pipe' => 20, | |
32 | 'unopened' => 22, | |
33 | 'misc' => 24, | |
34 | 'numeric' => 26, | |
35 | 'once' => 28, | |
36 | 'overflow' => 30, | |
37 | 'pack' => 32, | |
38 | 'portable' => 34, | |
39 | 'recursion' => 36, | |
40 | 'redefine' => 38, | |
41 | 'regexp' => 40, | |
42 | 'severe' => 42, | |
43 | 'debugging' => 44, | |
44 | 'inplace' => 46, | |
45 | 'internal' => 48, | |
46 | 'malloc' => 50, | |
47 | 'signal' => 52, | |
48 | 'substr' => 54, | |
49 | 'syntax' => 56, | |
50 | 'ambiguous' => 58, | |
51 | 'bareword' => 60, | |
52 | 'digit' => 62, | |
53 | 'parenthesis' => 64, | |
54 | 'precedence' => 66, | |
55 | 'printf' => 68, | |
56 | 'prototype' => 70, | |
57 | 'qw' => 72, | |
58 | 'reserved' => 74, | |
59 | 'semicolon' => 76, | |
60 | 'taint' => 78, | |
61 | 'threads' => 80, | |
62 | 'uninitialized' => 82, | |
63 | 'unpack' => 84, | |
64 | 'untie' => 86, | |
65 | 'utf8' => 88, | |
66 | 'void' => 90, | |
67 | ||
68 | # Warnings Categories added in Perl 5.011 | |
69 | ||
70 | 'imprecision' => 92, | |
71 | 'illegalproto' => 94, | |
72 | ||
73 | # Warnings Categories added in Perl 5.013 | |
74 | ||
75 | 'non_unicode' => 96, | |
76 | 'nonchar' => 98, | |
77 | 'surrogate' => 100, | |
78 | ||
79 | # Warnings Categories added in Perl 5.017 | |
80 | ||
81 | 'experimental' => 102, | |
82 | 'experimental::lexical_subs'=> 104, | |
83 | 'experimental::lexical_topic'=> 106, | |
84 | 'experimental::regex_sets'=> 108, | |
85 | 'experimental::smartmatch'=> 110, | |
86 | ||
87 | # Warnings Categories added in Perl 5.019 | |
88 | ||
89 | 'experimental::autoderef'=> 112, | |
90 | 'experimental::postderef'=> 114, | |
91 | 'experimental::signatures'=> 116, | |
92 | 'syscalls' => 118, | |
93 | ||
94 | # Warnings Categories added in Perl 5.021 | |
95 | ||
baabe3fb | 96 | 'experimental::refaliasing'=> 120, |
effd17dc | 97 | 'experimental::win32_perlio'=> 122, |
f809440b KW |
98 | 'locale' => 124, |
99 | 'missing' => 126, | |
100 | 'redundant' => 128, | |
effd17dc DD |
101 | ); |
102 | ||
103 | our %Bits = ( | |
f809440b KW |
104 | 'all' => "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x01", # [0..64] |
105 | 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [29] | |
106 | 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [30] | |
107 | 'closed' => "\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6] | |
108 | 'closure' => "\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1] | |
109 | 'debugging' => "\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [22] | |
110 | 'deprecated' => "\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2] | |
111 | 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [31] | |
112 | 'exec' => "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7] | |
113 | 'exiting' => "\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3] | |
114 | 'experimental' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x55\x15\x05\x00", # [51..58,60,61] | |
115 | 'experimental::autoderef'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00", # [56] | |
116 | 'experimental::lexical_subs'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00", # [52] | |
117 | 'experimental::lexical_topic'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00", # [53] | |
118 | 'experimental::postderef'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00", # [57] | |
119 | 'experimental::refaliasing'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00", # [60] | |
120 | 'experimental::regex_sets'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00", # [54] | |
121 | 'experimental::signatures'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00", # [58] | |
122 | 'experimental::smartmatch'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00", # [55] | |
123 | 'experimental::win32_perlio'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00", # [61] | |
124 | 'glob' => "\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4] | |
125 | 'illegalproto' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00", # [47] | |
126 | 'imprecision' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00", # [46] | |
127 | 'inplace' => "\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [23] | |
128 | 'internal' => "\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [24] | |
129 | 'io' => "\x00\x54\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00", # [5..11,59] | |
130 | 'layer' => "\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8] | |
131 | 'locale' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00", # [62] | |
132 | 'malloc' => "\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [25] | |
133 | 'misc' => "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [12] | |
134 | 'missing' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00", # [63] | |
135 | 'newline' => "\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9] | |
136 | 'non_unicode' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00", # [48] | |
137 | 'nonchar' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00", # [49] | |
138 | 'numeric' => "\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [13] | |
139 | 'once' => "\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [14] | |
140 | 'overflow' => "\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [15] | |
141 | 'pack' => "\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [16] | |
142 | 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00", # [32] | |
143 | 'pipe' => "\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10] | |
144 | 'portable' => "\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [17] | |
145 | 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00", # [33] | |
146 | 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00", # [34] | |
147 | 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00", # [35] | |
148 | 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00", # [36] | |
149 | 'recursion' => "\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [18] | |
150 | 'redefine' => "\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [19] | |
151 | 'redundant' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", # [64] | |
152 | 'regexp' => "\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [20] | |
153 | 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00", # [37] | |
154 | 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00", # [38] | |
155 | 'severe' => "\x00\x00\x00\x00\x00\x54\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [21..25] | |
156 | 'signal' => "\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [26] | |
157 | 'substr' => "\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [27] | |
158 | 'surrogate' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00", # [50] | |
159 | 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\x55\x55\x15\x00\x40\x00\x00\x00\x00\x00", # [28..38,47] | |
160 | 'syscalls' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00", # [59] | |
161 | 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00", # [39] | |
162 | 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00", # [40] | |
163 | 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00", # [41] | |
164 | 'unopened' => "\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11] | |
165 | 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00", # [42] | |
166 | 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00", # [43] | |
167 | 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x15\x00\x00\x00\x00", # [44,48..50] | |
168 | 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00", # [45] | |
effd17dc DD |
169 | ); |
170 | ||
171 | our %DeadBits = ( | |
f809440b KW |
172 | 'all' => "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\x02", # [0..64] |
173 | 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [29] | |
174 | 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [30] | |
175 | 'closed' => "\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6] | |
176 | 'closure' => "\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1] | |
177 | 'debugging' => "\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [22] | |
178 | 'deprecated' => "\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2] | |
179 | 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [31] | |
180 | 'exec' => "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7] | |
181 | 'exiting' => "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3] | |
182 | 'experimental' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xaa\x2a\x0a\x00", # [51..58,60,61] | |
183 | 'experimental::autoderef'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00", # [56] | |
184 | 'experimental::lexical_subs'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00", # [52] | |
185 | 'experimental::lexical_topic'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00", # [53] | |
186 | 'experimental::postderef'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00", # [57] | |
187 | 'experimental::refaliasing'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00", # [60] | |
188 | 'experimental::regex_sets'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00", # [54] | |
189 | 'experimental::signatures'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00", # [58] | |
190 | 'experimental::smartmatch'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00", # [55] | |
191 | 'experimental::win32_perlio'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00", # [61] | |
192 | 'glob' => "\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4] | |
193 | 'illegalproto' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00", # [47] | |
194 | 'imprecision' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00", # [46] | |
195 | 'inplace' => "\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [23] | |
196 | 'internal' => "\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [24] | |
197 | 'io' => "\x00\xa8\xaa\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00", # [5..11,59] | |
198 | 'layer' => "\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8] | |
199 | 'locale' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00", # [62] | |
200 | 'malloc' => "\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [25] | |
201 | 'misc' => "\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [12] | |
202 | 'missing' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00", # [63] | |
203 | 'newline' => "\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9] | |
204 | 'non_unicode' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00", # [48] | |
205 | 'nonchar' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00", # [49] | |
206 | 'numeric' => "\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [13] | |
207 | 'once' => "\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [14] | |
208 | 'overflow' => "\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [15] | |
209 | 'pack' => "\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [16] | |
210 | 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00", # [32] | |
211 | 'pipe' => "\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10] | |
212 | 'portable' => "\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [17] | |
213 | 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00", # [33] | |
214 | 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00", # [34] | |
215 | 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00", # [35] | |
216 | 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", # [36] | |
217 | 'recursion' => "\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [18] | |
218 | 'redefine' => "\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [19] | |
219 | 'redundant' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02", # [64] | |
220 | 'regexp' => "\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [20] | |
221 | 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00", # [37] | |
222 | 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00", # [38] | |
223 | 'severe' => "\x00\x00\x00\x00\x00\xa8\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [21..25] | |
224 | 'signal' => "\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [26] | |
225 | 'substr' => "\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [27] | |
226 | 'surrogate' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00", # [50] | |
227 | 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\xaa\xaa\x2a\x00\x80\x00\x00\x00\x00\x00", # [28..38,47] | |
228 | 'syscalls' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00", # [59] | |
229 | 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00", # [39] | |
230 | 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00", # [40] | |
231 | 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00", # [41] | |
232 | 'unopened' => "\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11] | |
233 | 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00", # [42] | |
234 | 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00", # [43] | |
235 | 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x2a\x00\x00\x00\x00", # [44,48..50] | |
236 | 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00", # [45] | |
effd17dc DD |
237 | ); |
238 | ||
f809440b KW |
239 | $NONE = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; |
240 | $DEFAULT = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x00\x55\x15\x15\x00", # [2,56,52,53,57,60,54,58,55,61,4,62,22,23,25] | |
241 | $LAST_BIT = 130 ; | |
242 | $BYTES = 17 ; | |
effd17dc DD |
243 | |
244 | $All = "" ; vec($All, $Offsets{'all'}, 2) = 3 ; | |
245 | ||
246 | sub Croaker | |
247 | { | |
248 | require Carp; # this initializes %CarpInternal | |
249 | local $Carp::CarpInternal{'warnings'}; | |
250 | delete $Carp::CarpInternal{'warnings'}; | |
251 | Carp::croak(@_); | |
252 | } | |
253 | ||
254 | sub _bits { | |
255 | my $mask = shift ; | |
256 | my $catmask ; | |
257 | my $fatal = 0 ; | |
258 | my $no_fatal = 0 ; | |
259 | ||
260 | foreach my $word ( @_ ) { | |
261 | if ($word eq 'FATAL') { | |
262 | $fatal = 1; | |
263 | $no_fatal = 0; | |
264 | } | |
265 | elsif ($word eq 'NONFATAL') { | |
266 | $fatal = 0; | |
267 | $no_fatal = 1; | |
268 | } | |
269 | elsif ($catmask = $Bits{$word}) { | |
270 | $mask |= $catmask ; | |
271 | $mask |= $DeadBits{$word} if $fatal ; | |
272 | $mask &= ~($DeadBits{$word}|$All) if $no_fatal ; | |
273 | } | |
274 | else | |
56873d42 | 275 | { Croaker("Unknown warnings category '$word'")} |
effd17dc DD |
276 | } |
277 | ||
278 | return $mask ; | |
279 | } | |
280 | ||
281 | sub bits | |
282 | { | |
283 | # called from B::Deparse.pm | |
284 | push @_, 'all' unless @_ ; | |
285 | return _bits(undef, @_) ; | |
286 | } | |
287 | ||
288 | sub import | |
289 | { | |
290 | shift; | |
291 | ||
292 | my $mask = ${^WARNING_BITS} // ($^W ? $Bits{all} : $DEFAULT) ; | |
293 | ||
294 | if (vec($mask, $Offsets{'all'}, 1)) { | |
56873d42 DD |
295 | $mask |= $Bits{'all'} ; |
296 | $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1); | |
effd17dc DD |
297 | } |
298 | ||
299 | # append 'all' when implied (after a lone "FATAL" or "NONFATAL") | |
300 | push @_, 'all' if @_==1 && ( $_[0] eq 'FATAL' || $_[0] eq 'NONFATAL' ); | |
301 | ||
302 | # Empty @_ is equivalent to @_ = 'all' ; | |
303 | ${^WARNING_BITS} = @_ ? _bits($mask, @_) : $mask | $Bits{all} ; | |
304 | } | |
305 | ||
306 | sub unimport | |
307 | { | |
308 | shift; | |
309 | ||
310 | my $catmask ; | |
311 | my $mask = ${^WARNING_BITS} // ($^W ? $Bits{all} : $DEFAULT) ; | |
312 | ||
313 | if (vec($mask, $Offsets{'all'}, 1)) { | |
56873d42 DD |
314 | $mask |= $Bits{'all'} ; |
315 | $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1); | |
effd17dc DD |
316 | } |
317 | ||
318 | # append 'all' when implied (empty import list or after a lone "FATAL") | |
319 | push @_, 'all' if !@_ || @_==1 && $_[0] eq 'FATAL'; | |
320 | ||
321 | foreach my $word ( @_ ) { | |
322 | if ($word eq 'FATAL') { | |
323 | next; | |
324 | } | |
325 | elsif ($catmask = $Bits{$word}) { | |
326 | $mask &= ~($catmask | $DeadBits{$word} | $All); | |
327 | } | |
328 | else | |
56873d42 | 329 | { Croaker("Unknown warnings category '$word'")} |
effd17dc DD |
330 | } |
331 | ||
332 | ${^WARNING_BITS} = $mask ; | |
333 | } | |
334 | ||
335 | my %builtin_type; @builtin_type{qw(SCALAR ARRAY HASH CODE REF GLOB LVALUE Regexp)} = (); | |
336 | ||
337 | sub MESSAGE () { 4 }; | |
338 | sub FATAL () { 2 }; | |
339 | sub NORMAL () { 1 }; | |
340 | ||
341 | sub __chk | |
342 | { | |
343 | my $category ; | |
344 | my $offset ; | |
345 | my $isobj = 0 ; | |
346 | my $wanted = shift; | |
347 | my $has_message = $wanted & MESSAGE; | |
348 | ||
349 | unless (@_ == 1 || @_ == ($has_message ? 2 : 0)) { | |
350 | my $sub = (caller 1)[3]; | |
351 | my $syntax = $has_message ? "[category,] 'message'" : '[category]'; | |
352 | Croaker("Usage: $sub($syntax)"); | |
353 | } | |
354 | ||
355 | my $message = pop if $has_message; | |
356 | ||
357 | if (@_) { | |
56873d42 DD |
358 | # check the category supplied. |
359 | $category = shift ; | |
360 | if (my $type = ref $category) { | |
361 | Croaker("not an object") | |
362 | if exists $builtin_type{$type}; | |
effd17dc | 363 | $category = $type; |
56873d42 DD |
364 | $isobj = 1 ; |
365 | } | |
366 | $offset = $Offsets{$category}; | |
367 | Croaker("Unknown warnings category '$category'") | |
effd17dc DD |
368 | unless defined $offset; |
369 | } | |
370 | else { | |
56873d42 DD |
371 | $category = (caller(1))[0] ; |
372 | $offset = $Offsets{$category}; | |
373 | Croaker("package '$category' not registered for warnings") | |
effd17dc DD |
374 | unless defined $offset ; |
375 | } | |
376 | ||
377 | my $i; | |
378 | ||
379 | if ($isobj) { | |
56873d42 DD |
380 | my $pkg; |
381 | $i = 2; | |
382 | while (do { { package DB; $pkg = (caller($i++))[0] } } ) { | |
383 | last unless @DB::args && $DB::args[0] =~ /^$category=/ ; | |
384 | } | |
effd17dc DD |
385 | $i -= 2 ; |
386 | } | |
387 | else { | |
56873d42 | 388 | $i = _error_loc(); # see where Carp will allocate the error |
effd17dc DD |
389 | } |
390 | ||
391 | # Default to 0 if caller returns nothing. Default to $DEFAULT if it | |
392 | # explicitly returns undef. | |
393 | my(@callers_bitmask) = (caller($i))[9] ; | |
394 | my $callers_bitmask = | |
395 | @callers_bitmask ? $callers_bitmask[0] // $DEFAULT : 0 ; | |
396 | ||
397 | my @results; | |
398 | foreach my $type (FATAL, NORMAL) { | |
399 | next unless $wanted & $type; | |
400 | ||
401 | push @results, (vec($callers_bitmask, $offset + $type - 1, 1) || | |
402 | vec($callers_bitmask, $Offsets{'all'} + $type - 1, 1)); | |
403 | } | |
404 | ||
405 | # &enabled and &fatal_enabled | |
406 | return $results[0] unless $has_message; | |
407 | ||
408 | # &warnif, and the category is neither enabled as warning nor as fatal | |
409 | return if $wanted == (NORMAL | FATAL | MESSAGE) | |
410 | && !($results[0] || $results[1]); | |
411 | ||
412 | require Carp; | |
413 | Carp::croak($message) if $results[0]; | |
414 | # will always get here for &warn. will only get here for &warnif if the | |
415 | # category is enabled | |
416 | Carp::carp($message); | |
417 | } | |
418 | ||
419 | sub _mkMask | |
420 | { | |
421 | my ($bit) = @_; | |
422 | my $mask = ""; | |
423 | ||
424 | vec($mask, $bit, 1) = 1; | |
425 | return $mask; | |
426 | } | |
427 | ||
428 | sub register_categories | |
429 | { | |
430 | my @names = @_; | |
431 | ||
432 | for my $name (@names) { | |
433 | if (! defined $Bits{$name}) { | |
434 | $Bits{$name} = _mkMask($LAST_BIT); | |
435 | vec($Bits{'all'}, $LAST_BIT, 1) = 1; | |
436 | $Offsets{$name} = $LAST_BIT ++; | |
437 | foreach my $k (keys %Bits) { | |
438 | vec($Bits{$k}, $LAST_BIT, 1) = 0; | |
439 | } | |
440 | $DeadBits{$name} = _mkMask($LAST_BIT); | |
441 | vec($DeadBits{'all'}, $LAST_BIT++, 1) = 1; | |
442 | } | |
443 | } | |
444 | } | |
445 | ||
446 | sub _error_loc { | |
447 | require Carp; | |
448 | goto &Carp::short_error_loc; # don't introduce another stack frame | |
449 | } | |
450 | ||
451 | sub enabled | |
452 | { | |
453 | return __chk(NORMAL, @_); | |
454 | } | |
455 | ||
456 | sub fatal_enabled | |
457 | { | |
458 | return __chk(FATAL, @_); | |
459 | } | |
460 | ||
461 | sub warn | |
462 | { | |
463 | return __chk(FATAL | MESSAGE, @_); | |
464 | } | |
465 | ||
466 | sub warnif | |
467 | { | |
468 | return __chk(NORMAL | FATAL | MESSAGE, @_); | |
469 | } | |
470 | ||
471 | # These are not part of any public interface, so we can delete them to save | |
472 | # space. | |
473 | delete @warnings::{qw(NORMAL FATAL MESSAGE)}; | |
474 | ||
475 | 1; | |
476 | __END__ | |
599cee73 PM |
477 | =head1 NAME |
478 | ||
4438c4b7 | 479 | warnings - Perl pragma to control optional warnings |
599cee73 PM |
480 | |
481 | =head1 SYNOPSIS | |
482 | ||
4438c4b7 JH |
483 | use warnings; |
484 | no warnings; | |
599cee73 | 485 | |
4438c4b7 JH |
486 | use warnings "all"; |
487 | no warnings "all"; | |
599cee73 | 488 | |
d3a7d8c7 GS |
489 | use warnings::register; |
490 | if (warnings::enabled()) { | |
491 | warnings::warn("some warning"); | |
492 | } | |
493 | ||
494 | if (warnings::enabled("void")) { | |
e476b1b5 GS |
495 | warnings::warn("void", "some warning"); |
496 | } | |
497 | ||
7e6d00f8 PM |
498 | if (warnings::enabled($object)) { |
499 | warnings::warn($object, "some warning"); | |
500 | } | |
501 | ||
721f911b PM |
502 | warnings::warnif("some warning"); |
503 | warnings::warnif("void", "some warning"); | |
504 | warnings::warnif($object, "some warning"); | |
7e6d00f8 | 505 | |
599cee73 PM |
506 | =head1 DESCRIPTION |
507 | ||
a7f2b7af RS |
508 | The C<warnings> pragma gives control over which warnings are enabled in |
509 | which parts of a Perl program. It's a more flexible alternative for | |
510 | both the command line flag B<-w> and the equivalent Perl variable, | |
511 | C<$^W>. | |
fe2e802c | 512 | |
a7f2b7af RS |
513 | This pragma works just like the C<strict> pragma. |
514 | This means that the scope of the warning pragma is limited to the | |
515 | enclosing block. It also means that the pragma setting will not | |
516 | leak across files (via C<use>, C<require> or C<do>). This allows | |
517 | authors to independently define the degree of warning checks that will | |
518 | be applied to their module. | |
599cee73 | 519 | |
a7f2b7af RS |
520 | By default, optional warnings are disabled, so any legacy code that |
521 | doesn't attempt to control the warnings will work unchanged. | |
522 | ||
523 | All warnings are enabled in a block by either of these: | |
524 | ||
525 | use warnings; | |
526 | use warnings 'all'; | |
527 | ||
528 | Similarly all warnings are disabled in a block by either of these: | |
529 | ||
530 | no warnings; | |
531 | no warnings 'all'; | |
532 | ||
533 | For example, consider the code below: | |
534 | ||
535 | use warnings; | |
536 | my @a; | |
537 | { | |
538 | no warnings; | |
539 | my $b = @a[0]; | |
540 | } | |
541 | my $c = @a[0]; | |
542 | ||
543 | The code in the enclosing block has warnings enabled, but the inner | |
544 | block has them disabled. In this case that means the assignment to the | |
545 | scalar C<$c> will trip the C<"Scalar value @a[0] better written as $a[0]"> | |
546 | warning, but the assignment to the scalar C<$b> will not. | |
547 | ||
548 | =head2 Default Warnings and Optional Warnings | |
549 | ||
550 | Before the introduction of lexical warnings, Perl had two classes of | |
56873d42 | 551 | warnings: mandatory and optional. |
a7f2b7af RS |
552 | |
553 | As its name suggests, if your code tripped a mandatory warning, you | |
554 | would get a warning whether you wanted it or not. | |
555 | For example, the code below would always produce an C<"isn't numeric"> | |
556 | warning about the "2:". | |
557 | ||
558 | my $a = "2:" + 3; | |
559 | ||
560 | With the introduction of lexical warnings, mandatory warnings now become | |
561 | I<default> warnings. The difference is that although the previously | |
562 | mandatory warnings are still enabled by default, they can then be | |
563 | subsequently enabled or disabled with the lexical warning pragma. For | |
564 | example, in the code below, an C<"isn't numeric"> warning will only | |
565 | be reported for the C<$a> variable. | |
566 | ||
567 | my $a = "2:" + 3; | |
568 | no warnings; | |
569 | my $b = "2:" + 3; | |
570 | ||
571 | Note that neither the B<-w> flag or the C<$^W> can be used to | |
572 | disable/enable default warnings. They are still mandatory in this case. | |
573 | ||
574 | =head2 What's wrong with B<-w> and C<$^W> | |
575 | ||
576 | Although very useful, the big problem with using B<-w> on the command | |
577 | line to enable warnings is that it is all or nothing. Take the typical | |
578 | scenario when you are writing a Perl program. Parts of the code you | |
579 | will write yourself, but it's very likely that you will make use of | |
580 | pre-written Perl modules. If you use the B<-w> flag in this case, you | |
581 | end up enabling warnings in pieces of code that you haven't written. | |
582 | ||
583 | Similarly, using C<$^W> to either disable or enable blocks of code is | |
584 | fundamentally flawed. For a start, say you want to disable warnings in | |
585 | a block of code. You might expect this to be enough to do the trick: | |
586 | ||
587 | { | |
588 | local ($^W) = 0; | |
589 | my $a =+ 2; | |
590 | my $b; chop $b; | |
591 | } | |
592 | ||
593 | When this code is run with the B<-w> flag, a warning will be produced | |
594 | for the C<$a> line: C<"Reversed += operator">. | |
595 | ||
596 | The problem is that Perl has both compile-time and run-time warnings. To | |
597 | disable compile-time warnings you need to rewrite the code like this: | |
598 | ||
599 | { | |
600 | BEGIN { $^W = 0 } | |
601 | my $a =+ 2; | |
602 | my $b; chop $b; | |
603 | } | |
604 | ||
605 | The other big problem with C<$^W> is the way you can inadvertently | |
606 | change the warning setting in unexpected places in your code. For example, | |
607 | when the code below is run (without the B<-w> flag), the second call | |
608 | to C<doit> will trip a C<"Use of uninitialized value"> warning, whereas | |
609 | the first will not. | |
610 | ||
611 | sub doit | |
612 | { | |
613 | my $b; chop $b; | |
614 | } | |
615 | ||
616 | doit(); | |
617 | ||
618 | { | |
619 | local ($^W) = 1; | |
620 | doit() | |
621 | } | |
622 | ||
623 | This is a side-effect of C<$^W> being dynamically scoped. | |
624 | ||
625 | Lexical warnings get around these limitations by allowing finer control | |
626 | over where warnings can or can't be tripped. | |
627 | ||
628 | =head2 Controlling Warnings from the Command Line | |
629 | ||
630 | There are three Command Line flags that can be used to control when | |
631 | warnings are (or aren't) produced: | |
632 | ||
633 | =over 5 | |
634 | ||
635 | =item B<-w> | |
636 | X<-w> | |
637 | ||
638 | This is the existing flag. If the lexical warnings pragma is B<not> | |
639 | used in any of you code, or any of the modules that you use, this flag | |
640 | will enable warnings everywhere. See L<Backward Compatibility> for | |
641 | details of how this flag interacts with lexical warnings. | |
642 | ||
643 | =item B<-W> | |
644 | X<-W> | |
645 | ||
646 | If the B<-W> flag is used on the command line, it will enable all warnings | |
647 | throughout the program regardless of whether warnings were disabled | |
648 | locally using C<no warnings> or C<$^W =0>. | |
649 | This includes all files that get | |
650 | included via C<use>, C<require> or C<do>. | |
651 | Think of it as the Perl equivalent of the "lint" command. | |
652 | ||
653 | =item B<-X> | |
654 | X<-X> | |
655 | ||
656 | Does the exact opposite to the B<-W> flag, i.e. it disables all warnings. | |
657 | ||
658 | =back | |
659 | ||
660 | =head2 Backward Compatibility | |
661 | ||
662 | If you are used to working with a version of Perl prior to the | |
663 | introduction of lexically scoped warnings, or have code that uses both | |
664 | lexical warnings and C<$^W>, this section will describe how they interact. | |
665 | ||
666 | How Lexical Warnings interact with B<-w>/C<$^W>: | |
667 | ||
668 | =over 5 | |
669 | ||
670 | =item 1. | |
671 | ||
672 | If none of the three command line flags (B<-w>, B<-W> or B<-X>) that | |
673 | control warnings is used and neither C<$^W> nor the C<warnings> pragma | |
674 | are used, then default warnings will be enabled and optional warnings | |
675 | disabled. | |
676 | This means that legacy code that doesn't attempt to control the warnings | |
677 | will work unchanged. | |
678 | ||
679 | =item 2. | |
680 | ||
681 | The B<-w> flag just sets the global C<$^W> variable as in 5.005. This | |
682 | means that any legacy code that currently relies on manipulating C<$^W> | |
56873d42 | 683 | to control warning behavior will still work as is. |
a7f2b7af RS |
684 | |
685 | =item 3. | |
686 | ||
687 | Apart from now being a boolean, the C<$^W> variable operates in exactly | |
688 | the same horrible uncontrolled global way, except that it cannot | |
689 | disable/enable default warnings. | |
690 | ||
691 | =item 4. | |
692 | ||
693 | If a piece of code is under the control of the C<warnings> pragma, | |
694 | both the C<$^W> variable and the B<-w> flag will be ignored for the | |
695 | scope of the lexical warning. | |
696 | ||
697 | =item 5. | |
698 | ||
699 | The only way to override a lexical warnings setting is with the B<-W> | |
700 | or B<-X> command line flags. | |
701 | ||
702 | =back | |
703 | ||
704 | The combined effect of 3 & 4 is that it will allow code which uses | |
705 | the C<warnings> pragma to control the warning behavior of $^W-type | |
706 | code (using a C<local $^W=0>) if it really wants to, but not vice-versa. | |
707 | ||
708 | =head2 Category Hierarchy | |
709 | X<warning, categories> | |
710 | ||
711 | A hierarchy of "categories" have been defined to allow groups of warnings | |
712 | to be enabled/disabled in isolation. | |
713 | ||
714 | The current hierarchy is: | |
715 | ||
716 | all -+ | |
717 | | | |
718 | +- closure | |
719 | | | |
720 | +- deprecated | |
721 | | | |
722 | +- exiting | |
723 | | | |
724 | +- experimental --+ | |
725 | | | | |
726 | | +- experimental::autoderef | |
727 | | | | |
728 | | +- experimental::lexical_subs | |
729 | | | | |
730 | | +- experimental::lexical_topic | |
731 | | | | |
732 | | +- experimental::postderef | |
733 | | | | |
baabe3fb FC |
734 | | +- experimental::refaliasing |
735 | | | | |
a7f2b7af RS |
736 | | +- experimental::regex_sets |
737 | | | | |
738 | | +- experimental::signatures | |
739 | | | | |
740 | | +- experimental::smartmatch | |
7ac92924 TC |
741 | | | |
742 | | +- experimental::win32_perlio | |
a7f2b7af RS |
743 | | |
744 | +- glob | |
745 | | | |
746 | +- imprecision | |
747 | | | |
748 | +- io ------------+ | |
749 | | | | |
750 | | +- closed | |
751 | | | | |
752 | | +- exec | |
753 | | | | |
754 | | +- layer | |
755 | | | | |
756 | | +- newline | |
757 | | | | |
758 | | +- pipe | |
759 | | | | |
760 | | +- syscalls | |
761 | | | | |
762 | | +- unopened | |
763 | | | |
f809440b KW |
764 | +- locale |
765 | | | |
a7f2b7af RS |
766 | +- misc |
767 | | | |
3664866e AB |
768 | +- missing |
769 | | | |
a7f2b7af RS |
770 | +- numeric |
771 | | | |
772 | +- once | |
773 | | | |
774 | +- overflow | |
775 | | | |
776 | +- pack | |
777 | | | |
778 | +- portable | |
779 | | | |
780 | +- recursion | |
781 | | | |
782 | +- redefine | |
783 | | | |
4077a6bc AB |
784 | +- redundant |
785 | | | |
a7f2b7af RS |
786 | +- regexp |
787 | | | |
788 | +- severe --------+ | |
789 | | | | |
790 | | +- debugging | |
791 | | | | |
792 | | +- inplace | |
793 | | | | |
794 | | +- internal | |
795 | | | | |
796 | | +- malloc | |
797 | | | |
798 | +- signal | |
799 | | | |
800 | +- substr | |
801 | | | |
802 | +- syntax --------+ | |
803 | | | | |
804 | | +- ambiguous | |
805 | | | | |
806 | | +- bareword | |
807 | | | | |
808 | | +- digit | |
809 | | | | |
810 | | +- illegalproto | |
811 | | | | |
812 | | +- parenthesis | |
813 | | | | |
814 | | +- precedence | |
815 | | | | |
816 | | +- printf | |
817 | | | | |
818 | | +- prototype | |
819 | | | | |
820 | | +- qw | |
821 | | | | |
822 | | +- reserved | |
823 | | | | |
824 | | +- semicolon | |
825 | | | |
826 | +- taint | |
827 | | | |
828 | +- threads | |
829 | | | |
830 | +- uninitialized | |
831 | | | |
832 | +- unpack | |
833 | | | |
834 | +- untie | |
835 | | | |
836 | +- utf8 ----------+ | |
837 | | | | |
838 | | +- non_unicode | |
839 | | | | |
840 | | +- nonchar | |
841 | | | | |
842 | | +- surrogate | |
843 | | | |
844 | +- void | |
845 | ||
846 | Just like the "strict" pragma any of these categories can be combined | |
847 | ||
848 | use warnings qw(void redefine); | |
849 | no warnings qw(io syntax untie); | |
850 | ||
851 | Also like the "strict" pragma, if there is more than one instance of the | |
56873d42 | 852 | C<warnings> pragma in a given scope the cumulative effect is additive. |
a7f2b7af RS |
853 | |
854 | use warnings qw(void); # only "void" warnings enabled | |
855 | ... | |
856 | use warnings qw(io); # only "void" & "io" warnings enabled | |
857 | ... | |
858 | no warnings qw(void); # only "io" warnings enabled | |
859 | ||
860 | To determine which category a specific warning has been assigned to see | |
861 | L<perldiag>. | |
862 | ||
863 | Note: Before Perl 5.8.0, the lexical warnings category "deprecated" was a | |
864 | sub-category of the "syntax" category. It is now a top-level category | |
865 | in its own right. | |
866 | ||
3664866e AB |
867 | Note: Before 5.21.0, the "missing" lexical warnings category was |
868 | internally defined to be the same as the "uninitialized" category. It | |
869 | is now a top-level category in its own right. | |
870 | ||
a7f2b7af RS |
871 | =head2 Fatal Warnings |
872 | X<warning, fatal> | |
873 | ||
874 | The presence of the word "FATAL" in the category list will escalate any | |
875 | warnings detected from the categories specified in the lexical scope | |
876 | into fatal errors. In the code below, the use of C<time>, C<length> | |
877 | and C<join> can all produce a C<"Useless use of xxx in void context"> | |
878 | warning. | |
879 | ||
880 | use warnings; | |
881 | ||
882 | time; | |
883 | ||
884 | { | |
885 | use warnings FATAL => qw(void); | |
886 | length "abc"; | |
887 | } | |
888 | ||
889 | join "", 1,2,3; | |
890 | ||
891 | print "done\n"; | |
892 | ||
893 | When run it produces this output | |
894 | ||
895 | Useless use of time in void context at fatal line 3. | |
56873d42 | 896 | Useless use of length in void context at fatal line 7. |
a7f2b7af RS |
897 | |
898 | The scope where C<length> is used has escalated the C<void> warnings | |
899 | category into a fatal error, so the program terminates immediately when it | |
900 | encounters the warning. | |
901 | ||
902 | To explicitly turn off a "FATAL" warning you just disable the warning | |
903 | it is associated with. So, for example, to disable the "void" warning | |
904 | in the example above, either of these will do the trick: | |
905 | ||
906 | no warnings qw(void); | |
907 | no warnings FATAL => qw(void); | |
908 | ||
909 | If you want to downgrade a warning that has been escalated into a fatal | |
910 | error back to a normal warning, you can use the "NONFATAL" keyword. For | |
911 | example, the code below will promote all warnings into fatal errors, | |
912 | except for those in the "syntax" category. | |
913 | ||
914 | use warnings FATAL => 'all', NONFATAL => 'syntax'; | |
915 | ||
916 | As of Perl 5.20, instead of C<< use warnings FATAL => 'all'; >> you can | |
917 | use: | |
918 | ||
919 | use v5.20; # Perl 5.20 or greater is required for the following | |
920 | use warnings 'FATAL'; # short form of "use warnings FATAL => 'all';" | |
921 | ||
922 | If you want your program to be compatible with versions of Perl before | |
923 | 5.20, you must use C<< use warnings FATAL => 'all'; >> instead. (In | |
924 | previous versions of Perl, the behavior of the statements | |
925 | C<< use warnings 'FATAL'; >>, C<< use warnings 'NONFATAL'; >> and | |
926 | C<< no warnings 'FATAL'; >> was unspecified; they did not behave as if | |
927 | they included the C<< => 'all' >> portion. As of 5.20, they do.) | |
928 | ||
929 | B<NOTE:> Users of FATAL warnings, especially | |
930 | those using C<< FATAL => 'all' >> | |
931 | should be fully aware that they are risking future portability of their | |
932 | programs by doing so. Perl makes absolutely no commitments to not | |
933 | introduce new warnings, or warnings categories in the future, and indeed | |
934 | we explicitly reserve the right to do so. Code that may not warn now may | |
935 | warn in a future release of Perl if the Perl5 development team deems it | |
936 | in the best interests of the community to do so. Should code using FATAL | |
937 | warnings break due to the introduction of a new warning we will NOT | |
938 | consider it an incompatible change. Users of FATAL warnings should take | |
939 | special caution during upgrades to check to see if their code triggers | |
940 | any new warnings and should pay particular attention to the fine print of | |
941 | the documentation of the features they use to ensure they do not exploit | |
942 | features that are documented as risky, deprecated, or unspecified, or where | |
943 | the documentation says "so don't do that", or anything with the same sense | |
944 | and spirit. Use of such features in combination with FATAL warnings is | |
945 | ENTIRELY AT THE USER'S RISK. | |
946 | ||
947 | =head2 Reporting Warnings from a Module | |
948 | X<warning, reporting> X<warning, registering> | |
949 | ||
950 | The C<warnings> pragma provides a number of functions that are useful for | |
951 | module authors. These are used when you want to report a module-specific | |
952 | warning to a calling module has enabled warnings via the C<warnings> | |
953 | pragma. | |
954 | ||
955 | Consider the module C<MyMod::Abc> below. | |
956 | ||
957 | package MyMod::Abc; | |
958 | ||
959 | use warnings::register; | |
960 | ||
961 | sub open { | |
962 | my $path = shift; | |
963 | if ($path !~ m#^/#) { | |
964 | warnings::warn("changing relative path to /var/abc") | |
965 | if warnings::enabled(); | |
966 | $path = "/var/abc/$path"; | |
967 | } | |
968 | } | |
969 | ||
970 | 1; | |
971 | ||
972 | The call to C<warnings::register> will create a new warnings category | |
973 | called "MyMod::Abc", i.e. the new category name matches the current | |
974 | package name. The C<open> function in the module will display a warning | |
975 | message if it gets given a relative path as a parameter. This warnings | |
976 | will only be displayed if the code that uses C<MyMod::Abc> has actually | |
977 | enabled them with the C<warnings> pragma like below. | |
978 | ||
979 | use MyMod::Abc; | |
980 | use warnings 'MyMod::Abc'; | |
981 | ... | |
982 | abc::open("../fred.txt"); | |
983 | ||
984 | It is also possible to test whether the pre-defined warnings categories are | |
985 | set in the calling module with the C<warnings::enabled> function. Consider | |
986 | this snippet of code: | |
987 | ||
988 | package MyMod::Abc; | |
989 | ||
990 | sub open { | |
56873d42 | 991 | warnings::warnif("deprecated", |
a7f2b7af RS |
992 | "open is deprecated, use new instead"); |
993 | new(@_); | |
994 | } | |
995 | ||
996 | sub new | |
997 | ... | |
998 | 1; | |
999 | ||
1000 | The function C<open> has been deprecated, so code has been included to | |
1001 | display a warning message whenever the calling module has (at least) the | |
1002 | "deprecated" warnings category enabled. Something like this, say. | |
1003 | ||
1004 | use warnings 'deprecated'; | |
1005 | use MyMod::Abc; | |
1006 | ... | |
1007 | MyMod::Abc::open($filename); | |
1008 | ||
1009 | Either the C<warnings::warn> or C<warnings::warnif> function should be | |
1010 | used to actually display the warnings message. This is because they can | |
1011 | make use of the feature that allows warnings to be escalated into fatal | |
1012 | errors. So in this case | |
1013 | ||
1014 | use MyMod::Abc; | |
1015 | use warnings FATAL => 'MyMod::Abc'; | |
1016 | ... | |
1017 | MyMod::Abc::open('../fred.txt'); | |
1018 | ||
1019 | the C<warnings::warnif> function will detect this and die after | |
1020 | displaying the warning message. | |
1021 | ||
1022 | The three warnings functions, C<warnings::warn>, C<warnings::warnif> | |
1023 | and C<warnings::enabled> can optionally take an object reference in place | |
1024 | of a category name. In this case the functions will use the class name | |
1025 | of the object as the warnings category. | |
1026 | ||
1027 | Consider this example: | |
1028 | ||
1029 | package Original; | |
1030 | ||
1031 | no warnings; | |
1032 | use warnings::register; | |
1033 | ||
1034 | sub new | |
1035 | { | |
1036 | my $class = shift; | |
1037 | bless [], $class; | |
1038 | } | |
1039 | ||
1040 | sub check | |
effd17dc DD |
1041 | { |
1042 | my $self = shift; | |
1043 | my $value = shift; | |
e476b1b5 | 1044 | |
effd17dc DD |
1045 | if ($value % 2 && warnings::enabled($self)) |
1046 | { warnings::warn($self, "Odd numbers are unsafe") } | |
1047 | } | |
599cee73 | 1048 | |
effd17dc DD |
1049 | sub doit |
1050 | { | |
1051 | my $self = shift; | |
1052 | my $value = shift; | |
1053 | $self->check($value); | |
1054 | # ... | |
1055 | } | |
599cee73 | 1056 | |
effd17dc | 1057 | 1; |
0d658bf5 | 1058 | |
effd17dc | 1059 | package Derived; |
0d658bf5 | 1060 | |
effd17dc DD |
1061 | use warnings::register; |
1062 | use Original; | |
1063 | our @ISA = qw( Original ); | |
1064 | sub new | |
1065 | { | |
1066 | my $class = shift; | |
1067 | bless [], $class; | |
1068 | } | |
b88df990 | 1069 | |
b88df990 | 1070 | |
effd17dc | 1071 | 1; |
8457b38f | 1072 | |
56873d42 | 1073 | The code below makes use of both modules, but it only enables warnings from |
effd17dc | 1074 | C<Derived>. |
8457b38f | 1075 | |
effd17dc DD |
1076 | use Original; |
1077 | use Derived; | |
1078 | use warnings 'Derived'; | |
1079 | my $a = Original->new(); | |
1080 | $a->doit(1); | |
1081 | my $b = Derived->new(); | |
1082 | $a->doit(1); | |
6f87cb12 | 1083 | |
effd17dc | 1084 | When this code is run only the C<Derived> object, C<$b>, will generate |
56873d42 | 1085 | a warning. |
6f87cb12 | 1086 | |
effd17dc | 1087 | Odd numbers are unsafe at main.pl line 7 |
c8028aa6 | 1088 | |
effd17dc DD |
1089 | Notice also that the warning is reported at the line where the object is first |
1090 | used. | |
c8028aa6 | 1091 | |
effd17dc DD |
1092 | When registering new categories of warning, you can supply more names to |
1093 | warnings::register like this: | |
7ac92924 | 1094 | |
effd17dc DD |
1095 | package MyModule; |
1096 | use warnings::register qw(format precision); | |
7ac92924 | 1097 | |
effd17dc | 1098 | ... |
d3a7d8c7 | 1099 | |
effd17dc | 1100 | warnings::warnif('MyModule::format', '...'); |
599cee73 | 1101 | |
effd17dc | 1102 | =head1 FUNCTIONS |
599cee73 | 1103 | |
effd17dc | 1104 | =over 4 |
d3a7d8c7 | 1105 | |
effd17dc | 1106 | =item use warnings::register |
599cee73 | 1107 | |
effd17dc DD |
1108 | Creates a new warnings category with the same name as the package where |
1109 | the call to the pragma is used. | |
c3186b65 | 1110 | |
effd17dc | 1111 | =item warnings::enabled() |
6e9af7e4 | 1112 | |
effd17dc | 1113 | Use the warnings category with the same name as the current package. |
599cee73 | 1114 | |
effd17dc DD |
1115 | Return TRUE if that warnings category is enabled in the calling module. |
1116 | Otherwise returns FALSE. | |
599cee73 | 1117 | |
effd17dc | 1118 | =item warnings::enabled($category) |
4c02ac93 | 1119 | |
effd17dc DD |
1120 | Return TRUE if the warnings category, C<$category>, is enabled in the |
1121 | calling module. | |
1122 | Otherwise returns FALSE. | |
6e9af7e4 | 1123 | |
effd17dc | 1124 | =item warnings::enabled($object) |
6e9af7e4 | 1125 | |
effd17dc DD |
1126 | Use the name of the class for the object reference, C<$object>, as the |
1127 | warnings category. | |
c91312d5 | 1128 | |
effd17dc DD |
1129 | Return TRUE if that warnings category is enabled in the first scope |
1130 | where the object is used. | |
1131 | Otherwise returns FALSE. | |
a7f2b7af | 1132 | |
effd17dc | 1133 | =item warnings::fatal_enabled() |
599cee73 | 1134 | |
effd17dc DD |
1135 | Return TRUE if the warnings category with the same name as the current |
1136 | package has been set to FATAL in the calling module. | |
1137 | Otherwise returns FALSE. | |
6e9af7e4 | 1138 | |
effd17dc | 1139 | =item warnings::fatal_enabled($category) |
6e9af7e4 | 1140 | |
effd17dc DD |
1141 | Return TRUE if the warnings category C<$category> has been set to FATAL in |
1142 | the calling module. | |
1143 | Otherwise returns FALSE. | |
6e9af7e4 | 1144 | |
effd17dc | 1145 | =item warnings::fatal_enabled($object) |
6e9af7e4 | 1146 | |
effd17dc DD |
1147 | Use the name of the class for the object reference, C<$object>, as the |
1148 | warnings category. | |
6e9af7e4 | 1149 | |
effd17dc DD |
1150 | Return TRUE if that warnings category has been set to FATAL in the first |
1151 | scope where the object is used. | |
1152 | Otherwise returns FALSE. | |
599cee73 | 1153 | |
effd17dc | 1154 | =item warnings::warn($message) |
9df0f64f | 1155 | |
effd17dc | 1156 | Print C<$message> to STDERR. |
8787a747 | 1157 | |
effd17dc | 1158 | Use the warnings category with the same name as the current package. |
96183d25 | 1159 | |
effd17dc DD |
1160 | If that warnings category has been set to "FATAL" in the calling module |
1161 | then die. Otherwise return. | |
96183d25 | 1162 | |
effd17dc | 1163 | =item warnings::warn($category, $message) |
d3a7d8c7 | 1164 | |
effd17dc | 1165 | Print C<$message> to STDERR. |
d3a7d8c7 | 1166 | |
effd17dc DD |
1167 | If the warnings category, C<$category>, has been set to "FATAL" in the |
1168 | calling module then die. Otherwise return. | |
7e6d00f8 | 1169 | |
effd17dc | 1170 | =item warnings::warn($object, $message) |
7e6d00f8 | 1171 | |
effd17dc | 1172 | Print C<$message> to STDERR. |
8787a747 | 1173 | |
effd17dc DD |
1174 | Use the name of the class for the object reference, C<$object>, as the |
1175 | warnings category. | |
8787a747 | 1176 | |
effd17dc DD |
1177 | If that warnings category has been set to "FATAL" in the scope where C<$object> |
1178 | is first used then die. Otherwise return. | |
96183d25 | 1179 | |
96183d25 | 1180 | |
effd17dc | 1181 | =item warnings::warnif($message) |
96183d25 | 1182 | |
effd17dc | 1183 | Equivalent to: |
7e6d00f8 | 1184 | |
effd17dc DD |
1185 | if (warnings::enabled()) |
1186 | { warnings::warn($message) } | |
572bfd36 | 1187 | |
effd17dc | 1188 | =item warnings::warnif($category, $message) |
572bfd36 | 1189 | |
effd17dc | 1190 | Equivalent to: |
572bfd36 | 1191 | |
effd17dc DD |
1192 | if (warnings::enabled($category)) |
1193 | { warnings::warn($category, $message) } | |
572bfd36 | 1194 | |
effd17dc | 1195 | =item warnings::warnif($object, $message) |
4f527b71 | 1196 | |
effd17dc | 1197 | Equivalent to: |
599cee73 | 1198 | |
effd17dc DD |
1199 | if (warnings::enabled($object)) |
1200 | { warnings::warn($object, $message) } | |
d3a7d8c7 | 1201 | |
effd17dc | 1202 | =item warnings::register_categories(@names) |
e476b1b5 | 1203 | |
effd17dc DD |
1204 | This registers warning categories for the given names and is primarily for |
1205 | use by the warnings::register pragma. | |
0d658bf5 | 1206 | |
effd17dc | 1207 | =back |
8787a747 | 1208 | |
effd17dc DD |
1209 | See also L<perlmodlib/Pragmatic Modules> and L<perldiag>. |
1210 | ||
1211 | =cut | |
ce716c52 | 1212 | |
37442d52 | 1213 | # ex: set ro: |