2 # !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
3 # This file was created by warnings.pl
4 # Any changes made here will be lost.
13 warnings - Perl pragma to control optional warnings
23 use warnings::register;
24 if (warnings::enabled()) {
25 warnings::warn("some warning");
28 if (warnings::enabled("void")) {
29 warnings::warn("void", "some warning");
32 if (warnings::enabled($object)) {
33 warnings::warn($object, "some warning");
36 warnings::warnif("some warning");
37 warnings::warnif("void", "some warning");
38 warnings::warnif($object, "some warning");
42 The C<warnings> pragma is a replacement for the command line flag C<-w>,
43 but the pragma is limited to the enclosing block, while the flag is global.
44 See L<perllexwarn> for more information.
46 If no import list is supplied, all possible warnings are either enabled
49 A number of functions are provided to assist module authors.
53 =item use warnings::register
55 Creates a new warnings category with the same name as the package where
56 the call to the pragma is used.
58 =item warnings::enabled()
60 Use the warnings category with the same name as the current package.
62 Return TRUE if that warnings category is enabled in the calling module.
63 Otherwise returns FALSE.
65 =item warnings::enabled($category)
67 Return TRUE if the warnings category, C<$category>, is enabled in the
69 Otherwise returns FALSE.
71 =item warnings::enabled($object)
73 Use the name of the class for the object reference, C<$object>, as the
76 Return TRUE if that warnings category is enabled in the first scope
77 where the object is used.
78 Otherwise returns FALSE.
80 =item warnings::warn($message)
82 Print C<$message> to STDERR.
84 Use the warnings category with the same name as the current package.
86 If that warnings category has been set to "FATAL" in the calling module
87 then die. Otherwise return.
89 =item warnings::warn($category, $message)
91 Print C<$message> to STDERR.
93 If the warnings category, C<$category>, has been set to "FATAL" in the
94 calling module then die. Otherwise return.
96 =item warnings::warn($object, $message)
98 Print C<$message> to STDERR.
100 Use the name of the class for the object reference, C<$object>, as the
103 If that warnings category has been set to "FATAL" in the scope where C<$object>
104 is first used then die. Otherwise return.
107 =item warnings::warnif($message)
111 if (warnings::enabled())
112 { warnings::warn($message) }
114 =item warnings::warnif($category, $message)
118 if (warnings::enabled($category))
119 { warnings::warn($category, $message) }
121 =item warnings::warnif($object, $message)
125 if (warnings::enabled($object))
126 { warnings::warn($object, $message) }
130 See L<perlmodlib/Pragmatic Modules> and L<perllexwarn>.
136 our %Offsets : unique = (
138 # Warnings Categories added in Perl 5.008
181 'uninitialized' => 82,
188 # Warnings Categories added in Perl 5.009
193 our %Bits : unique = (
194 'all' => "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55", # [0..47]
195 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00", # [29]
196 'assertions' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40", # [47]
197 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00", # [30]
198 'closed' => "\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
199 'closure' => "\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
200 'debugging' => "\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00", # [22]
201 'deprecated' => "\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
202 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00", # [31]
203 'exec' => "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
204 'exiting' => "\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
205 'glob' => "\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
206 'inplace' => "\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00", # [23]
207 'internal' => "\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00", # [24]
208 'io' => "\x00\x54\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [5..11]
209 'layer' => "\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
210 'malloc' => "\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00", # [25]
211 'misc' => "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
212 'newline' => "\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
213 'numeric' => "\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
214 'once' => "\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
215 'overflow' => "\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
216 'pack' => "\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00", # [16]
217 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00", # [32]
218 'pipe' => "\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
219 'portable' => "\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00", # [17]
220 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00", # [33]
221 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00", # [34]
222 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00", # [35]
223 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00", # [36]
224 'recursion' => "\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00", # [18]
225 'redefine' => "\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00", # [19]
226 'regexp' => "\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00", # [20]
227 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00", # [37]
228 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00", # [38]
229 'severe' => "\x00\x00\x00\x00\x00\x54\x05\x00\x00\x00\x00\x00", # [21..25]
230 'signal' => "\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00", # [26]
231 'substr' => "\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00", # [27]
232 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\x55\x55\x15\x00\x00", # [28..38]
233 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00", # [39]
234 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00", # [40]
235 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00", # [41]
236 'unopened' => "\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
237 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00", # [42]
238 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00", # [43]
239 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", # [44]
240 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04", # [45]
241 'y2k' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10", # [46]
244 our %DeadBits : unique = (
245 'all' => "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", # [0..47]
246 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00", # [29]
247 'assertions' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80", # [47]
248 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00", # [30]
249 'closed' => "\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
250 'closure' => "\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
251 'debugging' => "\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00", # [22]
252 'deprecated' => "\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
253 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00", # [31]
254 'exec' => "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
255 'exiting' => "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
256 'glob' => "\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
257 'inplace' => "\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00", # [23]
258 'internal' => "\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00", # [24]
259 'io' => "\x00\xa8\xaa\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [5..11]
260 'layer' => "\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
261 'malloc' => "\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00", # [25]
262 'misc' => "\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
263 'newline' => "\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
264 'numeric' => "\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
265 'once' => "\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
266 'overflow' => "\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
267 'pack' => "\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", # [16]
268 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00", # [32]
269 'pipe' => "\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
270 'portable' => "\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00", # [17]
271 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00", # [33]
272 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00", # [34]
273 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00", # [35]
274 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00", # [36]
275 'recursion' => "\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00", # [18]
276 'redefine' => "\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00", # [19]
277 'regexp' => "\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00", # [20]
278 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00", # [37]
279 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00", # [38]
280 'severe' => "\x00\x00\x00\x00\x00\xa8\x0a\x00\x00\x00\x00\x00", # [21..25]
281 'signal' => "\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00", # [26]
282 'substr' => "\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00", # [27]
283 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\xaa\xaa\x2a\x00\x00", # [28..38]
284 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00", # [39]
285 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00", # [40]
286 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00", # [41]
287 'unopened' => "\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
288 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00", # [42]
289 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00", # [43]
290 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02", # [44]
291 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08", # [45]
292 'y2k' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20", # [46]
295 $NONE = "\0\0\0\0\0\0\0\0\0\0\0\0";
299 $All = "" ; vec($All, $Offsets{'all'}, 2) = 3 ;
303 delete $Carp::CarpInternal{'warnings'};
309 # called from B::Deparse.pm
311 push @_, 'all' unless @_;
318 foreach my $word ( @_ ) {
319 if ($word eq 'FATAL') {
323 elsif ($word eq 'NONFATAL') {
327 elsif ($catmask = $Bits{$word}) {
329 $mask |= $DeadBits{$word} if $fatal ;
330 $mask &= ~($DeadBits{$word}|$All) if $no_fatal ;
333 { Croaker("Unknown warnings category '$word'")}
347 my $mask = ${^WARNING_BITS} ;
349 if (vec($mask, $Offsets{'all'}, 1)) {
350 $mask |= $Bits{'all'} ;
351 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
354 push @_, 'all' unless @_;
356 foreach my $word ( @_ ) {
357 if ($word eq 'FATAL') {
361 elsif ($word eq 'NONFATAL') {
365 elsif ($catmask = $Bits{$word}) {
367 $mask |= $DeadBits{$word} if $fatal ;
368 $mask &= ~($DeadBits{$word}|$All) if $no_fatal ;
371 { Croaker("Unknown warnings category '$word'")}
374 ${^WARNING_BITS} = $mask ;
382 my $mask = ${^WARNING_BITS} ;
384 if (vec($mask, $Offsets{'all'}, 1)) {
385 $mask |= $Bits{'all'} ;
386 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
389 push @_, 'all' unless @_;
391 foreach my $word ( @_ ) {
392 if ($word eq 'FATAL') {
395 elsif ($catmask = $Bits{$word}) {
396 $mask &= ~($catmask | $DeadBits{$word} | $All);
399 { Croaker("Unknown warnings category '$word'")}
402 ${^WARNING_BITS} = $mask ;
412 # check the category supplied.
415 Croaker ("not an object")
416 if $category !~ /^([^=]+)=/ ;
420 $offset = $Offsets{$category};
421 Croaker("Unknown warnings category '$category'")
422 unless defined $offset;
425 $category = (caller(1))[0] ;
426 $offset = $Offsets{$category};
427 Croaker("package '$category' not registered for warnings")
428 unless defined $offset ;
431 my $this_pkg = (caller(1))[0] ;
436 while (do { { package DB; $pkg = (caller($i++))[0] } } ) {
437 last unless @DB::args && $DB::args[0] =~ /^$category=/ ;
442 $i = _error_loc(); # see where Carp will allocate the error
445 my $callers_bitmask = (caller($i))[9] ;
446 return ($callers_bitmask, $offset, $i) ;
451 goto &Carp::short_error_loc; # don't introduce another stack frame
456 Croaker("Usage: warnings::enabled([category])")
457 unless @_ == 1 || @_ == 0 ;
459 my ($callers_bitmask, $offset, $i) = __chk(@_) ;
461 return 0 unless defined $callers_bitmask ;
462 return vec($callers_bitmask, $offset, 1) ||
463 vec($callers_bitmask, $Offsets{'all'}, 1) ;
469 Croaker("Usage: warnings::warn([category,] 'message')")
470 unless @_ == 2 || @_ == 1 ;
473 my ($callers_bitmask, $offset, $i) = __chk(@_) ;
474 Carp::croak($message)
475 if vec($callers_bitmask, $offset+1, 1) ||
476 vec($callers_bitmask, $Offsets{'all'}+1, 1) ;
477 Carp::carp($message) ;
482 Croaker("Usage: warnings::warnif([category,] 'message')")
483 unless @_ == 2 || @_ == 1 ;
486 my ($callers_bitmask, $offset, $i) = __chk(@_) ;
489 unless defined $callers_bitmask &&
490 (vec($callers_bitmask, $offset, 1) ||
491 vec($callers_bitmask, $Offsets{'all'}, 1)) ;
493 Carp::croak($message)
494 if vec($callers_bitmask, $offset+1, 1) ||
495 vec($callers_bitmask, $Offsets{'all'}+1, 1) ;
497 Carp::carp($message) ;