2 # This file was created by warnings.pl
3 # Any changes made here will be lost.
10 warnings - Perl pragma to control optional warnings
20 use warnings::register;
21 if (warnings::enabled()) {
22 warnings::warn("some warning");
25 if (warnings::enabled("void")) {
26 warnings::warn("void", "some warning");
29 if (warnings::enabled($object)) {
30 warnings::warn($object, "some warning");
33 warnif("some warning");
34 warnif("void", "some warning");
35 warnif($object, "some warning");
39 If no import list is supplied, all possible warnings are either enabled
42 A number of functions are provided to assist module authors.
46 =item use warnings::register
48 Creates a new warnings category with the same name as the package where
49 the call to the pragma is used.
51 =item warnings::enabled()
53 Use the warnings category with the same name as the current package.
55 Return TRUE if that warnings category is enabled in the calling module.
56 Otherwise returns FALSE.
58 =item warnings::enabled($category)
60 Return TRUE if the warnings category, C<$category>, is enabled in the
62 Otherwise returns FALSE.
64 =item warnings::enabled($object)
66 Use the name of the class for the object reference, C<$object>, as the
69 Return TRUE if that warnings category is enabled in the first scope
70 where the object is used.
71 Otherwise returns FALSE.
73 =item warnings::warn($message)
75 Print C<$message> to STDERR.
77 Use the warnings category with the same name as the current package.
79 If that warnings category has been set to "FATAL" in the calling module
80 then die. Otherwise return.
82 =item warnings::warn($category, $message)
84 Print C<$message> to STDERR.
86 If the warnings category, C<$category>, has been set to "FATAL" in the
87 calling module then die. Otherwise return.
89 =item warnings::warn($object, $message)
91 Print C<$message> to STDERR.
93 Use the name of the class for the object reference, C<$object>, as the
96 If that warnings category has been set to "FATAL" in the scope where C<$object>
97 is first used then die. Otherwise return.
100 =item warnings::warnif($message)
104 if (warnings::enabled())
105 { warnings::warn($message) }
107 =item warnings::warnif($category, $message)
111 if (warnings::enabled($category))
112 { warnings::warn($category, $message) }
114 =item warnings::warnif($object, $message)
118 if (warnings::enabled($object))
119 { warnings::warn($object, $message) }
123 See L<perlmodlib/Pragmatic Modules> and L<perllexwarn>.
171 'uninitialized' => 82,
180 'all' => "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x15", # [0..46]
181 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00", # [28]
182 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00", # [29]
183 'chmod' => "\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
184 'closed' => "\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
185 'closure' => "\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
186 'debugging' => "\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00", # [21]
187 'deprecated' => "\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00", # [30]
188 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00", # [31]
189 'exec' => "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
190 'exiting' => "\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
191 'glob' => "\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
192 'inplace' => "\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00", # [22]
193 'internal' => "\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00", # [23]
194 'io' => "\x00\x54\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [5..10]
195 'malloc' => "\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00", # [24]
196 'misc' => "\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
197 'newline' => "\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
198 'numeric' => "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
199 'once' => "\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
200 'overflow' => "\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
201 'pack' => "\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
202 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00", # [32]
203 'pipe' => "\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
204 'portable' => "\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00", # [16]
205 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00", # [33]
206 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00", # [34]
207 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00", # [35]
208 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00", # [36]
209 'recursion' => "\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00", # [17]
210 'redefine' => "\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00", # [18]
211 'regexp' => "\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00", # [19]
212 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00", # [37]
213 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00", # [38]
214 'severe' => "\x00\x00\x00\x00\x00\x55\x01\x00\x00\x00\x00\x00", # [20..24]
215 'signal' => "\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00", # [25]
216 'substr' => "\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00", # [26]
217 'syntax' => "\x00\x00\x00\x00\x00\x00\x40\x55\x55\x15\x00\x00", # [27..38]
218 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00", # [39]
219 'umask' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00", # [40]
220 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00", # [41]
221 'unopened' => "\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
222 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00", # [42]
223 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00", # [43]
224 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", # [44]
225 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04", # [45]
226 'y2k' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10", # [46]
230 'all' => "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\x2a", # [0..46]
231 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00", # [28]
232 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00", # [29]
233 'chmod' => "\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
234 'closed' => "\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
235 'closure' => "\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
236 'debugging' => "\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00", # [21]
237 'deprecated' => "\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00", # [30]
238 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00", # [31]
239 'exec' => "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
240 'exiting' => "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
241 'glob' => "\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
242 'inplace' => "\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00", # [22]
243 'internal' => "\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00", # [23]
244 'io' => "\x00\xa8\x2a\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [5..10]
245 'malloc' => "\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00", # [24]
246 'misc' => "\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
247 'newline' => "\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
248 'numeric' => "\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
249 'once' => "\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
250 'overflow' => "\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
251 'pack' => "\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
252 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00", # [32]
253 'pipe' => "\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
254 'portable' => "\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", # [16]
255 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00", # [33]
256 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00", # [34]
257 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00", # [35]
258 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00", # [36]
259 'recursion' => "\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00", # [17]
260 'redefine' => "\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00", # [18]
261 'regexp' => "\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00", # [19]
262 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00", # [37]
263 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00", # [38]
264 'severe' => "\x00\x00\x00\x00\x00\xaa\x02\x00\x00\x00\x00\x00", # [20..24]
265 'signal' => "\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00", # [25]
266 'substr' => "\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00", # [26]
267 'syntax' => "\x00\x00\x00\x00\x00\x00\x80\xaa\xaa\x2a\x00\x00", # [27..38]
268 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00", # [39]
269 'umask' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00", # [40]
270 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00", # [41]
271 'unopened' => "\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
272 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00", # [42]
273 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00", # [43]
274 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02", # [44]
275 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08", # [45]
276 'y2k' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20", # [46]
279 $NONE = "\0\0\0\0\0\0\0\0\0\0\0\0";
283 $All = "" ; vec($All, $Offsets{'all'}, 2) = 3 ;
289 foreach my $word (@_) {
290 if ($word eq 'FATAL') {
293 elsif ($catmask = $Bits{$word}) {
295 $mask |= $DeadBits{$word} if $fatal ;
298 { croak("unknown warnings category '$word'")}
306 ${^WARNING_BITS} |= bits(@_ ? @_ : 'all') ;
311 my $mask = ${^WARNING_BITS} ;
312 if (vec($mask, $Offsets{'all'}, 1)) {
313 $mask = $Bits{'all'} ;
314 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
316 ${^WARNING_BITS} = $mask & ~ (bits(@_ ? @_ : 'all') | $All) ;
326 # check the category supplied.
329 croak ("not an object")
330 if $category !~ /^([^=]+)=/ ;+
334 $offset = $Offsets{$category};
335 croak("unknown warnings category '$category'")
336 unless defined $offset;
339 $category = (caller(1))[0] ;
340 $offset = $Offsets{$category};
341 croak("package '$category' not registered for warnings")
342 unless defined $offset ;
345 my $this_pkg = (caller(1))[0] ;
350 while (do { { package DB; $pkg = (caller($i++))[0] } } ) {
351 last unless @DB::args && $DB::args[0] =~ /^$category=/ ;
356 for ($i = 2 ; $pkg = (caller($i))[0] ; ++ $i) {
357 last if $pkg ne $this_pkg ;
360 if !$pkg || $pkg eq $this_pkg ;
363 my $callers_bitmask = (caller($i))[9] ;
364 return ($callers_bitmask, $offset, $i) ;
369 croak("Usage: warnings::enabled([category])")
370 unless @_ == 1 || @_ == 0 ;
372 my ($callers_bitmask, $offset, $i) = __chk(@_) ;
374 return 0 unless defined $callers_bitmask ;
375 return vec($callers_bitmask, $offset, 1) ||
376 vec($callers_bitmask, $Offsets{'all'}, 1) ;
382 croak("Usage: warnings::warn([category,] 'message')")
383 unless @_ == 2 || @_ == 1 ;
386 my ($callers_bitmask, $offset, $i) = __chk(@_) ;
387 local $Carp::CarpLevel = $i ;
389 if vec($callers_bitmask, $offset+1, 1) ||
390 vec($callers_bitmask, $Offsets{'all'}+1, 1) ;
396 croak("Usage: warnings::warnif([category,] 'message')")
397 unless @_ == 2 || @_ == 1 ;
400 my ($callers_bitmask, $offset, $i) = __chk(@_) ;
401 local $Carp::CarpLevel = $i ;
404 unless defined $callers_bitmask &&
405 (vec($callers_bitmask, $offset, 1) ||
406 vec($callers_bitmask, $Offsets{'all'}, 1)) ;
409 if vec($callers_bitmask, $offset+1, 1) ||
410 vec($callers_bitmask, $Offsets{'all'}+1, 1) ;