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>.
138 # Warnings Categories added in Perl 5.008
181 'uninitialized' => 82,
190 'all' => "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x15", # [0..46]
191 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00", # [29]
192 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00", # [30]
193 'closed' => "\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
194 'closure' => "\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
195 'debugging' => "\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00", # [22]
196 'deprecated' => "\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
197 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00", # [31]
198 'exec' => "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
199 'exiting' => "\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
200 'glob' => "\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
201 'inplace' => "\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00", # [23]
202 'internal' => "\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00", # [24]
203 'io' => "\x00\x54\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [5..11]
204 'layer' => "\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
205 'malloc' => "\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00", # [25]
206 'misc' => "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
207 'newline' => "\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
208 'numeric' => "\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
209 'once' => "\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
210 'overflow' => "\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
211 'pack' => "\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00", # [16]
212 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00", # [32]
213 'pipe' => "\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
214 'portable' => "\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00", # [17]
215 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00", # [33]
216 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00", # [34]
217 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00", # [35]
218 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00", # [36]
219 'recursion' => "\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00", # [18]
220 'redefine' => "\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00", # [19]
221 'regexp' => "\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00", # [20]
222 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00", # [37]
223 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00", # [38]
224 'severe' => "\x00\x00\x00\x00\x00\x54\x05\x00\x00\x00\x00\x00", # [21..25]
225 'signal' => "\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00", # [26]
226 'substr' => "\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00", # [27]
227 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\x55\x55\x15\x00\x00", # [28..38]
228 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00", # [39]
229 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00", # [40]
230 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00", # [41]
231 'unopened' => "\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
232 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00", # [42]
233 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00", # [43]
234 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", # [44]
235 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04", # [45]
236 'y2k' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10", # [46]
240 'all' => "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\x2a", # [0..46]
241 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00", # [29]
242 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00", # [30]
243 'closed' => "\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
244 'closure' => "\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
245 'debugging' => "\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00", # [22]
246 'deprecated' => "\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
247 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00", # [31]
248 'exec' => "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
249 'exiting' => "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
250 'glob' => "\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
251 'inplace' => "\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00", # [23]
252 'internal' => "\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00", # [24]
253 'io' => "\x00\xa8\xaa\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [5..11]
254 'layer' => "\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
255 'malloc' => "\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00", # [25]
256 'misc' => "\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
257 'newline' => "\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
258 'numeric' => "\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
259 'once' => "\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
260 'overflow' => "\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
261 'pack' => "\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", # [16]
262 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00", # [32]
263 'pipe' => "\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
264 'portable' => "\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00", # [17]
265 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00", # [33]
266 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00", # [34]
267 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00", # [35]
268 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00", # [36]
269 'recursion' => "\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00", # [18]
270 'redefine' => "\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00", # [19]
271 'regexp' => "\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00", # [20]
272 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00", # [37]
273 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00", # [38]
274 'severe' => "\x00\x00\x00\x00\x00\xa8\x0a\x00\x00\x00\x00\x00", # [21..25]
275 'signal' => "\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00", # [26]
276 'substr' => "\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00", # [27]
277 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\xaa\xaa\x2a\x00\x00", # [28..38]
278 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00", # [39]
279 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00", # [40]
280 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00", # [41]
281 'unopened' => "\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
282 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00", # [42]
283 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00", # [43]
284 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02", # [44]
285 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08", # [45]
286 'y2k' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20", # [46]
289 $NONE = "\0\0\0\0\0\0\0\0\0\0\0\0";
293 $All = "" ; vec($All, $Offsets{'all'}, 2) = 3 ;
297 local $Carp::CarpInternal{'warnings'};
298 delete $Carp::CarpInternal{'warnings'};
304 # called from B::Deparse.pm
306 push @_, 'all' unless @_;
313 foreach my $word ( @_ ) {
314 if ($word eq 'FATAL') {
318 elsif ($word eq 'NONFATAL') {
322 elsif ($catmask = $Bits{$word}) {
324 $mask |= $DeadBits{$word} if $fatal ;
325 $mask &= ~($DeadBits{$word}|$All) if $no_fatal ;
328 { Croaker("Unknown warnings category '$word'")}
342 my $mask = ${^WARNING_BITS} ;
344 if (vec($mask, $Offsets{'all'}, 1)) {
345 $mask |= $Bits{'all'} ;
346 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
349 push @_, 'all' unless @_;
351 foreach my $word ( @_ ) {
352 if ($word eq 'FATAL') {
356 elsif ($word eq 'NONFATAL') {
360 elsif ($catmask = $Bits{$word}) {
362 $mask |= $DeadBits{$word} if $fatal ;
363 $mask &= ~($DeadBits{$word}|$All) if $no_fatal ;
366 { Croaker("Unknown warnings category '$word'")}
369 ${^WARNING_BITS} = $mask ;
377 my $mask = ${^WARNING_BITS} ;
379 if (vec($mask, $Offsets{'all'}, 1)) {
380 $mask |= $Bits{'all'} ;
381 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
384 push @_, 'all' unless @_;
386 foreach my $word ( @_ ) {
387 if ($word eq 'FATAL') {
390 elsif ($catmask = $Bits{$word}) {
391 $mask &= ~($catmask | $DeadBits{$word} | $All);
394 { Croaker("Unknown warnings category '$word'")}
397 ${^WARNING_BITS} = $mask ;
400 my %builtin_type; @builtin_type{qw(SCALAR ARRAY HASH CODE REF GLOB LVALUE Regexp)} = ();
409 # check the category supplied.
411 if (my $type = ref $category) {
412 Croaker("not an object")
413 if exists $builtin_type{$type};
417 $offset = $Offsets{$category};
418 Croaker("Unknown warnings category '$category'")
419 unless defined $offset;
422 $category = (caller(1))[0] ;
423 $offset = $Offsets{$category};
424 Croaker("package '$category' not registered for warnings")
425 unless defined $offset ;
428 my $this_pkg = (caller(1))[0] ;
433 while (do { { package DB; $pkg = (caller($i++))[0] } } ) {
434 last unless @DB::args && $DB::args[0] =~ /^$category=/ ;
439 for ($i = 2 ; $pkg = (caller($i))[0] ; ++ $i) {
440 last if $pkg ne $this_pkg ;
443 if !$pkg || $pkg eq $this_pkg ;
446 my $callers_bitmask = (caller($i))[9] ;
447 return ($callers_bitmask, $offset, $i) ;
452 Croaker("Usage: warnings::enabled([category])")
453 unless @_ == 1 || @_ == 0 ;
455 my ($callers_bitmask, $offset, $i) = __chk(@_) ;
457 return 0 unless defined $callers_bitmask ;
458 return vec($callers_bitmask, $offset, 1) ||
459 vec($callers_bitmask, $Offsets{'all'}, 1) ;
465 Croaker("Usage: warnings::warn([category,] 'message')")
466 unless @_ == 2 || @_ == 1 ;
469 my ($callers_bitmask, $offset, $i) = __chk(@_) ;
470 Carp::croak($message)
471 if vec($callers_bitmask, $offset+1, 1) ||
472 vec($callers_bitmask, $Offsets{'all'}+1, 1) ;
473 Carp::carp($message) ;
478 Croaker("Usage: warnings::warnif([category,] 'message')")
479 unless @_ == 2 || @_ == 1 ;
482 my ($callers_bitmask, $offset, $i) = __chk(@_) ;
485 unless defined $callers_bitmask &&
486 (vec($callers_bitmask, $offset, 1) ||
487 vec($callers_bitmask, $Offsets{'all'}, 1)) ;
489 Carp::croak($message)
490 if vec($callers_bitmask, $offset+1, 1) ||
491 vec($callers_bitmask, $Offsets{'all'}+1, 1) ;
493 Carp::carp($message) ;