Lines Matching full:warnings

5 #    lib/warnings.pm
6 # warnings.h
9 # template for warnings.pm in the DATA section.
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
31 # Define the hierarchy of warnings.
35 # version when that warnings category was introduced and, if a terminal
43 # of 'io', a warnings category called 'io::pipe' is NOT automatically
44 # created. But the warnings category 'io' WILL include all the mask bits
321 # return a string containing a visual representation of the warnings tree
421 open_new($_, '>', { by => 'regen/warnings.pl' });
422 } 'warnings.h', 'lib/warnings.pm';
426 # generate warnings.h
433 Too many warnings categories -- max is 255
450 print $warn_h "\n/* Warnings Categories added in Perl $version */\n\n"
468 print $warn_h "/* end of file warnings.h */\n";
473 # generate warnings.pm
495 print $warn_pm tab(6, " # Warnings Categories added in Perl $version");
544 if ($_ eq "=for warnings.pl tree-goes-here\n") {
573 #define pWARN_ALL &PL_WARN_ALL /* use warnings 'all' */
574 #define pWARN_NONE &PL_WARN_NONE /* no warnings 'all' */
579 /* if PL_warnhook is set to this value, then warnings die */
613 L<warnings/Category Hierarchy>, just capitalize all letters in the names
622 These return a boolean as to whether or not warnings are enabled for any of
626 scope of S<C<use warnings>>, instead use the C<L</ckWARN_d>> macros.
637 default enabled even if not within the scope of S<C<use warnings>>.
655 /* The w1, w2 ... should be independent warnings categories; one shouldn't be
671 /* The a, b, ... should be independent warnings categories; one shouldn't be
699 package warnings;
703 # Verify that we're called correctly so that warnings will work.
716 local $Carp::CarpInternal{'warnings'};
717 delete $Carp::CarpInternal{'warnings'};
763 { Croaker("Unknown warnings category '$word'")}
818 { Croaker("Unknown warnings category '$word'")}
867 Croaker("Unknown warnings category '$category'")
873 Croaker("package '$category' not registered for warnings")
1008 delete @warnings::{qw(NORMAL FATAL MESSAGE LEVEL)};
1015 warnings - Perl pragma to control optional warnings
1019 use warnings;
1020 no warnings;
1022 # Standard warnings are enabled by use v5.35 or above
1025 use warnings "all";
1026 no warnings "uninitialized";
1029 use warnings qw(all -uninitialized);
1031 use warnings::register;
1032 if (warnings::enabled()) {
1033 warnings::warn("some warning");
1036 if (warnings::enabled("void")) {
1037 warnings::warn("void", "some warning");
1040 if (warnings::enabled($object)) {
1041 warnings::warn($object, "some warning");
1044 warnings::warnif("some warning");
1045 warnings::warnif("void", "some warning");
1046 warnings::warnif($object, "some warning");
1050 The C<warnings> pragma gives control over which warnings are enabled in
1062 By default, optional warnings are disabled, so any legacy code that
1063 doesn't attempt to control the warnings will work unchanged.
1065 All warnings are enabled in a block by either of these:
1067 use warnings;
1068 use warnings 'all';
1070 Similarly all warnings are disabled in a block by either of these:
1072 no warnings;
1073 no warnings 'all';
1077 use warnings;
1080 no warnings;
1085 The code in the enclosing block has warnings enabled, but the inner
1090 All warnings are enabled automatically within the scope of
1093 =head2 Default Warnings and Optional Warnings
1095 Before the introduction of lexical warnings, Perl had two classes of
1096 warnings: mandatory and optional.
1105 With the introduction of lexical warnings, mandatory warnings now become
1106 I<default> warnings. The difference is that although the previously
1107 mandatory warnings are still enabled by default, they can then be
1113 no warnings;
1117 disable/enable default warnings. They are still mandatory in this case.
1119 =head2 "Negative warnings"
1122 C<import()> method both positively and negatively. Negative warnings
1123 are those with a C<-> sign prepended to their names; positive warnings
1124 are anything else. This lets you turn on some warnings and turn off
1126 bunch of warnings but want to tweak them a bit in some block, you can
1130 use warnings qw(uninitialized -redefine);
1137 use warnings qw(uninitialized);
1138 no warnings qw(redefine);
1146 use warnings qw(all -experimental experimental::somefeature);
1150 use warnings 'all';
1151 no warnings 'experimental';
1152 use warnings 'experimental::somefeature';
1155 the corresponding warnings are not printed anymore.
1158 It is still possible to request turning on or off these warnings,
1164 line to enable warnings is that it is all or nothing. Take the typical
1168 end up enabling warnings in pieces of code that you haven't written.
1171 fundamentally flawed. For a start, say you want to disable warnings in
1183 The problem is that Perl has both compile-time and run-time warnings. To
1184 disable compile-time warnings you need to rewrite the code like this:
1216 Lexical warnings get around these limitations by allowing finer control
1217 over where warnings can or can't be tripped.
1219 =head2 Controlling Warnings from the Command Line
1222 warnings are (or aren't) produced:
1229 This is the existing flag. If the lexical warnings pragma is B<not>
1231 will enable warnings everywhere. See L</Backward Compatibility> for
1232 details of how this flag interacts with lexical warnings.
1237 If the B<-W> flag is used on the command line, it will enable all warnings
1238 throughout the program regardless of whether warnings were disabled
1239 locally using C<no warnings> or C<$^W =0>.
1247 Does the exact opposite to the B<-W> flag, i.e. it disables all warnings.
1254 introduction of lexically scoped warnings, or have code that uses both
1255 lexical warnings and C<$^W>, this section will describe how they interact.
1257 How Lexical Warnings interact with B<-w>/C<$^W>:
1264 control warnings is used and neither C<$^W> nor the C<warnings> pragma
1265 are used, then default warnings will be enabled and optional warnings
1267 This means that legacy code that doesn't attempt to control the warnings
1280 disable/enable default warnings.
1284 If a piece of code is under the control of the C<warnings> pragma,
1290 The only way to override a lexical warnings setting is with the B<-W>
1296 the C<warnings> pragma to control the warning behavior of $^W-type
1302 A hierarchy of "categories" have been defined to allow groups of warnings
1307 =for warnings.pl tree-goes-here
1311 use warnings qw(void redefine);
1312 no warnings qw(io syntax untie);
1315 C<warnings> pragma in a given scope the cumulative effect is additive.
1317 use warnings qw(void); # only "void" warnings enabled
1319 use warnings qw(io); # only "void" & "io" warnings enabled
1321 no warnings qw(void); # only "io" warnings enabled
1326 Note: Before Perl 5.8.0, the lexical warnings category "deprecated" was a
1330 Note: Before 5.21.0, the "missing" lexical warnings category was
1334 =head2 Fatal Warnings
1338 warnings in those categories into fatal errors in that lexical scope.
1340 B<NOTE:> FATAL warnings should be used with care, particularly
1343 Libraries using L<warnings::warn|/FUNCTIONS> for custom warning categories
1344 generally don't expect L<warnings::warn|/FUNCTIONS> to be fatal and can wind up
1346 warnings, such unanticipated exceptions could also expose memory leak bugs.
1349 fatalized warnings. For a summary of resolved and unresolved problems as
1353 While some developers find fatalizing some warnings to be a useful
1360 a warnings subset that the module's authors believe is relatively safe to
1363 B<NOTE:> Users of FATAL warnings, especially those using
1366 commitments to not introduce new warnings or warnings categories in the
1370 using FATAL warnings break due to the introduction of a new warning we will
1371 NOT consider it an incompatible change. Users of FATAL warnings should
1373 any new warnings and should pay particular attention to the fine print of
1377 and spirit. Use of such features in combination with FATAL warnings is
1380 The following documentation describes how to use FATAL warnings but the
1389 use warnings;
1394 use warnings FATAL => qw(void);
1407 The scope where C<length> is used has escalated the C<void> warnings
1415 no warnings qw(void);
1416 no warnings FATAL => qw(void);
1420 example, the code below will promote all warnings into fatal errors,
1423 use warnings FATAL => 'all', NONFATAL => 'syntax';
1425 As of Perl 5.20, instead of C<< use warnings FATAL => 'all'; >> you can
1429 use warnings 'FATAL'; # short form of "use warnings FATAL => 'all';"
1432 using C<< use warnings FATAL => 'all'; >>.
1435 5.20, you must use C<< use warnings FATAL => 'all'; >> instead. (In
1437 C<< use warnings 'FATAL'; >>, C<< use warnings 'NONFATAL'; >> and
1438 C<< no warnings 'FATAL'; >> was unspecified; they did not behave as if
1441 =head2 Reporting Warnings from a Module
1444 The C<warnings> pragma provides a number of functions that are useful for
1446 warning to a calling module that has enabled warnings via the C<warnings>
1453 use warnings::register;
1458 warnings::warn("changing relative path to /var/abc")
1459 if warnings::enabled();
1466 The call to C<warnings::register> will create a new warnings category
1471 enabled them with the C<warnings> pragma as below - note that a plain
1472 C<use warnings> enables even warnings that have not yet been registered.
1474 use warnings;
1482 # no warnings 'MyMod::Abc'; # error, unknown category before
1485 no warnings 'MyMod::Abc'; # ok after the module is loaded
1489 It is also possible to test whether the pre-defined warnings categories are
1490 set in the calling module with the C<warnings::enabled> function. Consider
1496 if (warnings::enabled("deprecated")) {
1497 warnings::warn("deprecated",
1509 "deprecated" warnings category enabled. Something like this, say.
1511 use warnings 'deprecated';
1516 Either the C<warnings::warn> or C<warnings::warnif> function should be
1517 used to actually display the warnings message. This is because they can
1518 make use of the feature that allows warnings to be escalated into fatal
1522 use warnings FATAL => 'MyMod::Abc';
1526 the C<warnings::warnif> function will detect this and die after
1529 The three warnings functions, C<warnings::warn>, C<warnings::warnif>
1530 and C<warnings::enabled> can optionally take an object reference in place
1532 of the object as the warnings category.
1538 no warnings;
1539 use warnings::register;
1552 if ($value % 2 && warnings::enabled($self))
1553 { warnings::warn($self, "Odd numbers are unsafe") }
1568 use warnings::register;
1580 The code below makes use of both modules, but it only enables warnings from
1585 use warnings 'Derived';
1600 warnings::register like this:
1603 use warnings::register qw(format precision);
1607 warnings::warnif('MyModule::format', '...');
1616 =item use warnings::register
1618 Creates a new warnings category with the same name as the package where
1621 =item warnings::enabled()
1623 Use the warnings category with the same name as the current package.
1625 Return TRUE if that warnings category is enabled in the calling module.
1628 =item warnings::enabled($category)
1630 Return TRUE if the warnings category, C<$category>, is enabled in the
1634 =item warnings::enabled($object)
1637 warnings category.
1639 Return TRUE if that warnings category is enabled in the first scope
1643 =item warnings::enabled_at_level($category, $level)
1645 Like C<warnings::enabled>, but $level specifies the exact call frame, 0
1648 =item warnings::fatal_enabled()
1650 Return TRUE if the warnings category with the same name as the current
1654 =item warnings::fatal_enabled($category)
1656 Return TRUE if the warnings category C<$category> has been set to FATAL in
1660 =item warnings::fatal_enabled($object)
1663 warnings category.
1665 Return TRUE if that warnings category has been set to FATAL in the first
1669 =item warnings::fatal_enabled_at_level($category, $level)
1671 Like C<warnings::fatal_enabled>, but $level specifies the exact call frame,
1674 =item warnings::warn($message)
1678 Use the warnings category with the same name as the current package.
1680 If that warnings category has been set to "FATAL" in the calling module
1683 =item warnings::warn($category, $message)
1687 If the warnings category, C<$category>, has been set to "FATAL" in the
1690 =item warnings::warn($object, $message)
1695 warnings category.
1697 If that warnings category has been set to "FATAL" in the scope where C<$object>
1700 =item warnings::warn_at_level($category, $level, $message)
1702 Like C<warnings::warn>, but $level specifies the exact call frame,
1705 =item warnings::warnif($message)
1709 if (warnings::enabled())
1710 { warnings::warn($message) }
1712 =item warnings::warnif($category, $message)
1716 if (warnings::enabled($category))
1717 { warnings::warn($category, $message) }
1719 =item warnings::warnif($object, $message)
1723 if (warnings::enabled($object))
1724 { warnings::warn($object, $message) }
1726 =item warnings::warnif_at_level($category, $level, $message)
1728 Like C<warnings::warnif>, but $level specifies the exact call frame,
1731 =item warnings::register_categories(@names)
1734 use by the warnings::register pragma.