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 # Warnings Categories added in Perl 5.008
179 'uninitialized' => 82,
186 # Warnings Categories added in Perl 5.009
192 'all' => "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55", # [0..47]
193 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00", # [29]
194 'assertions' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40", # [47]
195 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00", # [30]
196 'closed' => "\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
197 'closure' => "\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
198 'debugging' => "\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00", # [22]
199 'deprecated' => "\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
200 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00", # [31]
201 'exec' => "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
202 'exiting' => "\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
203 'glob' => "\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
204 'inplace' => "\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00", # [23]
205 'internal' => "\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00", # [24]
206 'io' => "\x00\x54\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [5..11]
207 'layer' => "\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
208 'malloc' => "\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00", # [25]
209 'misc' => "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
210 'newline' => "\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
211 'numeric' => "\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
212 'once' => "\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
213 'overflow' => "\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
214 'pack' => "\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00", # [16]
215 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00", # [32]
216 'pipe' => "\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
217 'portable' => "\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00", # [17]
218 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00", # [33]
219 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00", # [34]
220 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00", # [35]
221 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00", # [36]
222 'recursion' => "\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00", # [18]
223 'redefine' => "\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00", # [19]
224 'regexp' => "\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00", # [20]
225 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00", # [37]
226 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00", # [38]
227 'severe' => "\x00\x00\x00\x00\x00\x54\x05\x00\x00\x00\x00\x00", # [21..25]
228 'signal' => "\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00", # [26]
229 'substr' => "\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00", # [27]
230 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\x55\x55\x15\x00\x00", # [28..38]
231 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00", # [39]
232 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00", # [40]
233 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00", # [41]
234 'unopened' => "\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
235 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00", # [42]
236 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00", # [43]
237 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", # [44]
238 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04", # [45]
239 'y2k' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10", # [46]
243 'all' => "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", # [0..47]
244 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00", # [29]
245 'assertions' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80", # [47]
246 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00", # [30]
247 'closed' => "\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
248 'closure' => "\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
249 'debugging' => "\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00", # [22]
250 'deprecated' => "\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
251 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00", # [31]
252 'exec' => "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
253 'exiting' => "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
254 'glob' => "\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
255 'inplace' => "\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00", # [23]
256 'internal' => "\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00", # [24]
257 'io' => "\x00\xa8\xaa\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [5..11]
258 'layer' => "\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
259 'malloc' => "\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00", # [25]
260 'misc' => "\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
261 'newline' => "\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
262 'numeric' => "\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
263 'once' => "\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
264 'overflow' => "\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
265 'pack' => "\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", # [16]
266 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00", # [32]
267 'pipe' => "\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
268 'portable' => "\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00", # [17]
269 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00", # [33]
270 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00", # [34]
271 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00", # [35]
272 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00", # [36]
273 'recursion' => "\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00", # [18]
274 'redefine' => "\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00", # [19]
275 'regexp' => "\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00", # [20]
276 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00", # [37]
277 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00", # [38]
278 'severe' => "\x00\x00\x00\x00\x00\xa8\x0a\x00\x00\x00\x00\x00", # [21..25]
279 'signal' => "\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00", # [26]
280 'substr' => "\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00", # [27]
281 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\xaa\xaa\x2a\x00\x00", # [28..38]
282 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00", # [39]
283 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00", # [40]
284 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00", # [41]
285 'unopened' => "\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
286 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00", # [42]
287 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00", # [43]
288 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02", # [44]
289 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08", # [45]
290 'y2k' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20", # [46]
293 $NONE = "\0\0\0\0\0\0\0\0\0\0\0\0";
297 $All = "" ; vec($All, $Offsets{'all'}, 2) = 3 ;
302 delete $Carp::CarpInternal{'warnings'};
308 # called from B::Deparse.pm
310 push @_, 'all' unless @_;
317 foreach my $word ( @_ ) {
318 if ($word eq 'FATAL') {
322 elsif ($word eq 'NONFATAL') {
326 elsif ($catmask = $Bits{$word}) {
328 $mask |= $DeadBits{$word} if $fatal ;
329 $mask &= ~($DeadBits{$word}|$All) if $no_fatal ;
332 { Croaker("Unknown warnings category '$word'")}
346 my $mask = ${^WARNING_BITS} ;
348 if (vec($mask, $Offsets{'all'}, 1)) {
349 $mask |= $Bits{'all'} ;
350 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
353 push @_, 'all' unless @_;
355 foreach my $word ( @_ ) {
356 if ($word eq 'FATAL') {
360 elsif ($word eq 'NONFATAL') {
364 elsif ($catmask = $Bits{$word}) {
366 $mask |= $DeadBits{$word} if $fatal ;
367 $mask &= ~($DeadBits{$word}|$All) if $no_fatal ;
370 { Croaker("Unknown warnings category '$word'")}
373 ${^WARNING_BITS} = $mask ;
381 my $mask = ${^WARNING_BITS} ;
383 if (vec($mask, $Offsets{'all'}, 1)) {
384 $mask |= $Bits{'all'} ;
385 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
388 push @_, 'all' unless @_;
390 foreach my $word ( @_ ) {
391 if ($word eq 'FATAL') {
394 elsif ($catmask = $Bits{$word}) {
395 $mask &= ~($catmask | $DeadBits{$word} | $All);
398 { Croaker("Unknown warnings category '$word'")}
401 ${^WARNING_BITS} = $mask ;
404 my %builtin_type; @builtin_type{qw(SCALAR ARRAY HASH CODE REF GLOB LVALUE Regexp)} = ();
413 # check the category supplied.
415 if (my $type = ref $category) {
416 Croaker("not an object")
417 if exists $builtin_type{$type};
421 $offset = $Offsets{$category};
422 Croaker("Unknown warnings category '$category'")
423 unless defined $offset;
426 $category = (caller(1))[0] ;
427 $offset = $Offsets{$category};
428 Croaker("package '$category' not registered for warnings")
429 unless defined $offset ;
432 my $this_pkg = (caller(1))[0] ;
437 while (do { { package DB; $pkg = (caller($i++))[0] } } ) {
438 last unless @DB::args && $DB::args[0] =~ /^$category=/ ;
443 $i = _error_loc(); # see where Carp will allocate the error
446 my $callers_bitmask = (caller($i))[9] ;
447 return ($callers_bitmask, $offset, $i) ;
452 goto &Carp::short_error_loc; # don't introduce another stack frame
457 Croaker("Usage: warnings::enabled([category])")
458 unless @_ == 1 || @_ == 0 ;
460 my ($callers_bitmask, $offset, $i) = __chk(@_) ;
462 return 0 unless defined $callers_bitmask ;
463 return vec($callers_bitmask, $offset, 1) ||
464 vec($callers_bitmask, $Offsets{'all'}, 1) ;
470 Croaker("Usage: warnings::warn([category,] 'message')")
471 unless @_ == 2 || @_ == 1 ;
474 my ($callers_bitmask, $offset, $i) = __chk(@_) ;
476 Carp::croak($message)
477 if vec($callers_bitmask, $offset+1, 1) ||
478 vec($callers_bitmask, $Offsets{'all'}+1, 1) ;
479 Carp::carp($message) ;
484 Croaker("Usage: warnings::warnif([category,] 'message')")
485 unless @_ == 2 || @_ == 1 ;
488 my ($callers_bitmask, $offset, $i) = __chk(@_) ;
491 unless defined $callers_bitmask &&
492 (vec($callers_bitmask, $offset, 1) ||
493 vec($callers_bitmask, $Offsets{'all'}, 1)) ;
496 Carp::croak($message)
497 if vec($callers_bitmask, $offset+1, 1) ||
498 vec($callers_bitmask, $Offsets{'all'}+1, 1) ;
500 Carp::carp($message) ;