This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pp.c: Fix Win32 compilation problems
[perl5.git] / regen / warnings.pl
CommitLineData
599cee73 1#!/usr/bin/perl
c4a853d1 2#
6294c161
DM
3# Regenerate (overwriting only if changed):
4#
5# lib/warnings.pm
6# warnings.h
7#
8# from information hardcoded into this script (the $tree hash), plus the
d2ec25a5 9# template for warnings.pm in the DATA section.
6294c161 10#
91efc02c
KW
11# When changing the number of warnings, t/op/caller.t should change to
12# correspond with the value of $BYTES in lib/warnings.pm
8457b38f 13#
6294c161
DM
14# With an argument of 'tree', just dump the contents of $tree and exits.
15# Also accepts the standard regen_lib -q and -v args.
16#
17# This script is normally invoked from regen.pl.
599cee73 18
0febf6c1 19$VERSION = '1.03';
b75c8c73 20
73f0cc2d 21BEGIN {
af001346 22 require 'regen/regen_lib.pl';
b6b9a099 23 push @INC, './lib';
73f0cc2d 24}
599cee73
PM
25use strict ;
26
27sub DEFAULT_ON () { 1 }
28sub DEFAULT_OFF () { 2 }
29
30my $tree = {
d3a7d8c7 31
0d658bf5 32'all' => [ 5.008, {
c4a853d1 33 'io' => [ 5.008, {
0d658bf5
PM
34 'pipe' => [ 5.008, DEFAULT_OFF],
35 'unopened' => [ 5.008, DEFAULT_OFF],
36 'closed' => [ 5.008, DEFAULT_OFF],
37 'newline' => [ 5.008, DEFAULT_OFF],
38 'exec' => [ 5.008, DEFAULT_OFF],
39 'layer' => [ 5.008, DEFAULT_OFF],
c8028aa6 40 'syscalls' => [ 5.019, DEFAULT_OFF],
0d658bf5 41 }],
c4a853d1 42 'syntax' => [ 5.008, {
0d658bf5
PM
43 'ambiguous' => [ 5.008, DEFAULT_OFF],
44 'semicolon' => [ 5.008, DEFAULT_OFF],
45 'precedence' => [ 5.008, DEFAULT_OFF],
46 'bareword' => [ 5.008, DEFAULT_OFF],
47 'reserved' => [ 5.008, DEFAULT_OFF],
48 'digit' => [ 5.008, DEFAULT_OFF],
49 'parenthesis' => [ 5.008, DEFAULT_OFF],
50 'printf' => [ 5.008, DEFAULT_OFF],
51 'prototype' => [ 5.008, DEFAULT_OFF],
52 'qw' => [ 5.008, DEFAULT_OFF],
197afce1 53 'illegalproto' => [ 5.011, DEFAULT_OFF],
0d658bf5 54 }],
c4a853d1 55 'severe' => [ 5.008, {
0d658bf5 56 'inplace' => [ 5.008, DEFAULT_ON],
7fc874e8 57 'internal' => [ 5.008, DEFAULT_OFF],
0d658bf5
PM
58 'debugging' => [ 5.008, DEFAULT_ON],
59 'malloc' => [ 5.008, DEFAULT_ON],
c8028aa6 60 }],
7fc874e8 61 'deprecated' => [ 5.008, DEFAULT_ON],
0d658bf5
PM
62 'void' => [ 5.008, DEFAULT_OFF],
63 'recursion' => [ 5.008, DEFAULT_OFF],
64 'redefine' => [ 5.008, DEFAULT_OFF],
65 'numeric' => [ 5.008, DEFAULT_OFF],
66 'uninitialized' => [ 5.008, DEFAULT_OFF],
67 'once' => [ 5.008, DEFAULT_OFF],
68 'misc' => [ 5.008, DEFAULT_OFF],
69 'regexp' => [ 5.008, DEFAULT_OFF],
7fc874e8 70 'glob' => [ 5.008, DEFAULT_ON],
0d658bf5
PM
71 'untie' => [ 5.008, DEFAULT_OFF],
72 'substr' => [ 5.008, DEFAULT_OFF],
73 'taint' => [ 5.008, DEFAULT_OFF],
74 'signal' => [ 5.008, DEFAULT_OFF],
75 'closure' => [ 5.008, DEFAULT_OFF],
76 'overflow' => [ 5.008, DEFAULT_OFF],
77 'portable' => [ 5.008, DEFAULT_OFF],
8457b38f
KW
78 'utf8' => [ 5.008, {
79 'surrogate' => [ 5.013, DEFAULT_OFF],
80 'nonchar' => [ 5.013, DEFAULT_OFF],
81 'non_unicode' => [ 5.013, DEFAULT_OFF],
82 }],
0d658bf5
PM
83 'exiting' => [ 5.008, DEFAULT_OFF],
84 'pack' => [ 5.008, DEFAULT_OFF],
85 'unpack' => [ 5.008, DEFAULT_OFF],
38875929 86 'threads' => [ 5.008, DEFAULT_OFF],
b88df990 87 'imprecision' => [ 5.011, DEFAULT_OFF],
6f87cb12 88 'experimental' => [ 5.017, {
f1d34ca8 89 'experimental::lexical_subs' =>
6f87cb12 90 [ 5.017, DEFAULT_ON ],
db620012
KW
91 'experimental::regex_sets' =>
92 [ 5.017, DEFAULT_ON ],
4055dbce
RS
93 'experimental::lexical_topic' =>
94 [ 5.017, DEFAULT_ON ],
0f539b13
BF
95 'experimental::smartmatch' =>
96 [ 5.017, DEFAULT_ON ],
1f25714a
FC
97 'experimental::postderef' =>
98 [ 5.019, DEFAULT_ON ],
d401967c 99 'experimental::autoderef' =>
0953b66b 100 [ 5.019, DEFAULT_ON ],
30d9c59b
Z
101 'experimental::signatures' =>
102 [ 5.019, DEFAULT_ON ],
7ac92924
TC
103 'experimental::win32_perlio' =>
104 [ 5.021, DEFAULT_ON ],
6f87cb12 105 }],
8fa7688f 106
0d658bf5
PM
107 #'default' => [ 5.008, DEFAULT_ON ],
108 }],
d3a7d8c7 109} ;
599cee73 110
7fc874e8 111my @def ;
599cee73
PM
112my %list ;
113my %Value ;
0d658bf5
PM
114my %ValueToName ;
115my %NameToValue ;
599cee73 116
0d658bf5
PM
117my %v_list = () ;
118
119sub valueWalk
120{
121 my $tre = shift ;
122 my @list = () ;
123 my ($k, $v) ;
124
125 foreach $k (sort keys %$tre) {
126 $v = $tre->{$k};
127 die "duplicate key $k\n" if defined $list{$k} ;
128 die "Value associated with key '$k' is not an ARRAY reference"
129 if !ref $v || ref $v ne 'ARRAY' ;
130
131 my ($ver, $rest) = @{ $v } ;
132 push @{ $v_list{$ver} }, $k;
c4a853d1 133
0d658bf5
PM
134 if (ref $rest)
135 { valueWalk ($rest) }
136
137 }
138
139}
140
141sub orderValues
142{
143 my $index = 0;
144 foreach my $ver ( sort { $a <=> $b } keys %v_list ) {
145 foreach my $name (@{ $v_list{$ver} } ) {
146 $ValueToName{ $index } = [ uc $name, $ver ] ;
147 $NameToValue{ uc $name } = $index ++ ;
148 }
149 }
150
151 return $index ;
152}
153
154###########################################################################
155
599cee73
PM
156sub walk
157{
158 my $tre = shift ;
159 my @list = () ;
160 my ($k, $v) ;
161
95dfd3ab
GS
162 foreach $k (sort keys %$tre) {
163 $v = $tre->{$k};
599cee73 164 die "duplicate key $k\n" if defined $list{$k} ;
0d658bf5
PM
165 die "Can't find key '$k'"
166 if ! defined $NameToValue{uc $k} ;
167 push @{ $list{$k} }, $NameToValue{uc $k} ;
168 die "Value associated with key '$k' is not an ARRAY reference"
169 if !ref $v || ref $v ne 'ARRAY' ;
c4a853d1 170
0d658bf5
PM
171 my ($ver, $rest) = @{ $v } ;
172 if (ref $rest)
173 { push (@{ $list{$k} }, walk ($rest)) }
7fc874e8
FC
174 elsif ($rest == DEFAULT_ON)
175 { push @def, $NameToValue{uc $k} }
0d658bf5 176
599cee73
PM
177 push @list, @{ $list{$k} } ;
178 }
179
180 return @list ;
599cee73
PM
181}
182
183###########################################################################
184
185sub mkRange
186{
187 my @a = @_ ;
188 my @out = @a ;
599cee73 189
e95a9fc2 190 for my $i (1 .. @a - 1) {
0ca4541c 191 $out[$i] = ".."
e95a9fc2
KW
192 if $a[$i] == $a[$i - 1] + 1
193 && ($i >= @a - 1 || $a[$i] + 1 == $a[$i + 1] );
599cee73 194 }
e95a9fc2 195 $out[-1] = $a[-1] if $out[-1] eq "..";
599cee73
PM
196
197 my $out = join(",",@out);
198
199 $out =~ s/,(\.\.,)+/../g ;
200 return $out;
201}
202
203###########################################################################
e15f14b8 204sub warningsTree
e476b1b5
GS
205{
206 my $tre = shift ;
207 my $prefix = shift ;
e476b1b5
GS
208 my ($k, $v) ;
209
210 my $max = (sort {$a <=> $b} map { length $_ } keys %$tre)[-1] ;
0d658bf5 211 my @keys = sort keys %$tre ;
e476b1b5 212
e15f14b8
RS
213 my $rv = '';
214
0d658bf5 215 while ($k = shift @keys) {
e476b1b5 216 $v = $tre->{$k};
0d658bf5
PM
217 die "Value associated with key '$k' is not an ARRAY reference"
218 if !ref $v || ref $v ne 'ARRAY' ;
c4a853d1 219
0d658bf5
PM
220 my $offset ;
221 if ($tre ne $tree) {
e15f14b8
RS
222 $rv .= $prefix . "|\n" ;
223 $rv .= $prefix . "+- $k" ;
0d658bf5
PM
224 $offset = ' ' x ($max + 4) ;
225 }
226 else {
e15f14b8 227 $rv .= $prefix . "$k" ;
0d658bf5
PM
228 $offset = ' ' x ($max + 1) ;
229 }
230
231 my ($ver, $rest) = @{ $v } ;
f1d34ca8 232 if (ref $rest)
0ca4541c 233 {
0d658bf5 234 my $bar = @keys ? "|" : " ";
e15f14b8
RS
235 $rv .= " -" . "-" x ($max - length $k ) . "+\n" ;
236 $rv .= warningsTree ($rest, $prefix . $bar . $offset )
e476b1b5
GS
237 }
238 else
e15f14b8 239 { $rv .= "\n" }
e476b1b5
GS
240 }
241
e15f14b8 242 return $rv;
e476b1b5
GS
243}
244
245###########################################################################
599cee73 246
317ea90d 247sub mkHexOct
599cee73 248{
317ea90d 249 my ($f, $max, @a) = @_ ;
599cee73
PM
250 my $mask = "\x00" x $max ;
251 my $string = "" ;
252
253 foreach (@a) {
254 vec($mask, $_, 1) = 1 ;
255 }
256
599cee73 257 foreach (unpack("C*", $mask)) {
317ea90d
MS
258 if ($f eq 'x') {
259 $string .= '\x' . sprintf("%2.2x", $_)
260 }
261 else {
262 $string .= '\\' . sprintf("%o", $_)
263 }
599cee73
PM
264 }
265 return $string ;
266}
267
317ea90d
MS
268sub mkHex
269{
270 my($max, @a) = @_;
271 return mkHexOct("x", $max, @a);
272}
273
274sub mkOct
275{
276 my($max, @a) = @_;
277 return mkHexOct("o", $max, @a);
278}
279
599cee73
PM
280###########################################################################
281
e476b1b5
GS
282if (@ARGV && $ARGV[0] eq "tree")
283{
e15f14b8 284 print warningsTree($tree, " ") ;
e476b1b5
GS
285 exit ;
286}
599cee73 287
cc49830d
NC
288my ($warn, $pm) = map {
289 open_new($_, '>', { by => 'regen/warnings.pl' });
290} 'warnings.h', 'lib/warnings.pm';
599cee73 291
c4a853d1
RS
292my ($index, $warn_size);
293
294{
295 # generate warnings.h
296
297 print $warn <<'EOM';
599cee73 298
0453d815
PM
299#define Off(x) ((x) / 8)
300#define Bit(x) (1 << ((x) % 8))
599cee73
PM
301#define IsSet(a, x) ((a)[Off(x)] & Bit(x))
302
0453d815 303
599cee73 304#define G_WARN_OFF 0 /* $^W == 0 */
0453d815 305#define G_WARN_ON 1 /* -w flag and $^W != 0 */
599cee73
PM
306#define G_WARN_ALL_ON 2 /* -W flag */
307#define G_WARN_ALL_OFF 4 /* -X flag */
0453d815 308#define G_WARN_ONCE 8 /* set if 'once' ever enabled */
599cee73
PM
309#define G_WARN_ALL_MASK (G_WARN_ALL_ON|G_WARN_ALL_OFF)
310
a0714e2c 311#define pWARN_STD NULL
72dc9ed5
NC
312#define pWARN_ALL (((STRLEN*)0)+1) /* use warnings 'all' */
313#define pWARN_NONE (((STRLEN*)0)+2) /* no warnings 'all' */
599cee73 314
d3a7d8c7
GS
315#define specialWARN(x) ((x) == pWARN_STD || (x) == pWARN_ALL || \
316 (x) == pWARN_NONE)
5f2d9966
DM
317
318/* if PL_warnhook is set to this value, then warnings die */
06dcd5bf 319#define PERL_WARNHOOK_FATAL (&PL_sv_placeholder)
599cee73
PM
320EOM
321
c4a853d1 322 my $offset = 0 ;
d3a7d8c7 323
c4a853d1
RS
324 valueWalk ($tree) ;
325 $index = orderValues();
599cee73 326
c4a853d1 327 die <<EOM if $index > 255 ;
12bcd1a6 328Too many warnings categories -- max is 255
c4a853d1 329 rewrite packWARN* & unpackWARN* macros
12bcd1a6 330EOM
599cee73 331
c4a853d1 332 walk ($tree) ;
0d658bf5 333
c4a853d1
RS
334 $index *= 2 ;
335 $warn_size = int($index / 8) + ($index % 8 != 0) ;
599cee73 336
c4a853d1
RS
337 my $k ;
338 my $last_ver = 0;
339 foreach $k (sort { $a <=> $b } keys %ValueToName) {
340 my ($name, $version) = @{ $ValueToName{$k} };
341 print $warn "\n/* Warnings Categories added in Perl $version */\n\n"
342 if $last_ver != $version ;
343 $name =~ y/:/_/;
344 print $warn tab(5, "#define WARN_$name"), " $k\n" ;
345 $last_ver = $version ;
346 }
347 print $warn "\n" ;
599cee73 348
c4a853d1
RS
349 print $warn tab(5, '#define WARNsize'), "$warn_size\n" ;
350 print $warn tab(5, '#define WARN_ALLstring'), '"', ('\125' x $warn_size) , "\"\n" ;
351 print $warn tab(5, '#define WARN_NONEstring'), '"', ('\0' x $warn_size) , "\"\n" ;
599cee73 352
c4a853d1 353 print $warn <<'EOM';
599cee73 354
d5a71f30
GS
355#define isLEXWARN_on (PL_curcop->cop_warnings != pWARN_STD)
356#define isLEXWARN_off (PL_curcop->cop_warnings == pWARN_STD)
357#define isWARN_ONCE (PL_dowarn & (G_WARN_ON|G_WARN_ONCE))
72dc9ed5
NC
358#define isWARN_on(c,x) (IsSet((U8 *)(c + 1), 2*(x)))
359#define isWARNf_on(c,x) (IsSet((U8 *)(c + 1), 2*(x)+1))
360
361#define DUP_WARNINGS(p) \
594cd643
NC
362 (specialWARN(p) ? (STRLEN*)(p) \
363 : (STRLEN*)CopyD(p, PerlMemShared_malloc(sizeof(*p)+*p), sizeof(*p)+*p, \
364 char))
d5a71f30 365
f54ba1c2 366#define ckWARN(w) Perl_ckwarn(aTHX_ packWARN(w))
7c08c4c5
KW
367
368/* The w1, w2 ... should be independent warnings categories; one shouldn't be
369 * a subcategory of any other */
370
f54ba1c2
DM
371#define ckWARN2(w1,w2) Perl_ckwarn(aTHX_ packWARN2(w1,w2))
372#define ckWARN3(w1,w2,w3) Perl_ckwarn(aTHX_ packWARN3(w1,w2,w3))
373#define ckWARN4(w1,w2,w3,w4) Perl_ckwarn(aTHX_ packWARN4(w1,w2,w3,w4))
374
375#define ckWARN_d(w) Perl_ckwarn_d(aTHX_ packWARN(w))
376#define ckWARN2_d(w1,w2) Perl_ckwarn_d(aTHX_ packWARN2(w1,w2))
377#define ckWARN3_d(w1,w2,w3) Perl_ckwarn_d(aTHX_ packWARN3(w1,w2,w3))
378#define ckWARN4_d(w1,w2,w3,w4) Perl_ckwarn_d(aTHX_ packWARN4(w1,w2,w3,w4))
12bcd1a6 379
98fe6610
NC
380#define WARNshift 8
381
3b9e3074 382#define packWARN(a) (a )
7c08c4c5
KW
383
384/* The a, b, ... should be independent warnings categories; one shouldn't be
385 * a subcategory of any other */
386
3b9e3074
SH
387#define packWARN2(a,b) ((a) | ((b)<<8) )
388#define packWARN3(a,b,c) ((a) | ((b)<<8) | ((c)<<16) )
389#define packWARN4(a,b,c,d) ((a) | ((b)<<8) | ((c)<<16) | ((d) <<24))
12bcd1a6
PM
390
391#define unpackWARN1(x) ((x) & 0xFF)
392#define unpackWARN2(x) (((x) >>8) & 0xFF)
393#define unpackWARN3(x) (((x) >>16) & 0xFF)
394#define unpackWARN4(x) (((x) >>24) & 0xFF)
395
396#define ckDEAD(x) \
397 ( ! specialWARN(PL_curcop->cop_warnings) && \
398 ( isWARNf_on(PL_curcop->cop_warnings, WARN_ALL) || \
399 isWARNf_on(PL_curcop->cop_warnings, unpackWARN1(x)) || \
400 isWARNf_on(PL_curcop->cop_warnings, unpackWARN2(x)) || \
401 isWARNf_on(PL_curcop->cop_warnings, unpackWARN3(x)) || \
402 isWARNf_on(PL_curcop->cop_warnings, unpackWARN4(x))))
403
4438c4b7 404/* end of file warnings.h */
599cee73
PM
405EOM
406
c4a853d1
RS
407 read_only_bottom_close_and_rename($warn);
408}
599cee73
PM
409
410while (<DATA>) {
411 last if /^KEYWORDS$/ ;
33edcb80
RS
412 if ($_ eq "=for warnings.pl tree-goes-here\n") {
413 print $pm warningsTree($tree, " ");
414 next;
415 }
424a4936 416 print $pm $_ ;
599cee73
PM
417}
418
c4a853d1 419my $last_ver = 0;
424a4936 420print $pm "our %Offsets = (\n" ;
0d658bf5
PM
421foreach my $k (sort { $a <=> $b } keys %ValueToName) {
422 my ($name, $version) = @{ $ValueToName{$k} };
423 $name = lc $name;
d3a7d8c7 424 $k *= 2 ;
0d658bf5 425 if ( $last_ver != $version ) {
424a4936
NC
426 print $pm "\n";
427 print $pm tab(4, " # Warnings Categories added in Perl $version");
428 print $pm "\n\n";
0d658bf5 429 }
424a4936 430 print $pm tab(4, " '$name'"), "=> $k,\n" ;
0d658bf5 431 $last_ver = $version;
d3a7d8c7
GS
432}
433
424a4936 434print $pm " );\n\n" ;
d3a7d8c7 435
424a4936 436print $pm "our %Bits = (\n" ;
c4a853d1 437foreach my $k (sort keys %list) {
599cee73
PM
438
439 my $v = $list{$k} ;
440 my @list = sort { $a <=> $b } @$v ;
441
424a4936 442 print $pm tab(4, " '$k'"), '=> "',
0ca4541c 443 mkHex($warn_size, map $_ * 2 , @list),
599cee73
PM
444 '", # [', mkRange(@list), "]\n" ;
445}
446
424a4936 447print $pm " );\n\n" ;
599cee73 448
424a4936 449print $pm "our %DeadBits = (\n" ;
c4a853d1 450foreach my $k (sort keys %list) {
599cee73
PM
451
452 my $v = $list{$k} ;
453 my @list = sort { $a <=> $b } @$v ;
454
424a4936 455 print $pm tab(4, " '$k'"), '=> "',
0ca4541c 456 mkHex($warn_size, map $_ * 2 + 1 , @list),
599cee73
PM
457 '", # [', mkRange(@list), "]\n" ;
458}
459
424a4936
NC
460print $pm " );\n\n" ;
461print $pm '$NONE = "', ('\0' x $warn_size) , "\";\n" ;
7fc874e8
FC
462print $pm '$DEFAULT = "', mkHex($warn_size, map $_ * 2, @def),
463 '", # [', mkRange(@def), "]\n" ;
424a4936
NC
464print $pm '$LAST_BIT = ' . "$index ;\n" ;
465print $pm '$BYTES = ' . "$warn_size ;\n" ;
599cee73 466while (<DATA>) {
424a4936 467 print $pm $_ ;
599cee73
PM
468}
469
ce716c52 470read_only_bottom_close_and_rename($pm);
599cee73
PM
471
472__END__
4438c4b7 473package warnings;
599cee73 474
7ac92924 475our $VERSION = '1.24';
f2c3e829
RGS
476
477# Verify that we're called correctly so that warnings will work.
478# see also strict.pm.
5108dc18 479unless ( __FILE__ =~ /(^|[\/\\])\Q${\__PACKAGE__}\E\.pmc?$/ ) {
f2c3e829 480 my (undef, $f, $l) = caller;
5108dc18 481 die("Incorrect use of pragma '${\__PACKAGE__}' at $f line $l.\n");
f2c3e829 482}
b75c8c73 483
599cee73
PM
484=head1 NAME
485
4438c4b7 486warnings - Perl pragma to control optional warnings
599cee73
PM
487
488=head1 SYNOPSIS
489
4438c4b7
JH
490 use warnings;
491 no warnings;
599cee73 492
4438c4b7
JH
493 use warnings "all";
494 no warnings "all";
599cee73 495
d3a7d8c7
GS
496 use warnings::register;
497 if (warnings::enabled()) {
498 warnings::warn("some warning");
499 }
500
501 if (warnings::enabled("void")) {
e476b1b5
GS
502 warnings::warn("void", "some warning");
503 }
504
7e6d00f8
PM
505 if (warnings::enabled($object)) {
506 warnings::warn($object, "some warning");
507 }
508
721f911b
PM
509 warnings::warnif("some warning");
510 warnings::warnif("void", "some warning");
511 warnings::warnif($object, "some warning");
7e6d00f8 512
599cee73
PM
513=head1 DESCRIPTION
514
188c4f6f
RS
515The C<warnings> pragma gives control over which warnings are enabled in
516which parts of a Perl program. It's a more flexible alternative for
517both the command line flag B<-w> and the equivalent Perl variable,
518C<$^W>.
33edcb80
RS
519
520This pragma works just like the C<strict> pragma.
521This means that the scope of the warning pragma is limited to the
522enclosing block. It also means that the pragma setting will not
523leak across files (via C<use>, C<require> or C<do>). This allows
524authors to independently define the degree of warning checks that will
525be applied to their module.
526
527By default, optional warnings are disabled, so any legacy code that
528doesn't attempt to control the warnings will work unchanged.
529
530All warnings are enabled in a block by either of these:
531
532 use warnings;
533 use warnings 'all';
534
535Similarly all warnings are disabled in a block by either of these:
536
537 no warnings;
538 no warnings 'all';
539
540For example, consider the code below:
541
542 use warnings;
543 my @a;
544 {
545 no warnings;
546 my $b = @a[0];
547 }
548 my $c = @a[0];
549
550The code in the enclosing block has warnings enabled, but the inner
551block has them disabled. In this case that means the assignment to the
552scalar C<$c> will trip the C<"Scalar value @a[0] better written as $a[0]">
553warning, but the assignment to the scalar C<$b> will not.
554
555=head2 Default Warnings and Optional Warnings
556
557Before the introduction of lexical warnings, Perl had two classes of
558warnings: mandatory and optional.
559
560As its name suggests, if your code tripped a mandatory warning, you
561would get a warning whether you wanted it or not.
562For example, the code below would always produce an C<"isn't numeric">
563warning about the "2:".
564
565 my $a = "2:" + 3;
566
567With the introduction of lexical warnings, mandatory warnings now become
568I<default> warnings. The difference is that although the previously
569mandatory warnings are still enabled by default, they can then be
570subsequently enabled or disabled with the lexical warning pragma. For
571example, in the code below, an C<"isn't numeric"> warning will only
572be reported for the C<$a> variable.
573
574 my $a = "2:" + 3;
575 no warnings;
576 my $b = "2:" + 3;
577
578Note that neither the B<-w> flag or the C<$^W> can be used to
579disable/enable default warnings. They are still mandatory in this case.
580
581=head2 What's wrong with B<-w> and C<$^W>
582
583Although very useful, the big problem with using B<-w> on the command
584line to enable warnings is that it is all or nothing. Take the typical
585scenario when you are writing a Perl program. Parts of the code you
586will write yourself, but it's very likely that you will make use of
587pre-written Perl modules. If you use the B<-w> flag in this case, you
588end up enabling warnings in pieces of code that you haven't written.
589
590Similarly, using C<$^W> to either disable or enable blocks of code is
591fundamentally flawed. For a start, say you want to disable warnings in
592a block of code. You might expect this to be enough to do the trick:
593
594 {
595 local ($^W) = 0;
596 my $a =+ 2;
597 my $b; chop $b;
598 }
599
600When this code is run with the B<-w> flag, a warning will be produced
601for the C<$a> line: C<"Reversed += operator">.
602
603The problem is that Perl has both compile-time and run-time warnings. To
604disable compile-time warnings you need to rewrite the code like this:
605
606 {
607 BEGIN { $^W = 0 }
608 my $a =+ 2;
609 my $b; chop $b;
610 }
611
612The other big problem with C<$^W> is the way you can inadvertently
613change the warning setting in unexpected places in your code. For example,
614when the code below is run (without the B<-w> flag), the second call
615to C<doit> will trip a C<"Use of uninitialized value"> warning, whereas
616the first will not.
617
618 sub doit
619 {
620 my $b; chop $b;
621 }
622
623 doit();
624
625 {
626 local ($^W) = 1;
627 doit()
628 }
629
630This is a side-effect of C<$^W> being dynamically scoped.
631
632Lexical warnings get around these limitations by allowing finer control
633over where warnings can or can't be tripped.
634
635=head2 Controlling Warnings from the Command Line
636
637There are three Command Line flags that can be used to control when
638warnings are (or aren't) produced:
639
640=over 5
641
642=item B<-w>
643X<-w>
644
645This is the existing flag. If the lexical warnings pragma is B<not>
646used in any of you code, or any of the modules that you use, this flag
647will enable warnings everywhere. See L<Backward Compatibility> for
648details of how this flag interacts with lexical warnings.
649
650=item B<-W>
651X<-W>
652
653If the B<-W> flag is used on the command line, it will enable all warnings
654throughout the program regardless of whether warnings were disabled
655locally using C<no warnings> or C<$^W =0>.
656This includes all files that get
657included via C<use>, C<require> or C<do>.
658Think of it as the Perl equivalent of the "lint" command.
659
660=item B<-X>
661X<-X>
662
663Does the exact opposite to the B<-W> flag, i.e. it disables all warnings.
664
665=back
666
667=head2 Backward Compatibility
668
669If you are used to working with a version of Perl prior to the
670introduction of lexically scoped warnings, or have code that uses both
671lexical warnings and C<$^W>, this section will describe how they interact.
672
673How Lexical Warnings interact with B<-w>/C<$^W>:
674
675=over 5
676
677=item 1.
678
679If none of the three command line flags (B<-w>, B<-W> or B<-X>) that
680control warnings is used and neither C<$^W> nor the C<warnings> pragma
681are used, then default warnings will be enabled and optional warnings
682disabled.
683This means that legacy code that doesn't attempt to control the warnings
684will work unchanged.
685
686=item 2.
687
688The B<-w> flag just sets the global C<$^W> variable as in 5.005. This
689means that any legacy code that currently relies on manipulating C<$^W>
690to control warning behavior will still work as is.
691
692=item 3.
693
694Apart from now being a boolean, the C<$^W> variable operates in exactly
695the same horrible uncontrolled global way, except that it cannot
696disable/enable default warnings.
697
698=item 4.
699
700If a piece of code is under the control of the C<warnings> pragma,
701both the C<$^W> variable and the B<-w> flag will be ignored for the
702scope of the lexical warning.
703
704=item 5.
705
706The only way to override a lexical warnings setting is with the B<-W>
707or B<-X> command line flags.
708
709=back
710
711The combined effect of 3 & 4 is that it will allow code which uses
712the C<warnings> pragma to control the warning behavior of $^W-type
713code (using a C<local $^W=0>) if it really wants to, but not vice-versa.
714
715=head2 Category Hierarchy
716X<warning, categories>
717
718A hierarchy of "categories" have been defined to allow groups of warnings
719to be enabled/disabled in isolation.
720
721The current hierarchy is:
722
723=for warnings.pl tree-goes-here
724
725Just like the "strict" pragma any of these categories can be combined
726
727 use warnings qw(void redefine);
728 no warnings qw(io syntax untie);
729
730Also like the "strict" pragma, if there is more than one instance of the
731C<warnings> pragma in a given scope the cumulative effect is additive.
732
733 use warnings qw(void); # only "void" warnings enabled
734 ...
735 use warnings qw(io); # only "void" & "io" warnings enabled
736 ...
737 no warnings qw(void); # only "io" warnings enabled
738
739To determine which category a specific warning has been assigned to see
740L<perldiag>.
741
742Note: Before Perl 5.8.0, the lexical warnings category "deprecated" was a
743sub-category of the "syntax" category. It is now a top-level category
744in its own right.
745
746=head2 Fatal Warnings
747X<warning, fatal>
748
749The presence of the word "FATAL" in the category list will escalate any
750warnings detected from the categories specified in the lexical scope
751into fatal errors. In the code below, the use of C<time>, C<length>
752and C<join> can all produce a C<"Useless use of xxx in void context">
753warning.
754
755 use warnings;
756
757 time;
758
759 {
760 use warnings FATAL => qw(void);
761 length "abc";
762 }
763
764 join "", 1,2,3;
765
766 print "done\n";
767
768When run it produces this output
769
770 Useless use of time in void context at fatal line 3.
771 Useless use of length in void context at fatal line 7.
772
773The scope where C<length> is used has escalated the C<void> warnings
774category into a fatal error, so the program terminates immediately when it
775encounters the warning.
776
777To explicitly turn off a "FATAL" warning you just disable the warning
778it is associated with. So, for example, to disable the "void" warning
779in the example above, either of these will do the trick:
780
781 no warnings qw(void);
782 no warnings FATAL => qw(void);
783
784If you want to downgrade a warning that has been escalated into a fatal
785error back to a normal warning, you can use the "NONFATAL" keyword. For
786example, the code below will promote all warnings into fatal errors,
787except for those in the "syntax" category.
788
789 use warnings FATAL => 'all', NONFATAL => 'syntax';
790
791As of Perl 5.20, instead of C<< use warnings FATAL => 'all'; >> you can
792use:
793
794 use v5.20; # Perl 5.20 or greater is required for the following
795 use warnings 'FATAL'; # short form of "use warnings FATAL => 'all';"
796
797If you want your program to be compatible with versions of Perl before
7985.20, you must use C<< use warnings FATAL => 'all'; >> instead. (In
799previous versions of Perl, the behavior of the statements
800C<< use warnings 'FATAL'; >>, C<< use warnings 'NONFATAL'; >> and
801C<< no warnings 'FATAL'; >> was unspecified; they did not behave as if
802they included the C<< => 'all' >> portion. As of 5.20, they do.)
803
804B<NOTE:> Users of FATAL warnings, especially
805those using C<< FATAL => 'all' >>
806should be fully aware that they are risking future portability of their
807programs by doing so. Perl makes absolutely no commitments to not
808introduce new warnings, or warnings categories in the future, and indeed
809we explicitly reserve the right to do so. Code that may not warn now may
810warn in a future release of Perl if the Perl5 development team deems it
811in the best interests of the community to do so. Should code using FATAL
812warnings break due to the introduction of a new warning we will NOT
813consider it an incompatible change. Users of FATAL warnings should take
814special caution during upgrades to check to see if their code triggers
815any new warnings and should pay particular attention to the fine print of
816the documentation of the features they use to ensure they do not exploit
817features that are documented as risky, deprecated, or unspecified, or where
818the documentation says "so don't do that", or anything with the same sense
819and spirit. Use of such features in combination with FATAL warnings is
820ENTIRELY AT THE USER'S RISK.
821
822=head2 Reporting Warnings from a Module
823X<warning, reporting> X<warning, registering>
824
825The C<warnings> pragma provides a number of functions that are useful for
826module authors. These are used when you want to report a module-specific
827warning to a calling module has enabled warnings via the C<warnings>
828pragma.
829
830Consider the module C<MyMod::Abc> below.
831
832 package MyMod::Abc;
833
834 use warnings::register;
835
836 sub open {
837 my $path = shift;
838 if ($path !~ m#^/#) {
839 warnings::warn("changing relative path to /var/abc")
840 if warnings::enabled();
841 $path = "/var/abc/$path";
842 }
843 }
844
845 1;
846
847The call to C<warnings::register> will create a new warnings category
848called "MyMod::Abc", i.e. the new category name matches the current
849package name. The C<open> function in the module will display a warning
850message if it gets given a relative path as a parameter. This warnings
851will only be displayed if the code that uses C<MyMod::Abc> has actually
852enabled them with the C<warnings> pragma like below.
853
854 use MyMod::Abc;
855 use warnings 'MyMod::Abc';
856 ...
857 abc::open("../fred.txt");
858
859It is also possible to test whether the pre-defined warnings categories are
860set in the calling module with the C<warnings::enabled> function. Consider
861this snippet of code:
862
863 package MyMod::Abc;
864
865 sub open {
866 warnings::warnif("deprecated",
867 "open is deprecated, use new instead");
868 new(@_);
869 }
870
871 sub new
872 ...
873 1;
874
875The function C<open> has been deprecated, so code has been included to
876display a warning message whenever the calling module has (at least) the
877"deprecated" warnings category enabled. Something like this, say.
878
879 use warnings 'deprecated';
880 use MyMod::Abc;
881 ...
882 MyMod::Abc::open($filename);
883
884Either the C<warnings::warn> or C<warnings::warnif> function should be
885used to actually display the warnings message. This is because they can
886make use of the feature that allows warnings to be escalated into fatal
887errors. So in this case
888
889 use MyMod::Abc;
890 use warnings FATAL => 'MyMod::Abc';
891 ...
892 MyMod::Abc::open('../fred.txt');
893
894the C<warnings::warnif> function will detect this and die after
895displaying the warning message.
896
897The three warnings functions, C<warnings::warn>, C<warnings::warnif>
898and C<warnings::enabled> can optionally take an object reference in place
899of a category name. In this case the functions will use the class name
900of the object as the warnings category.
901
902Consider this example:
903
904 package Original;
905
906 no warnings;
907 use warnings::register;
908
909 sub new
910 {
911 my $class = shift;
912 bless [], $class;
913 }
914
915 sub check
916 {
917 my $self = shift;
918 my $value = shift;
919
920 if ($value % 2 && warnings::enabled($self))
921 { warnings::warn($self, "Odd numbers are unsafe") }
922 }
923
924 sub doit
925 {
926 my $self = shift;
927 my $value = shift;
928 $self->check($value);
929 # ...
930 }
931
932 1;
933
934 package Derived;
935
936 use warnings::register;
937 use Original;
938 our @ISA = qw( Original );
939 sub new
940 {
941 my $class = shift;
942 bless [], $class;
943 }
944
945
946 1;
947
948The code below makes use of both modules, but it only enables warnings from
949C<Derived>.
950
951 use Original;
952 use Derived;
953 use warnings 'Derived';
954 my $a = Original->new();
955 $a->doit(1);
956 my $b = Derived->new();
957 $a->doit(1);
958
959When this code is run only the C<Derived> object, C<$b>, will generate
960a warning.
961
962 Odd numbers are unsafe at main.pl line 7
963
964Notice also that the warning is reported at the line where the object is first
965used.
966
967When registering new categories of warning, you can supply more names to
968warnings::register like this:
969
970 package MyModule;
971 use warnings::register qw(format precision);
972
973 ...
fe2e802c 974
33edcb80 975 warnings::warnif('MyModule::format', '...');
599cee73 976
33edcb80 977=head1 FUNCTIONS
e476b1b5
GS
978
979=over 4
980
d3a7d8c7
GS
981=item use warnings::register
982
7e6d00f8
PM
983Creates a new warnings category with the same name as the package where
984the call to the pragma is used.
985
986=item warnings::enabled()
987
988Use the warnings category with the same name as the current package.
989
990Return TRUE if that warnings category is enabled in the calling module.
991Otherwise returns FALSE.
992
993=item warnings::enabled($category)
994
995Return TRUE if the warnings category, C<$category>, is enabled in the
996calling module.
997Otherwise returns FALSE.
998
999=item warnings::enabled($object)
1000
1001Use the name of the class for the object reference, C<$object>, as the
1002warnings category.
1003
1004Return TRUE if that warnings category is enabled in the first scope
1005where the object is used.
1006Otherwise returns FALSE.
1007
ec983580
AR
1008=item warnings::fatal_enabled()
1009
1010Return TRUE if the warnings category with the same name as the current
1011package has been set to FATAL in the calling module.
1012Otherwise returns FALSE.
1013
1014=item warnings::fatal_enabled($category)
1015
1016Return TRUE if the warnings category C<$category> has been set to FATAL in
1017the calling module.
1018Otherwise returns FALSE.
1019
1020=item warnings::fatal_enabled($object)
1021
1022Use the name of the class for the object reference, C<$object>, as the
1023warnings category.
1024
1025Return TRUE if that warnings category has been set to FATAL in the first
1026scope where the object is used.
1027Otherwise returns FALSE.
1028
7e6d00f8
PM
1029=item warnings::warn($message)
1030
1031Print C<$message> to STDERR.
1032
1033Use the warnings category with the same name as the current package.
1034
1035If that warnings category has been set to "FATAL" in the calling module
1036then die. Otherwise return.
1037
1038=item warnings::warn($category, $message)
1039
1040Print C<$message> to STDERR.
1041
1042If the warnings category, C<$category>, has been set to "FATAL" in the
1043calling module then die. Otherwise return.
d3a7d8c7 1044
7e6d00f8 1045=item warnings::warn($object, $message)
e476b1b5 1046
7e6d00f8 1047Print C<$message> to STDERR.
e476b1b5 1048
7e6d00f8
PM
1049Use the name of the class for the object reference, C<$object>, as the
1050warnings category.
e476b1b5 1051
7e6d00f8
PM
1052If that warnings category has been set to "FATAL" in the scope where C<$object>
1053is first used then die. Otherwise return.
599cee73 1054
e476b1b5 1055
7e6d00f8
PM
1056=item warnings::warnif($message)
1057
1058Equivalent to:
1059
1060 if (warnings::enabled())
1061 { warnings::warn($message) }
1062
1063=item warnings::warnif($category, $message)
1064
1065Equivalent to:
1066
1067 if (warnings::enabled($category))
1068 { warnings::warn($category, $message) }
1069
1070=item warnings::warnif($object, $message)
1071
1072Equivalent to:
1073
1074 if (warnings::enabled($object))
1075 { warnings::warn($object, $message) }
d3a7d8c7 1076
5e7ad92a 1077=item warnings::register_categories(@names)
13781810
FR
1078
1079This registers warning categories for the given names and is primarily for
d2ec25a5 1080use by the warnings::register pragma.
13781810 1081
e476b1b5
GS
1082=back
1083
d2ec25a5 1084See also L<perlmodlib/Pragmatic Modules> and L<perldiag>.
599cee73
PM
1085
1086=cut
1087
599cee73
PM
1088KEYWORDS
1089
d3a7d8c7
GS
1090$All = "" ; vec($All, $Offsets{'all'}, 2) = 3 ;
1091
c3186b65
PM
1092sub Croaker
1093{
4dd71923 1094 require Carp; # this initializes %CarpInternal
dbab294c 1095 local $Carp::CarpInternal{'warnings'};
c3186b65 1096 delete $Carp::CarpInternal{'warnings'};
8becbb3b 1097 Carp::croak(@_);
c3186b65
PM
1098}
1099
4c02ac93
NC
1100sub _bits {
1101 my $mask = shift ;
599cee73
PM
1102 my $catmask ;
1103 my $fatal = 0 ;
6e9af7e4
PM
1104 my $no_fatal = 0 ;
1105
1106 foreach my $word ( @_ ) {
1107 if ($word eq 'FATAL') {
327afb7f 1108 $fatal = 1;
6e9af7e4
PM
1109 $no_fatal = 0;
1110 }
1111 elsif ($word eq 'NONFATAL') {
1112 $fatal = 0;
1113 $no_fatal = 1;
327afb7f 1114 }
d3a7d8c7
GS
1115 elsif ($catmask = $Bits{$word}) {
1116 $mask |= $catmask ;
1117 $mask |= $DeadBits{$word} if $fatal ;
6e9af7e4 1118 $mask &= ~($DeadBits{$word}|$All) if $no_fatal ;
599cee73 1119 }
d3a7d8c7 1120 else
c3186b65 1121 { Croaker("Unknown warnings category '$word'")}
599cee73
PM
1122 }
1123
1124 return $mask ;
1125}
1126
4c02ac93
NC
1127sub bits
1128{
1129 # called from B::Deparse.pm
1130 push @_, 'all' unless @_ ;
1131 return _bits(undef, @_) ;
1132}
1133
c4a853d1 1134sub import
6e9af7e4 1135{
599cee73 1136 shift;
6e9af7e4 1137
7fc874e8 1138 my $mask = ${^WARNING_BITS} // ($^W ? $Bits{all} : $DEFAULT) ;
6e9af7e4 1139
f1f33818
PM
1140 if (vec($mask, $Offsets{'all'}, 1)) {
1141 $mask |= $Bits{'all'} ;
1142 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
1143 }
c91312d5
H
1144
1145 # append 'all' when implied (after a lone "FATAL" or "NONFATAL")
1146 push @_, 'all' if @_==1 && ( $_[0] eq 'FATAL' || $_[0] eq 'NONFATAL' );
c4a853d1 1147
4c02ac93
NC
1148 # Empty @_ is equivalent to @_ = 'all' ;
1149 ${^WARNING_BITS} = @_ ? _bits($mask, @_) : $mask | $Bits{all} ;
599cee73
PM
1150}
1151
c4a853d1 1152sub unimport
6e9af7e4 1153{
599cee73 1154 shift;
6e9af7e4
PM
1155
1156 my $catmask ;
7fc874e8 1157 my $mask = ${^WARNING_BITS} // ($^W ? $Bits{all} : $DEFAULT) ;
6e9af7e4 1158
d3a7d8c7 1159 if (vec($mask, $Offsets{'all'}, 1)) {
f1f33818 1160 $mask |= $Bits{'all'} ;
d3a7d8c7
GS
1161 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
1162 }
6e9af7e4 1163
c91312d5
H
1164 # append 'all' when implied (empty import list or after a lone "FATAL")
1165 push @_, 'all' if !@_ || @_==1 && $_[0] eq 'FATAL';
6e9af7e4
PM
1166
1167 foreach my $word ( @_ ) {
1168 if ($word eq 'FATAL') {
c4a853d1 1169 next;
6e9af7e4
PM
1170 }
1171 elsif ($catmask = $Bits{$word}) {
1172 $mask &= ~($catmask | $DeadBits{$word} | $All);
1173 }
1174 else
1175 { Croaker("Unknown warnings category '$word'")}
1176 }
1177
1178 ${^WARNING_BITS} = $mask ;
599cee73
PM
1179}
1180
9df0f64f
MK
1181my %builtin_type; @builtin_type{qw(SCALAR ARRAY HASH CODE REF GLOB LVALUE Regexp)} = ();
1182
96183d25 1183sub MESSAGE () { 4 };
8787a747
NC
1184sub FATAL () { 2 };
1185sub NORMAL () { 1 };
1186
7e6d00f8 1187sub __chk
599cee73 1188{
d3a7d8c7
GS
1189 my $category ;
1190 my $offset ;
7e6d00f8 1191 my $isobj = 0 ;
8787a747 1192 my $wanted = shift;
96183d25
NC
1193 my $has_message = $wanted & MESSAGE;
1194
1195 unless (@_ == 1 || @_ == ($has_message ? 2 : 0)) {
1196 my $sub = (caller 1)[3];
1197 my $syntax = $has_message ? "[category,] 'message'" : '[category]';
1198 Croaker("Usage: $sub($syntax)");
1199 }
1200
1201 my $message = pop if $has_message;
d3a7d8c7
GS
1202
1203 if (@_) {
1204 # check the category supplied.
1205 $category = shift ;
9df0f64f
MK
1206 if (my $type = ref $category) {
1207 Croaker("not an object")
1208 if exists $builtin_type{$type};
1209 $category = $type;
7e6d00f8
PM
1210 $isobj = 1 ;
1211 }
d3a7d8c7 1212 $offset = $Offsets{$category};
c3186b65 1213 Croaker("Unknown warnings category '$category'")
d3a7d8c7
GS
1214 unless defined $offset;
1215 }
1216 else {
0ca4541c 1217 $category = (caller(1))[0] ;
d3a7d8c7 1218 $offset = $Offsets{$category};
c3186b65 1219 Croaker("package '$category' not registered for warnings")
d3a7d8c7
GS
1220 unless defined $offset ;
1221 }
1222
f0a8fd68 1223 my $i;
7e6d00f8
PM
1224
1225 if ($isobj) {
f0a8fd68
NC
1226 my $pkg;
1227 $i = 2;
7e6d00f8
PM
1228 while (do { { package DB; $pkg = (caller($i++))[0] } } ) {
1229 last unless @DB::args && $DB::args[0] =~ /^$category=/ ;
1230 }
1231 $i -= 2 ;
1232 }
1233 else {
4f527b71 1234 $i = _error_loc(); # see where Carp will allocate the error
7e6d00f8
PM
1235 }
1236
7fc874e8
FC
1237 # Default to 0 if caller returns nothing. Default to $DEFAULT if it
1238 # explicitly returns undef.
1239 my(@callers_bitmask) = (caller($i))[9] ;
1240 my $callers_bitmask =
1241 @callers_bitmask ? $callers_bitmask[0] // $DEFAULT : 0 ;
8787a747
NC
1242
1243 my @results;
96183d25 1244 foreach my $type (FATAL, NORMAL) {
8787a747
NC
1245 next unless $wanted & $type;
1246
1247 push @results, (vec($callers_bitmask, $offset + $type - 1, 1) ||
1248 vec($callers_bitmask, $Offsets{'all'} + $type - 1, 1));
1249 }
96183d25
NC
1250
1251 # &enabled and &fatal_enabled
1252 return $results[0] unless $has_message;
1253
1254 # &warnif, and the category is neither enabled as warning nor as fatal
1255 return if $wanted == (NORMAL | FATAL | MESSAGE)
1256 && !($results[0] || $results[1]);
1257
1258 require Carp;
1259 Carp::croak($message) if $results[0];
1260 # will always get here for &warn. will only get here for &warnif if the
1261 # category is enabled
1262 Carp::carp($message);
7e6d00f8
PM
1263}
1264
13781810
FR
1265sub _mkMask
1266{
1267 my ($bit) = @_;
1268 my $mask = "";
1269
1270 vec($mask, $bit, 1) = 1;
1271 return $mask;
1272}
1273
5e7ad92a 1274sub register_categories
13781810
FR
1275{
1276 my @names = @_;
1277
1278 for my $name (@names) {
1279 if (! defined $Bits{$name}) {
1280 $Bits{$name} = _mkMask($LAST_BIT);
1281 vec($Bits{'all'}, $LAST_BIT, 1) = 1;
1282 $Offsets{$name} = $LAST_BIT ++;
1283 foreach my $k (keys %Bits) {
1284 vec($Bits{$k}, $LAST_BIT, 1) = 0;
1285 }
1286 $DeadBits{$name} = _mkMask($LAST_BIT);
1287 vec($DeadBits{'all'}, $LAST_BIT++, 1) = 1;
1288 }
1289 }
1290}
1291
4f527b71 1292sub _error_loc {
4dd71923 1293 require Carp;
4f527b71 1294 goto &Carp::short_error_loc; # don't introduce another stack frame
13781810 1295}
4f527b71 1296
7e6d00f8
PM
1297sub enabled
1298{
8787a747 1299 return __chk(NORMAL, @_);
599cee73
PM
1300}
1301
ec983580
AR
1302sub fatal_enabled
1303{
8787a747 1304 return __chk(FATAL, @_);
ec983580 1305}
d3a7d8c7 1306
e476b1b5
GS
1307sub warn
1308{
96183d25 1309 return __chk(FATAL | MESSAGE, @_);
e476b1b5
GS
1310}
1311
7e6d00f8
PM
1312sub warnif
1313{
96183d25 1314 return __chk(NORMAL | FATAL | MESSAGE, @_);
7e6d00f8 1315}
0d658bf5 1316
8787a747
NC
1317# These are not part of any public interface, so we can delete them to save
1318# space.
b9929960 1319delete @warnings::{qw(NORMAL FATAL MESSAGE)};
8787a747 1320
599cee73 13211;