1 # -*- buffer-read-only: t -*-
2 # !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
3 # This file is built by regen/warnings.pl.
4 # Any changes made here will be lost!
10 # Verify that we're called correctly so that warnings will work.
12 unless ( __FILE__ =~ /(^|[\/\\])\Q${\__PACKAGE__}\E\.pmc?$/ ) {
13 my (undef, $f, $l) = caller;
14 die("Incorrect use of pragma '${\__PACKAGE__}' at $f line $l.\n");
19 warnings - Perl pragma to control optional warnings
29 use warnings::register;
30 if (warnings::enabled()) {
31 warnings::warn("some warning");
34 if (warnings::enabled("void")) {
35 warnings::warn("void", "some warning");
38 if (warnings::enabled($object)) {
39 warnings::warn($object, "some warning");
42 warnings::warnif("some warning");
43 warnings::warnif("void", "some warning");
44 warnings::warnif($object, "some warning");
48 The C<warnings> pragma gives control over which warnings are enabled in
49 which parts of a Perl program. It's a more flexible alternative for
50 both the command line flag B<-w> and the equivalent Perl variable,
53 This pragma works just like the C<strict> pragma.
54 This means that the scope of the warning pragma is limited to the
55 enclosing block. It also means that the pragma setting will not
56 leak across files (via C<use>, C<require> or C<do>). This allows
57 authors to independently define the degree of warning checks that will
58 be applied to their module.
60 By default, optional warnings are disabled, so any legacy code that
61 doesn't attempt to control the warnings will work unchanged.
63 All warnings are enabled in a block by either of these:
68 Similarly all warnings are disabled in a block by either of these:
73 For example, consider the code below:
83 The code in the enclosing block has warnings enabled, but the inner
84 block has them disabled. In this case that means the assignment to the
85 scalar C<$c> will trip the C<"Scalar value @a[0] better written as $a[0]">
86 warning, but the assignment to the scalar C<$b> will not.
88 =head2 Default Warnings and Optional Warnings
90 Before the introduction of lexical warnings, Perl had two classes of
91 warnings: mandatory and optional.
93 As its name suggests, if your code tripped a mandatory warning, you
94 would get a warning whether you wanted it or not.
95 For example, the code below would always produce an C<"isn't numeric">
96 warning about the "2:".
100 With the introduction of lexical warnings, mandatory warnings now become
101 I<default> warnings. The difference is that although the previously
102 mandatory warnings are still enabled by default, they can then be
103 subsequently enabled or disabled with the lexical warning pragma. For
104 example, in the code below, an C<"isn't numeric"> warning will only
105 be reported for the C<$a> variable.
111 Note that neither the B<-w> flag or the C<$^W> can be used to
112 disable/enable default warnings. They are still mandatory in this case.
114 =head2 What's wrong with B<-w> and C<$^W>
116 Although very useful, the big problem with using B<-w> on the command
117 line to enable warnings is that it is all or nothing. Take the typical
118 scenario when you are writing a Perl program. Parts of the code you
119 will write yourself, but it's very likely that you will make use of
120 pre-written Perl modules. If you use the B<-w> flag in this case, you
121 end up enabling warnings in pieces of code that you haven't written.
123 Similarly, using C<$^W> to either disable or enable blocks of code is
124 fundamentally flawed. For a start, say you want to disable warnings in
125 a block of code. You might expect this to be enough to do the trick:
133 When this code is run with the B<-w> flag, a warning will be produced
134 for the C<$a> line: C<"Reversed += operator">.
136 The problem is that Perl has both compile-time and run-time warnings. To
137 disable compile-time warnings you need to rewrite the code like this:
145 The other big problem with C<$^W> is the way you can inadvertently
146 change the warning setting in unexpected places in your code. For example,
147 when the code below is run (without the B<-w> flag), the second call
148 to C<doit> will trip a C<"Use of uninitialized value"> warning, whereas
163 This is a side-effect of C<$^W> being dynamically scoped.
165 Lexical warnings get around these limitations by allowing finer control
166 over where warnings can or can't be tripped.
168 =head2 Controlling Warnings from the Command Line
170 There are three Command Line flags that can be used to control when
171 warnings are (or aren't) produced:
178 This is the existing flag. If the lexical warnings pragma is B<not>
179 used in any of you code, or any of the modules that you use, this flag
180 will enable warnings everywhere. See L<Backward Compatibility> for
181 details of how this flag interacts with lexical warnings.
186 If the B<-W> flag is used on the command line, it will enable all warnings
187 throughout the program regardless of whether warnings were disabled
188 locally using C<no warnings> or C<$^W =0>.
189 This includes all files that get
190 included via C<use>, C<require> or C<do>.
191 Think of it as the Perl equivalent of the "lint" command.
196 Does the exact opposite to the B<-W> flag, i.e. it disables all warnings.
200 =head2 Backward Compatibility
202 If you are used to working with a version of Perl prior to the
203 introduction of lexically scoped warnings, or have code that uses both
204 lexical warnings and C<$^W>, this section will describe how they interact.
206 How Lexical Warnings interact with B<-w>/C<$^W>:
212 If none of the three command line flags (B<-w>, B<-W> or B<-X>) that
213 control warnings is used and neither C<$^W> nor the C<warnings> pragma
214 are used, then default warnings will be enabled and optional warnings
216 This means that legacy code that doesn't attempt to control the warnings
221 The B<-w> flag just sets the global C<$^W> variable as in 5.005. This
222 means that any legacy code that currently relies on manipulating C<$^W>
223 to control warning behavior will still work as is.
227 Apart from now being a boolean, the C<$^W> variable operates in exactly
228 the same horrible uncontrolled global way, except that it cannot
229 disable/enable default warnings.
233 If a piece of code is under the control of the C<warnings> pragma,
234 both the C<$^W> variable and the B<-w> flag will be ignored for the
235 scope of the lexical warning.
239 The only way to override a lexical warnings setting is with the B<-W>
240 or B<-X> command line flags.
244 The combined effect of 3 & 4 is that it will allow code which uses
245 the C<warnings> pragma to control the warning behavior of $^W-type
246 code (using a C<local $^W=0>) if it really wants to, but not vice-versa.
248 =head2 Category Hierarchy
249 X<warning, categories>
251 A hierarchy of "categories" have been defined to allow groups of warnings
252 to be enabled/disabled in isolation.
254 The current hierarchy is:
266 | +- experimental::autoderef
268 | +- experimental::lexical_subs
270 | +- experimental::lexical_topic
272 | +- experimental::postderef
274 | +- experimental::regex_sets
276 | +- experimental::signatures
278 | +- experimental::smartmatch
280 | +- experimental::win32_perlio
380 Just like the "strict" pragma any of these categories can be combined
382 use warnings qw(void redefine);
383 no warnings qw(io syntax untie);
385 Also like the "strict" pragma, if there is more than one instance of the
386 C<warnings> pragma in a given scope the cumulative effect is additive.
388 use warnings qw(void); # only "void" warnings enabled
390 use warnings qw(io); # only "void" & "io" warnings enabled
392 no warnings qw(void); # only "io" warnings enabled
394 To determine which category a specific warning has been assigned to see
397 Note: Before Perl 5.8.0, the lexical warnings category "deprecated" was a
398 sub-category of the "syntax" category. It is now a top-level category
401 Note: Before 5.21.0, the "missing" lexical warnings category was
402 internally defined to be the same as the "uninitialized" category. It
403 is now a top-level category in its own right.
405 =head2 Fatal Warnings
408 The presence of the word "FATAL" in the category list will escalate any
409 warnings detected from the categories specified in the lexical scope
410 into fatal errors. In the code below, the use of C<time>, C<length>
411 and C<join> can all produce a C<"Useless use of xxx in void context">
419 use warnings FATAL => qw(void);
427 When run it produces this output
429 Useless use of time in void context at fatal line 3.
430 Useless use of length in void context at fatal line 7.
432 The scope where C<length> is used has escalated the C<void> warnings
433 category into a fatal error, so the program terminates immediately when it
434 encounters the warning.
436 To explicitly turn off a "FATAL" warning you just disable the warning
437 it is associated with. So, for example, to disable the "void" warning
438 in the example above, either of these will do the trick:
440 no warnings qw(void);
441 no warnings FATAL => qw(void);
443 If you want to downgrade a warning that has been escalated into a fatal
444 error back to a normal warning, you can use the "NONFATAL" keyword. For
445 example, the code below will promote all warnings into fatal errors,
446 except for those in the "syntax" category.
448 use warnings FATAL => 'all', NONFATAL => 'syntax';
450 As of Perl 5.20, instead of C<< use warnings FATAL => 'all'; >> you can
453 use v5.20; # Perl 5.20 or greater is required for the following
454 use warnings 'FATAL'; # short form of "use warnings FATAL => 'all';"
456 If you want your program to be compatible with versions of Perl before
457 5.20, you must use C<< use warnings FATAL => 'all'; >> instead. (In
458 previous versions of Perl, the behavior of the statements
459 C<< use warnings 'FATAL'; >>, C<< use warnings 'NONFATAL'; >> and
460 C<< no warnings 'FATAL'; >> was unspecified; they did not behave as if
461 they included the C<< => 'all' >> portion. As of 5.20, they do.)
463 B<NOTE:> Users of FATAL warnings, especially
464 those using C<< FATAL => 'all' >>
465 should be fully aware that they are risking future portability of their
466 programs by doing so. Perl makes absolutely no commitments to not
467 introduce new warnings, or warnings categories in the future, and indeed
468 we explicitly reserve the right to do so. Code that may not warn now may
469 warn in a future release of Perl if the Perl5 development team deems it
470 in the best interests of the community to do so. Should code using FATAL
471 warnings break due to the introduction of a new warning we will NOT
472 consider it an incompatible change. Users of FATAL warnings should take
473 special caution during upgrades to check to see if their code triggers
474 any new warnings and should pay particular attention to the fine print of
475 the documentation of the features they use to ensure they do not exploit
476 features that are documented as risky, deprecated, or unspecified, or where
477 the documentation says "so don't do that", or anything with the same sense
478 and spirit. Use of such features in combination with FATAL warnings is
479 ENTIRELY AT THE USER'S RISK.
481 =head2 Reporting Warnings from a Module
482 X<warning, reporting> X<warning, registering>
484 The C<warnings> pragma provides a number of functions that are useful for
485 module authors. These are used when you want to report a module-specific
486 warning to a calling module has enabled warnings via the C<warnings>
489 Consider the module C<MyMod::Abc> below.
493 use warnings::register;
497 if ($path !~ m#^/#) {
498 warnings::warn("changing relative path to /var/abc")
499 if warnings::enabled();
500 $path = "/var/abc/$path";
506 The call to C<warnings::register> will create a new warnings category
507 called "MyMod::Abc", i.e. the new category name matches the current
508 package name. The C<open> function in the module will display a warning
509 message if it gets given a relative path as a parameter. This warnings
510 will only be displayed if the code that uses C<MyMod::Abc> has actually
511 enabled them with the C<warnings> pragma like below.
514 use warnings 'MyMod::Abc';
516 abc::open("../fred.txt");
518 It is also possible to test whether the pre-defined warnings categories are
519 set in the calling module with the C<warnings::enabled> function. Consider
520 this snippet of code:
525 warnings::warnif("deprecated",
526 "open is deprecated, use new instead");
534 The function C<open> has been deprecated, so code has been included to
535 display a warning message whenever the calling module has (at least) the
536 "deprecated" warnings category enabled. Something like this, say.
538 use warnings 'deprecated';
541 MyMod::Abc::open($filename);
543 Either the C<warnings::warn> or C<warnings::warnif> function should be
544 used to actually display the warnings message. This is because they can
545 make use of the feature that allows warnings to be escalated into fatal
546 errors. So in this case
549 use warnings FATAL => 'MyMod::Abc';
551 MyMod::Abc::open('../fred.txt');
553 the C<warnings::warnif> function will detect this and die after
554 displaying the warning message.
556 The three warnings functions, C<warnings::warn>, C<warnings::warnif>
557 and C<warnings::enabled> can optionally take an object reference in place
558 of a category name. In this case the functions will use the class name
559 of the object as the warnings category.
561 Consider this example:
566 use warnings::register;
579 if ($value % 2 && warnings::enabled($self))
580 { warnings::warn($self, "Odd numbers are unsafe") }
587 $self->check($value);
595 use warnings::register;
597 our @ISA = qw( Original );
607 The code below makes use of both modules, but it only enables warnings from
612 use warnings 'Derived';
613 my $a = Original->new();
615 my $b = Derived->new();
618 When this code is run only the C<Derived> object, C<$b>, will generate
621 Odd numbers are unsafe at main.pl line 7
623 Notice also that the warning is reported at the line where the object is first
626 When registering new categories of warning, you can supply more names to
627 warnings::register like this:
630 use warnings::register qw(format precision);
634 warnings::warnif('MyModule::format', '...');
640 =item use warnings::register
642 Creates a new warnings category with the same name as the package where
643 the call to the pragma is used.
645 =item warnings::enabled()
647 Use the warnings category with the same name as the current package.
649 Return TRUE if that warnings category is enabled in the calling module.
650 Otherwise returns FALSE.
652 =item warnings::enabled($category)
654 Return TRUE if the warnings category, C<$category>, is enabled in the
656 Otherwise returns FALSE.
658 =item warnings::enabled($object)
660 Use the name of the class for the object reference, C<$object>, as the
663 Return TRUE if that warnings category is enabled in the first scope
664 where the object is used.
665 Otherwise returns FALSE.
667 =item warnings::fatal_enabled()
669 Return TRUE if the warnings category with the same name as the current
670 package has been set to FATAL in the calling module.
671 Otherwise returns FALSE.
673 =item warnings::fatal_enabled($category)
675 Return TRUE if the warnings category C<$category> has been set to FATAL in
677 Otherwise returns FALSE.
679 =item warnings::fatal_enabled($object)
681 Use the name of the class for the object reference, C<$object>, as the
684 Return TRUE if that warnings category has been set to FATAL in the first
685 scope where the object is used.
686 Otherwise returns FALSE.
688 =item warnings::warn($message)
690 Print C<$message> to STDERR.
692 Use the warnings category with the same name as the current package.
694 If that warnings category has been set to "FATAL" in the calling module
695 then die. Otherwise return.
697 =item warnings::warn($category, $message)
699 Print C<$message> to STDERR.
701 If the warnings category, C<$category>, has been set to "FATAL" in the
702 calling module then die. Otherwise return.
704 =item warnings::warn($object, $message)
706 Print C<$message> to STDERR.
708 Use the name of the class for the object reference, C<$object>, as the
711 If that warnings category has been set to "FATAL" in the scope where C<$object>
712 is first used then die. Otherwise return.
715 =item warnings::warnif($message)
719 if (warnings::enabled())
720 { warnings::warn($message) }
722 =item warnings::warnif($category, $message)
726 if (warnings::enabled($category))
727 { warnings::warn($category, $message) }
729 =item warnings::warnif($object, $message)
733 if (warnings::enabled($object))
734 { warnings::warn($object, $message) }
736 =item warnings::register_categories(@names)
738 This registers warning categories for the given names and is primarily for
739 use by the warnings::register pragma.
743 See also L<perlmodlib/Pragmatic Modules> and L<perldiag>.
749 # Warnings Categories added in Perl 5.008
792 'uninitialized' => 82,
798 # Warnings Categories added in Perl 5.011
801 'illegalproto' => 94,
803 # Warnings Categories added in Perl 5.013
809 # Warnings Categories added in Perl 5.017
811 'experimental' => 102,
812 'experimental::lexical_subs'=> 104,
813 'experimental::lexical_topic'=> 106,
814 'experimental::regex_sets'=> 108,
815 'experimental::smartmatch'=> 110,
817 # Warnings Categories added in Perl 5.019
819 'experimental::autoderef'=> 112,
820 'experimental::postderef'=> 114,
821 'experimental::signatures'=> 116,
824 # Warnings Categories added in Perl 5.021
826 'experimental::win32_perlio'=> 120,
831 'all' => "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x05", # [0..61]
832 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00", # [29]
833 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00", # [30]
834 'closed' => "\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
835 'closure' => "\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
836 'debugging' => "\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [22]
837 'deprecated' => "\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
838 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00", # [31]
839 'exec' => "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
840 'exiting' => "\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
841 'experimental' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x55\x15\x01", # [51..58,60]
842 'experimental::autoderef'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00", # [56]
843 'experimental::lexical_subs'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00", # [52]
844 'experimental::lexical_topic'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00", # [53]
845 'experimental::postderef'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00", # [57]
846 'experimental::regex_sets'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00", # [54]
847 'experimental::signatures'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00", # [58]
848 'experimental::smartmatch'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00", # [55]
849 'experimental::win32_perlio'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", # [60]
850 'glob' => "\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
851 'illegalproto' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00", # [47]
852 'imprecision' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00", # [46]
853 'inplace' => "\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [23]
854 'internal' => "\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [24]
855 'io' => "\x00\x54\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00", # [5..11,59]
856 'layer' => "\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
857 'malloc' => "\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [25]
858 'misc' => "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
859 'missing' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04", # [61]
860 'newline' => "\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
861 'non_unicode' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00", # [48]
862 'nonchar' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00", # [49]
863 'numeric' => "\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
864 'once' => "\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
865 'overflow' => "\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
866 'pack' => "\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [16]
867 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00", # [32]
868 'pipe' => "\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
869 'portable' => "\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [17]
870 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00", # [33]
871 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00", # [34]
872 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00", # [35]
873 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00", # [36]
874 'recursion' => "\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [18]
875 'redefine' => "\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [19]
876 'regexp' => "\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [20]
877 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00", # [37]
878 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00", # [38]
879 'severe' => "\x00\x00\x00\x00\x00\x54\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [21..25]
880 'signal' => "\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [26]
881 'substr' => "\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [27]
882 'surrogate' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00", # [50]
883 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\x55\x55\x15\x00\x40\x00\x00\x00\x00", # [28..38,47]
884 'syscalls' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00", # [59]
885 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00", # [39]
886 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00", # [40]
887 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00", # [41]
888 'unopened' => "\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
889 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00", # [42]
890 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00", # [43]
891 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x15\x00\x00\x00", # [44,48..50]
892 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00", # [45]
896 'all' => "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\x0a", # [0..61]
897 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00", # [29]
898 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00", # [30]
899 'closed' => "\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
900 'closure' => "\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
901 'debugging' => "\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [22]
902 'deprecated' => "\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
903 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00", # [31]
904 'exec' => "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
905 'exiting' => "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
906 'experimental' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xaa\x2a\x02", # [51..58,60]
907 'experimental::autoderef'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00", # [56]
908 'experimental::lexical_subs'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00", # [52]
909 'experimental::lexical_topic'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00", # [53]
910 'experimental::postderef'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00", # [57]
911 'experimental::regex_sets'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00", # [54]
912 'experimental::signatures'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00", # [58]
913 'experimental::smartmatch'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00", # [55]
914 'experimental::win32_perlio'=> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02", # [60]
915 'glob' => "\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
916 'illegalproto' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00", # [47]
917 'imprecision' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00", # [46]
918 'inplace' => "\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [23]
919 'internal' => "\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [24]
920 'io' => "\x00\xa8\xaa\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00", # [5..11,59]
921 'layer' => "\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
922 'malloc' => "\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [25]
923 'misc' => "\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
924 'missing' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08", # [61]
925 'newline' => "\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
926 'non_unicode' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00", # [48]
927 'nonchar' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00", # [49]
928 'numeric' => "\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
929 'once' => "\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
930 'overflow' => "\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
931 'pack' => "\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [16]
932 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", # [32]
933 'pipe' => "\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
934 'portable' => "\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [17]
935 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00", # [33]
936 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00", # [34]
937 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00", # [35]
938 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00", # [36]
939 'recursion' => "\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [18]
940 'redefine' => "\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [19]
941 'regexp' => "\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [20]
942 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00", # [37]
943 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00", # [38]
944 'severe' => "\x00\x00\x00\x00\x00\xa8\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [21..25]
945 'signal' => "\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [26]
946 'substr' => "\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [27]
947 'surrogate' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00", # [50]
948 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\xaa\xaa\x2a\x00\x80\x00\x00\x00\x00", # [28..38,47]
949 'syscalls' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00", # [59]
950 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00", # [39]
951 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00", # [40]
952 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00", # [41]
953 'unopened' => "\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
954 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00", # [42]
955 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00", # [43]
956 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x2a\x00\x00\x00", # [44,48..50]
957 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00", # [45]
960 $NONE = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
961 $DEFAULT = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x00\x55\x15\x01", # [2,56,52,53,57,54,58,55,60,4,22,23,25]
965 $All = "" ; vec($All, $Offsets{'all'}, 2) = 3 ;
969 require Carp; # this initializes %CarpInternal
970 local $Carp::CarpInternal{'warnings'};
971 delete $Carp::CarpInternal{'warnings'};
981 foreach my $word ( @_ ) {
982 if ($word eq 'FATAL') {
986 elsif ($word eq 'NONFATAL') {
990 elsif ($catmask = $Bits{$word}) {
992 $mask |= $DeadBits{$word} if $fatal ;
993 $mask &= ~($DeadBits{$word}|$All) if $no_fatal ;
996 { Croaker("Unknown warnings category '$word'")}
1004 # called from B::Deparse.pm
1005 push @_, 'all' unless @_ ;
1006 return _bits(undef, @_) ;
1013 my $mask = ${^WARNING_BITS} // ($^W ? $Bits{all} : $DEFAULT) ;
1015 if (vec($mask, $Offsets{'all'}, 1)) {
1016 $mask |= $Bits{'all'} ;
1017 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
1020 # append 'all' when implied (after a lone "FATAL" or "NONFATAL")
1021 push @_, 'all' if @_==1 && ( $_[0] eq 'FATAL' || $_[0] eq 'NONFATAL' );
1023 # Empty @_ is equivalent to @_ = 'all' ;
1024 ${^WARNING_BITS} = @_ ? _bits($mask, @_) : $mask | $Bits{all} ;
1032 my $mask = ${^WARNING_BITS} // ($^W ? $Bits{all} : $DEFAULT) ;
1034 if (vec($mask, $Offsets{'all'}, 1)) {
1035 $mask |= $Bits{'all'} ;
1036 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
1039 # append 'all' when implied (empty import list or after a lone "FATAL")
1040 push @_, 'all' if !@_ || @_==1 && $_[0] eq 'FATAL';
1042 foreach my $word ( @_ ) {
1043 if ($word eq 'FATAL') {
1046 elsif ($catmask = $Bits{$word}) {
1047 $mask &= ~($catmask | $DeadBits{$word} | $All);
1050 { Croaker("Unknown warnings category '$word'")}
1053 ${^WARNING_BITS} = $mask ;
1056 my %builtin_type; @builtin_type{qw(SCALAR ARRAY HASH CODE REF GLOB LVALUE Regexp)} = ();
1058 sub MESSAGE () { 4 };
1060 sub NORMAL () { 1 };
1068 my $has_message = $wanted & MESSAGE;
1070 unless (@_ == 1 || @_ == ($has_message ? 2 : 0)) {
1071 my $sub = (caller 1)[3];
1072 my $syntax = $has_message ? "[category,] 'message'" : '[category]';
1073 Croaker("Usage: $sub($syntax)");
1076 my $message = pop if $has_message;
1079 # check the category supplied.
1081 if (my $type = ref $category) {
1082 Croaker("not an object")
1083 if exists $builtin_type{$type};
1087 $offset = $Offsets{$category};
1088 Croaker("Unknown warnings category '$category'")
1089 unless defined $offset;
1092 $category = (caller(1))[0] ;
1093 $offset = $Offsets{$category};
1094 Croaker("package '$category' not registered for warnings")
1095 unless defined $offset ;
1103 while (do { { package DB; $pkg = (caller($i++))[0] } } ) {
1104 last unless @DB::args && $DB::args[0] =~ /^$category=/ ;
1109 $i = _error_loc(); # see where Carp will allocate the error
1112 # Default to 0 if caller returns nothing. Default to $DEFAULT if it
1113 # explicitly returns undef.
1114 my(@callers_bitmask) = (caller($i))[9] ;
1115 my $callers_bitmask =
1116 @callers_bitmask ? $callers_bitmask[0] // $DEFAULT : 0 ;
1119 foreach my $type (FATAL, NORMAL) {
1120 next unless $wanted & $type;
1122 push @results, (vec($callers_bitmask, $offset + $type - 1, 1) ||
1123 vec($callers_bitmask, $Offsets{'all'} + $type - 1, 1));
1126 # &enabled and &fatal_enabled
1127 return $results[0] unless $has_message;
1129 # &warnif, and the category is neither enabled as warning nor as fatal
1130 return if $wanted == (NORMAL | FATAL | MESSAGE)
1131 && !($results[0] || $results[1]);
1134 Carp::croak($message) if $results[0];
1135 # will always get here for &warn. will only get here for &warnif if the
1136 # category is enabled
1137 Carp::carp($message);
1145 vec($mask, $bit, 1) = 1;
1149 sub register_categories
1153 for my $name (@names) {
1154 if (! defined $Bits{$name}) {
1155 $Bits{$name} = _mkMask($LAST_BIT);
1156 vec($Bits{'all'}, $LAST_BIT, 1) = 1;
1157 $Offsets{$name} = $LAST_BIT ++;
1158 foreach my $k (keys %Bits) {
1159 vec($Bits{$k}, $LAST_BIT, 1) = 0;
1161 $DeadBits{$name} = _mkMask($LAST_BIT);
1162 vec($DeadBits{'all'}, $LAST_BIT++, 1) = 1;
1169 goto &Carp::short_error_loc; # don't introduce another stack frame
1174 return __chk(NORMAL, @_);
1179 return __chk(FATAL, @_);
1184 return __chk(FATAL | MESSAGE, @_);
1189 return __chk(NORMAL | FATAL | MESSAGE, @_);
1192 # These are not part of any public interface, so we can delete them to save
1194 delete @warnings::{qw(NORMAL FATAL MESSAGE)};