1warnings(3pm) Perl Programmers Reference Guide warnings(3pm)
2
3
4
6 warnings - Perl pragma to control optional warnings
7
9 use warnings;
10 no warnings;
11
12 use warnings "all";
13 no warnings "all";
14
15 use warnings::register;
16 if (warnings::enabled()) {
17 warnings::warn("some warning");
18 }
19
20 if (warnings::enabled("void")) {
21 warnings::warn("void", "some warning");
22 }
23
24 if (warnings::enabled($object)) {
25 warnings::warn($object, "some warning");
26 }
27
28 warnings::warnif("some warning");
29 warnings::warnif("void", "some warning");
30 warnings::warnif($object, "some warning");
31
33 The "warnings" pragma is a replacement for the command line flag "-w",
34 but the pragma is limited to the enclosing block, while the flag is
35 global. See perllexwarn for more information and the list of built-in
36 warning categories.
37
38 If no import list is supplied, all possible warnings are either enabled
39 or disabled.
40
41 A number of functions are provided to assist module authors.
42
43 use warnings::register
44 Creates a new warnings category with the same name as the package
45 where the call to the pragma is used.
46
47 warnings::enabled()
48 Use the warnings category with the same name as the current
49 package.
50
51 Return TRUE if that warnings category is enabled in the calling
52 module. Otherwise returns FALSE.
53
54 warnings::enabled($category)
55 Return TRUE if the warnings category, $category, is enabled in the
56 calling module. Otherwise returns FALSE.
57
58 warnings::enabled($object)
59 Use the name of the class for the object reference, $object, as the
60 warnings category.
61
62 Return TRUE if that warnings category is enabled in the first scope
63 where the object is used. Otherwise returns FALSE.
64
65 warnings::fatal_enabled()
66 Return TRUE if the warnings category with the same name as the
67 current package has been set to FATAL in the calling module.
68 Otherwise returns FALSE.
69
70 warnings::fatal_enabled($category)
71 Return TRUE if the warnings category $category has been set to
72 FATAL in the calling module. Otherwise returns FALSE.
73
74 warnings::fatal_enabled($object)
75 Use the name of the class for the object reference, $object, as the
76 warnings category.
77
78 Return TRUE if that warnings category has been set to FATAL in the
79 first scope where the object is used. Otherwise returns FALSE.
80
81 warnings::warn($message)
82 Print $message to STDERR.
83
84 Use the warnings category with the same name as the current
85 package.
86
87 If that warnings category has been set to "FATAL" in the calling
88 module then die. Otherwise return.
89
90 warnings::warn($category, $message)
91 Print $message to STDERR.
92
93 If the warnings category, $category, has been set to "FATAL" in the
94 calling module then die. Otherwise return.
95
96 warnings::warn($object, $message)
97 Print $message to STDERR.
98
99 Use the name of the class for the object reference, $object, as the
100 warnings category.
101
102 If that warnings category has been set to "FATAL" in the scope
103 where $object is first used then die. Otherwise return.
104
105 warnings::warnif($message)
106 Equivalent to:
107
108 if (warnings::enabled())
109 { warnings::warn($message) }
110
111 warnings::warnif($category, $message)
112 Equivalent to:
113
114 if (warnings::enabled($category))
115 { warnings::warn($category, $message) }
116
117 warnings::warnif($object, $message)
118 Equivalent to:
119
120 if (warnings::enabled($object))
121 { warnings::warn($object, $message) }
122
123 warnings::register_categories(@names)
124 This registers warning categories for the given names and is
125 primarily for use by the warnings::register pragma, for which see
126 perllexwarn.
127
128 See "Pragmatic Modules" in perlmodlib and perllexwarn.
129
130
131
132perl v5.16.3 2013-03-04 warnings(3pm)