Lines Matching defs:warnings

3 # This file is built by regen/warnings.pl.
6 package warnings;
10 # Verify that we're called correctly so that warnings will work.
328 local $Carp::CarpInternal{'warnings'};
329 delete $Carp::CarpInternal{'warnings'};
375 { Croaker("Unknown warnings category '$word'")}
430 { Croaker("Unknown warnings category '$word'")}
479 Croaker("Unknown warnings category '$category'")
485 Croaker("package '$category' not registered for warnings")
620 delete @warnings::{qw(NORMAL FATAL MESSAGE LEVEL)};
627 warnings - Perl pragma to control optional warnings
631 use warnings;
632 no warnings;
634 # Standard warnings are enabled by use v5.35 or above
637 use warnings "all";
638 no warnings "uninitialized";
641 use warnings qw(all -uninitialized);
643 use warnings::register;
644 if (warnings::enabled()) {
645 warnings::warn("some warning");
648 if (warnings::enabled("void")) {
649 warnings::warn("void", "some warning");
652 if (warnings::enabled($object)) {
653 warnings::warn($object, "some warning");
656 warnings::warnif("some warning");
657 warnings::warnif("void", "some warning");
658 warnings::warnif($object, "some warning");
662 The C<warnings> pragma gives control over which warnings are enabled in
674 By default, optional warnings are disabled, so any legacy code that
675 doesn't attempt to control the warnings will work unchanged.
677 All warnings are enabled in a block by either of these:
679 use warnings;
680 use warnings 'all';
682 Similarly all warnings are disabled in a block by either of these:
684 no warnings;
685 no warnings 'all';
689 use warnings;
692 no warnings;
697 The code in the enclosing block has warnings enabled, but the inner
702 All warnings are enabled automatically within the scope of
707 Before the introduction of lexical warnings, Perl had two classes of
708 warnings: mandatory and optional.
717 With the introduction of lexical warnings, mandatory warnings now become
718 I<default> warnings. The difference is that although the previously
719 mandatory warnings are still enabled by default, they can then be
725 no warnings;
729 disable/enable default warnings. They are still mandatory in this case.
731 =head2 "Negative warnings"
734 C<import()> method both positively and negatively. Negative warnings
735 are those with a C<-> sign prepended to their names; positive warnings
736 are anything else. This lets you turn on some warnings and turn off
738 bunch of warnings but want to tweak them a bit in some block, you can
742 use warnings qw(uninitialized -redefine);
749 use warnings qw(uninitialized);
750 no warnings qw(redefine);
758 use warnings qw(all -experimental experimental::somefeature);
762 use warnings 'all';
763 no warnings 'experimental';
764 use warnings 'experimental::somefeature';
767 the corresponding warnings are not printed anymore.
770 It is still possible to request turning on or off these warnings,
776 line to enable warnings is that it is all or nothing. Take the typical
780 end up enabling warnings in pieces of code that you haven't written.
783 fundamentally flawed. For a start, say you want to disable warnings in
795 The problem is that Perl has both compile-time and run-time warnings. To
796 disable compile-time warnings you need to rewrite the code like this:
828 Lexical warnings get around these limitations by allowing finer control
829 over where warnings can or can't be tripped.
834 warnings are (or aren't) produced:
841 This is the existing flag. If the lexical warnings pragma is B<not>
843 will enable warnings everywhere. See L</Backward Compatibility> for
844 details of how this flag interacts with lexical warnings.
849 If the B<-W> flag is used on the command line, it will enable all warnings
850 throughout the program regardless of whether warnings were disabled
851 locally using C<no warnings> or C<$^W =0>.
859 Does the exact opposite to the B<-W> flag, i.e. it disables all warnings.
866 introduction of lexically scoped warnings, or have code that uses both
867 lexical warnings and C<$^W>, this section will describe how they interact.
876 control warnings is used and neither C<$^W> nor the C<warnings> pragma
877 are used, then default warnings will be enabled and optional warnings
879 This means that legacy code that doesn't attempt to control the warnings
892 disable/enable default warnings.
896 If a piece of code is under the control of the C<warnings> pragma,
902 The only way to override a lexical warnings setting is with the B<-W>
908 the C<warnings> pragma to control the warning behavior of $^W-type
914 A hierarchy of "categories" have been defined to allow groups of warnings
1081 use warnings qw(void redefine);
1082 no warnings qw(io syntax untie);
1085 C<warnings> pragma in a given scope the cumulative effect is additive.
1087 use warnings qw(void); # only "void" warnings enabled
1089 use warnings qw(io); # only "void" & "io" warnings enabled
1091 no warnings qw(void); # only "io" warnings enabled
1096 Note: Before Perl 5.8.0, the lexical warnings category "deprecated" was a
1100 Note: Before 5.21.0, the "missing" lexical warnings category was
1108 warnings in those categories into fatal errors in that lexical scope.
1110 B<NOTE:> FATAL warnings should be used with care, particularly
1113 Libraries using L<warnings::warn|/FUNCTIONS> for custom warning categories
1114 generally don't expect L<warnings::warn|/FUNCTIONS> to be fatal and can wind up
1116 warnings, such unanticipated exceptions could also expose memory leak bugs.
1119 fatalized warnings. For a summary of resolved and unresolved problems as
1123 While some developers find fatalizing some warnings to be a useful
1130 a warnings subset that the module's authors believe is relatively safe to
1133 B<NOTE:> Users of FATAL warnings, especially those using
1136 commitments to not introduce new warnings or warnings categories in the
1140 using FATAL warnings break due to the introduction of a new warning we will
1141 NOT consider it an incompatible change. Users of FATAL warnings should
1143 any new warnings and should pay particular attention to the fine print of
1147 and spirit. Use of such features in combination with FATAL warnings is
1150 The following documentation describes how to use FATAL warnings but the
1159 use warnings;
1164 use warnings FATAL => qw(void);
1177 The scope where C<length> is used has escalated the C<void> warnings
1185 no warnings qw(void);
1186 no warnings FATAL => qw(void);
1190 example, the code below will promote all warnings into fatal errors,
1193 use warnings FATAL => 'all', NONFATAL => 'syntax';
1195 As of Perl 5.20, instead of C<< use warnings FATAL => 'all'; >> you can
1199 use warnings 'FATAL'; # short form of "use warnings FATAL => 'all';"
1202 using C<< use warnings FATAL => 'all'; >>.
1205 5.20, you must use C<< use warnings FATAL => 'all'; >> instead. (In
1207 C<< use warnings 'FATAL'; >>, C<< use warnings 'NONFATAL'; >> and
1208 C<< no warnings 'FATAL'; >> was unspecified; they did not behave as if
1214 The C<warnings> pragma provides a number of functions that are useful for
1216 warning to a calling module that has enabled warnings via the C<warnings>
1223 use warnings::register;
1228 warnings::warn("changing relative path to /var/abc")
1229 if warnings::enabled();
1236 The call to C<warnings::register> will create a new warnings category
1241 enabled them with the C<warnings> pragma as below - note that a plain
1242 C<use warnings> enables even warnings that have not yet been registered.
1244 use warnings;
1252 # no warnings 'MyMod::Abc'; # error, unknown category before
1255 no warnings 'MyMod::Abc'; # ok after the module is loaded
1259 It is also possible to test whether the pre-defined warnings categories are
1260 set in the calling module with the C<warnings::enabled> function. Consider
1266 if (warnings::enabled("deprecated")) {
1267 warnings::warn("deprecated",
1279 "deprecated" warnings category enabled. Something like this, say.
1281 use warnings 'deprecated';
1286 Either the C<warnings::warn> or C<warnings::warnif> function should be
1287 used to actually display the warnings message. This is because they can
1288 make use of the feature that allows warnings to be escalated into fatal
1292 use warnings FATAL => 'MyMod::Abc';
1296 the C<warnings::warnif> function will detect this and die after
1299 The three warnings functions, C<warnings::warn>, C<warnings::warnif>
1300 and C<warnings::enabled> can optionally take an object reference in place
1302 of the object as the warnings category.
1308 no warnings;
1309 use warnings::register;
1322 if ($value % 2 && warnings::enabled($self))
1323 { warnings::warn($self, "Odd numbers are unsafe") }
1338 use warnings::register;
1350 The code below makes use of both modules, but it only enables warnings from
1355 use warnings 'Derived';
1370 warnings::register like this:
1373 use warnings::register qw(format precision);
1377 warnings::warnif('MyModule::format', '...');
1386 =item use warnings::register
1388 Creates a new warnings category with the same name as the package where
1391 =item warnings::enabled()
1393 Use the warnings category with the same name as the current package.
1395 Return TRUE if that warnings category is enabled in the calling module.
1398 =item warnings::enabled($category)
1400 Return TRUE if the warnings category, C<$category>, is enabled in the
1404 =item warnings::enabled($object)
1407 warnings category.
1409 Return TRUE if that warnings category is enabled in the first scope
1413 =item warnings::enabled_at_level($category, $level)
1415 Like C<warnings::enabled>, but $level specifies the exact call frame, 0
1418 =item warnings::fatal_enabled()
1420 Return TRUE if the warnings category with the same name as the current
1424 =item warnings::fatal_enabled($category)
1426 Return TRUE if the warnings category C<$category> has been set to FATAL in
1430 =item warnings::fatal_enabled($object)
1433 warnings category.
1435 Return TRUE if that warnings category has been set to FATAL in the first
1439 =item warnings::fatal_enabled_at_level($category, $level)
1441 Like C<warnings::fatal_enabled>, but $level specifies the exact call frame,
1444 =item warnings::warn($message)
1448 Use the warnings category with the same name as the current package.
1450 If that warnings category has been set to "FATAL" in the calling module
1453 =item warnings::warn($category, $message)
1457 If the warnings category, C<$category>, has been set to "FATAL" in the
1460 =item warnings::warn($object, $message)
1465 warnings category.
1467 If that warnings category has been set to "FATAL" in the scope where C<$object>
1470 =item warnings::warn_at_level($category, $level, $message)
1472 Like C<warnings::warn>, but $level specifies the exact call frame,
1475 =item warnings::warnif($message)
1479 if (warnings::enabled())
1480 { warnings::warn($message) }
1482 =item warnings::warnif($category, $message)
1486 if (warnings::enabled($category))
1487 { warnings::warn($category, $message) }
1489 =item warnings::warnif($object, $message)
1493 if (warnings::enabled($object))
1494 { warnings::warn($object, $message) }
1496 =item warnings::warnif_at_level($category, $level, $message)
1498 Like C<warnings::warnif>, but $level specifies the exact call frame,
1501 =item warnings::register_categories(@names)
1504 use by the warnings::register pragma.