1 # -*- buffer-read-only: t -*-
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,
185 # Warnings Categories added in Perl 5.009
191 'all' => "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x15", # [0..46]
192 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00", # [29]
193 'assertions' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10", # [46]
194 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00", # [30]
195 'closed' => "\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
196 'closure' => "\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
197 'debugging' => "\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00", # [22]
198 'deprecated' => "\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
199 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00", # [31]
200 'exec' => "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
201 'exiting' => "\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
202 'glob' => "\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
203 'inplace' => "\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00", # [23]
204 'internal' => "\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00", # [24]
205 'io' => "\x00\x54\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [5..11]
206 'layer' => "\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
207 'malloc' => "\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00", # [25]
208 'misc' => "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
209 'newline' => "\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
210 'numeric' => "\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
211 'once' => "\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
212 'overflow' => "\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
213 'pack' => "\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00", # [16]
214 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00", # [32]
215 'pipe' => "\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
216 'portable' => "\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00", # [17]
217 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00", # [33]
218 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00", # [34]
219 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00", # [35]
220 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00", # [36]
221 'recursion' => "\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00", # [18]
222 'redefine' => "\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00", # [19]
223 'regexp' => "\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00", # [20]
224 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00", # [37]
225 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00", # [38]
226 'severe' => "\x00\x00\x00\x00\x00\x54\x05\x00\x00\x00\x00\x00", # [21..25]
227 'signal' => "\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00", # [26]
228 'substr' => "\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00", # [27]
229 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\x55\x55\x15\x00\x00", # [28..38]
230 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00", # [39]
231 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00", # [40]
232 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00", # [41]
233 'unopened' => "\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
234 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00", # [42]
235 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00", # [43]
236 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", # [44]
237 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04", # [45]
241 'all' => "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\x2a", # [0..46]
242 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00", # [29]
243 'assertions' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20", # [46]
244 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00", # [30]
245 'closed' => "\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
246 'closure' => "\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
247 'debugging' => "\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00", # [22]
248 'deprecated' => "\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
249 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00", # [31]
250 'exec' => "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
251 'exiting' => "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
252 'glob' => "\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
253 'inplace' => "\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00", # [23]
254 'internal' => "\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00", # [24]
255 'io' => "\x00\xa8\xaa\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [5..11]
256 'layer' => "\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
257 'malloc' => "\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00", # [25]
258 'misc' => "\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
259 'newline' => "\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
260 'numeric' => "\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
261 'once' => "\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
262 'overflow' => "\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
263 'pack' => "\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", # [16]
264 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00", # [32]
265 'pipe' => "\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
266 'portable' => "\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00", # [17]
267 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00", # [33]
268 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00", # [34]
269 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00", # [35]
270 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00", # [36]
271 'recursion' => "\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00", # [18]
272 'redefine' => "\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00", # [19]
273 'regexp' => "\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00", # [20]
274 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00", # [37]
275 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00", # [38]
276 'severe' => "\x00\x00\x00\x00\x00\xa8\x0a\x00\x00\x00\x00\x00", # [21..25]
277 'signal' => "\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00", # [26]
278 'substr' => "\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00", # [27]
279 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\xaa\xaa\x2a\x00\x00", # [28..38]
280 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00", # [39]
281 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00", # [40]
282 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00", # [41]
283 'unopened' => "\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
284 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00", # [42]
285 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00", # [43]
286 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02", # [44]
287 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08", # [45]
290 $NONE = "\0\0\0\0\0\0\0\0\0\0\0\0";
294 $All = "" ; vec($All, $Offsets{'all'}, 2) = 3 ;
299 delete $Carp::CarpInternal{'warnings'};
305 # called from B::Deparse.pm
307 push @_, 'all' unless @_;
314 foreach my $word ( @_ ) {
315 if ($word eq 'FATAL') {
319 elsif ($word eq 'NONFATAL') {
323 elsif ($catmask = $Bits{$word}) {
325 $mask |= $DeadBits{$word} if $fatal ;
326 $mask &= ~($DeadBits{$word}|$All) if $no_fatal ;
329 { Croaker("Unknown warnings category '$word'")}
343 my $mask = ${^WARNING_BITS} ;
345 if (vec($mask, $Offsets{'all'}, 1)) {
346 $mask |= $Bits{'all'} ;
347 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
350 push @_, 'all' unless @_;
352 foreach my $word ( @_ ) {
353 if ($word eq 'FATAL') {
357 elsif ($word eq 'NONFATAL') {
361 elsif ($catmask = $Bits{$word}) {
363 $mask |= $DeadBits{$word} if $fatal ;
364 $mask &= ~($DeadBits{$word}|$All) if $no_fatal ;
367 { Croaker("Unknown warnings category '$word'")}
370 ${^WARNING_BITS} = $mask ;
378 my $mask = ${^WARNING_BITS} ;
380 if (vec($mask, $Offsets{'all'}, 1)) {
381 $mask |= $Bits{'all'} ;
382 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
385 push @_, 'all' unless @_;
387 foreach my $word ( @_ ) {
388 if ($word eq 'FATAL') {
391 elsif ($catmask = $Bits{$word}) {
392 $mask &= ~($catmask | $DeadBits{$word} | $All);
395 { Croaker("Unknown warnings category '$word'")}
398 ${^WARNING_BITS} = $mask ;
401 my %builtin_type; @builtin_type{qw(SCALAR ARRAY HASH CODE REF GLOB LVALUE Regexp)} = ();
410 # check the category supplied.
412 if (my $type = ref $category) {
413 Croaker("not an object")
414 if exists $builtin_type{$type};
418 $offset = $Offsets{$category};
419 Croaker("Unknown warnings category '$category'")
420 unless defined $offset;
423 $category = (caller(1))[0] ;
424 $offset = $Offsets{$category};
425 Croaker("package '$category' not registered for warnings")
426 unless defined $offset ;
429 my $this_pkg = (caller(1))[0] ;
434 while (do { { package DB; $pkg = (caller($i++))[0] } } ) {
435 last unless @DB::args && $DB::args[0] =~ /^$category=/ ;
440 $i = _error_loc(); # see where Carp will allocate the error
443 my $callers_bitmask = (caller($i))[9] ;
444 return ($callers_bitmask, $offset, $i) ;
449 goto &Carp::short_error_loc; # don't introduce another stack frame
454 Croaker("Usage: warnings::enabled([category])")
455 unless @_ == 1 || @_ == 0 ;
457 my ($callers_bitmask, $offset, $i) = __chk(@_) ;
459 return 0 unless defined $callers_bitmask ;
460 return vec($callers_bitmask, $offset, 1) ||
461 vec($callers_bitmask, $Offsets{'all'}, 1) ;
467 Croaker("Usage: warnings::warn([category,] 'message')")
468 unless @_ == 2 || @_ == 1 ;
471 my ($callers_bitmask, $offset, $i) = __chk(@_) ;
473 Carp::croak($message)
474 if vec($callers_bitmask, $offset+1, 1) ||
475 vec($callers_bitmask, $Offsets{'all'}+1, 1) ;
476 Carp::carp($message) ;
481 Croaker("Usage: warnings::warnif([category,] 'message')")
482 unless @_ == 2 || @_ == 1 ;
485 my ($callers_bitmask, $offset, $i) = __chk(@_) ;
488 unless defined $callers_bitmask &&
489 (vec($callers_bitmask, $offset, 1) ||
490 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) ;