56
56
<li><a href="http://search.cpan.org">CPAN</a></li>
57
<li><a href="http://www.perl.org">Perl.org</a></li>
57
58
<li><a href="http://www.perl.com">Perl.com</a></li>
58
<li><a href="http://www.perl.org">Perl.org</a></li>
59
<li><a href="http://perlbuzz.com">Perl Buzz</a></li>
60
<li><a href="http://www.perlfoundation.org/perl5/index.cgi">Perl 5 Wiki</a></li>
61
<li><a href="http://jobs.perl.org">Perl Jobs</a></li>
59
62
<li><a href="http://www.pm.org">Perl Mongers</a></li>
60
63
<li><a href="http://www.perlmonks.org">Perl Monks</a></li>
61
64
<li><a href="http://planet.perl.org">Planet Perl</a></li>
76
79
<div id="centerContent">
77
80
<div id="contentHeader">
78
81
<div id="contentHeaderLeft"><a href="#" onClick="showLeft()">Show navigation</a></div>
79
<div id="contentHeaderCentre">-- Perl 5.8.8 documentation --</div>
82
<div id="contentHeaderCentre">-- Perl 5.10.0 documentation --</div>
80
83
<div id="contentHeaderRight"><a href="#" onClick="showRight()">Show toolbar</a></div>
82
85
<div id="breadCrumbs"><a href="index.html">Home</a> > <a href="index-language.html">Language reference</a> > perllexwarn</div>
83
86
<script language="JavaScript">fromSearch();</script>
84
<div id="contentBody"><div class="title_container"><div class="page_title">perllexwarn</div></div><ul><li><a href="#NAME-warning%2c-lexical-warnings-warning">NAME
87
<div id="contentBody"><div class="title_container"><div class="page_title">perllexwarn</div></div><ul><li><a href="#NAME">NAME
85
88
</a><li><a href="#DESCRIPTION">DESCRIPTION</a><ul><li><a href="#Default-Warnings-and-Optional-Warnings">Default Warnings and Optional Warnings</a><li><a href="#What's-wrong-with-*-w*-and-'%24%5eW'">What's wrong with <b>-w</b> and <code class="inline"><span class="i">$^W</span></code>
86
</a><li><a href="#Controlling-Warnings-from-the-Command-Line">Controlling Warnings from the Command Line</a><li><a href="#Backward-Compatibility">Backward Compatibility</a><li><a href="#Category-Hierarchy-warning%2c-categories">Category Hierarchy
87
</a><li><a href="#Fatal-Warnings-warning%2c-fatal">Fatal Warnings
88
</a><li><a href="#Reporting-Warnings-from-a-Module-warning%2c-reporting-warning%2c-registering">Reporting Warnings from a Module
89
</a></ul><li><a href="#TODO">TODO</a><li><a href="#SEE-ALSO">SEE ALSO</a><li><a href="#AUTHOR">AUTHOR</a></ul><a name="NAME-warning%2c-lexical-warnings-warning"></a><h1>NAME
89
</a><li><a href="#Controlling-Warnings-from-the-Command-Line">Controlling Warnings from the Command Line</a><li><a href="#Backward-Compatibility">Backward Compatibility</a><li><a href="#Category-Hierarchy">Category Hierarchy
90
</a><li><a href="#Fatal-Warnings">Fatal Warnings
91
</a><li><a href="#Reporting-Warnings-from-a-Module">Reporting Warnings from a Module
92
</a></ul><li><a href="#SEE-ALSO">SEE ALSO</a><li><a href="#AUTHOR">AUTHOR</a></ul><a name="NAME"></a><h1>NAME
91
94
<p>perllexwarn - Perl Lexical Warnings</p>
92
95
<a name="DESCRIPTION"></a><h1>DESCRIPTION</h1>
93
<p>The <code class="inline"><a class="l_k" href="functions/use.html">use</a> <a class="l_w" href="warnings.html">warnings</a></code>
94
pragma is a replacement for both the command line
95
flag <b>-w</b> and the equivalent Perl variable, <code class="inline"><span class="i">$^W</span></code>
96
<p>The <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">warnings</span></code>
97
pragma enables to control precisely what warnings are
98
to be enabled in which parts of a Perl program. It's a more flexible
99
alternative for both the command line flag <b>-w</b> and the equivalent Perl
100
variable, <code class="inline"><span class="i">$^W</span></code>
97
<p>The pragma works just like the existing "strict" pragma.
102
<p>This pragma works just like the <code class="inline"><span class="w">strict</span></code>
98
104
This means that the scope of the warning pragma is limited to the
99
105
enclosing block. It also means that the pragma setting will not
100
106
leak across files (via <code class="inline"><a class="l_k" href="functions/use.html">use</a></code>, <code class="inline"><a class="l_k" href="functions/require.html">require</a></code> or <code class="inline"><a class="l_k" href="functions/do.html">do</a></code>). This allows
103
109
<p>By default, optional warnings are disabled, so any legacy code that
104
110
doesn't attempt to control the warnings will work unchanged.</p>
105
111
<p>All warnings are enabled in a block by either of these:</p>
106
<pre class="verbatim"> <a class="l_k" href="functions/use.html">use</a> <a class="l_w" href="warnings.html">warnings</a><span class="sc">;</span>
107
<a class="l_k" href="functions/use.html">use</a> <a class="l_w" href="warnings.html">warnings</a> <span class="q">'all'</span><span class="sc">;</span></pre>
112
<pre class="verbatim"> <a class="l_k" href="functions/use.html">use</a> <span class="w">warnings</span><span class="sc">;</span>
113
<a class="l_k" href="functions/use.html">use</a> <span class="w">warnings</span> <span class="q">'all'</span><span class="sc">;</span></pre>
108
114
<p>Similarly all warnings are disabled in a block by either of these:</p>
109
<pre class="verbatim"> <a class="l_k" href="functions/no.html">no</a> <a class="l_w" href="warnings.html">warnings</a><span class="sc">;</span>
110
<a class="l_k" href="functions/no.html">no</a> <a class="l_w" href="warnings.html">warnings</a> <span class="q">'all'</span><span class="sc">;</span></pre>
115
<pre class="verbatim"> <a class="l_k" href="functions/no.html">no</a> <span class="w">warnings</span><span class="sc">;</span>
116
<a class="l_k" href="functions/no.html">no</a> <span class="w">warnings</span> <span class="q">'all'</span><span class="sc">;</span></pre>
111
117
<p>For example, consider the code below:</p>
112
<pre class="verbatim"> <a class="l_k" href="functions/use.html">use</a> <a class="l_w" href="warnings.html">warnings</a><span class="sc">;</span>
118
<pre class="verbatim"> <a class="l_k" href="functions/use.html">use</a> <span class="w">warnings</span><span class="sc">;</span>
113
119
<a class="l_k" href="functions/my.html">my</a> <span class="i">@a</span><span class="sc">;</span>
114
120
<span class="s">{</span>
115
<a class="l_k" href="functions/no.html">no</a> <a class="l_w" href="warnings.html">warnings</a><span class="sc">;</span>
121
<a class="l_k" href="functions/no.html">no</a> <span class="w">warnings</span><span class="sc">;</span>
116
122
<a class="l_k" href="functions/my.html">my</a> <span class="i">$b</span> = <span class="i">@a</span>[<span class="n">0</span>]<span class="sc">;</span>
117
123
<span class="s">}</span>
118
124
<a class="l_k" href="functions/my.html">my</a> <span class="i">$c</span> = <span class="i">@a</span>[<span class="n">0</span>]<span class="sc">;</span></pre>
199
205
<p>There are three Command Line flags that can be used to control when
200
206
warnings are (or aren't) produced:</p>
202
<li><a name="*-w*--w"></a><b><b>-w</b>
208
<li><a name="*-w*"></a><b><b>-w</b>
204
210
<p>This is the existing flag. If the lexical warnings pragma is <b>not</b>
205
211
used in any of you code, or any of the modules that you use, this flag
206
212
will enable warnings everywhere. See <a href="#Backward-Compatibility">"Backward Compatibility"</a> for
207
213
details of how this flag interacts with lexical warnings.</p>
209
<li><a name="*-W*--W"></a><b><b>-W</b>
215
<li><a name="*-W*"></a><b><b>-W</b>
211
217
<p>If the <b>-W</b> flag is used on the command line, it will enable all warnings
212
218
throughout the program regardless of whether warnings were disabled
213
locally using <code class="inline"><a class="l_k" href="functions/no.html">no</a> <a class="l_w" href="warnings.html">warnings</a></code>
219
locally using <code class="inline"><a class="l_k" href="functions/no.html">no</a> <span class="w">warnings</span></code>
214
220
or <code class="inline"><span class="i">$^W</span> =<span class="n">0</span></code>
215
221
. This includes all files that get
216
222
included via <code class="inline"><a class="l_k" href="functions/use.html">use</a></code>, <code class="inline"><a class="l_k" href="functions/require.html">require</a></code> or <code class="inline"><a class="l_k" href="functions/do.html">do</a></code>.
217
223
Think of it as the Perl equivalent of the "lint" command.</p>
219
<li><a name="*-X*--X"></a><b><b>-X</b>
225
<li><a name="*-X*"></a><b><b>-X</b>
221
227
<p>Does the exact opposite to the <b>-W</b> flag, i.e. it disables all warnings.</p>
265
273
<p>The combined effect of 3 & 4 is that it will allow code which uses
266
the <code class="inline"><a class="l_w" href="warnings.html">warnings</a></code> pragma to control the warning behavior of $^W-type
274
the <code class="inline"><span class="w">warnings</span></code>
275
pragma to control the warning behavior of $^W-type
267
276
code (using a <code class="inline"><a class="l_k" href="functions/local.html">local</a> <span class="i">$^W</span>=<span class="n">0</span></code>
268
277
) if it really wants to, but not vice-versa.</p>
269
<a name="Category-Hierarchy-warning%2c-categories"></a><h2>Category Hierarchy
278
<a name="Category-Hierarchy"></a><h2>Category Hierarchy
271
280
<p>A hierarchy of "categories" have been defined to allow groups of warnings
272
281
to be enabled/disabled in isolation.</p>
366
+- y2k</pre><p>Just like the "strict" pragma any of these categories can be combined</p>
367
<pre class="verbatim"> <a class="l_k" href="functions/use.html">use</a> <a class="l_w" href="warnings.html">warnings</a> <span class="q">qw(void redefine)</span><span class="sc">;</span>
368
<a class="l_k" href="functions/no.html">no</a> <a class="l_w" href="warnings.html">warnings</a> <span class="q">qw(io syntax untie)</span><span class="sc">;</span></pre>
373
+- void</pre><p>Just like the "strict" pragma any of these categories can be combined</p>
374
<pre class="verbatim"> <a class="l_k" href="functions/use.html">use</a> <span class="w">warnings</span> <span class="q">qw(void redefine)</span><span class="sc">;</span>
375
<a class="l_k" href="functions/no.html">no</a> <span class="w">warnings</span> <span class="q">qw(io syntax untie)</span><span class="sc">;</span></pre>
369
376
<p>Also like the "strict" pragma, if there is more than one instance of the
370
<code class="inline"><a class="l_w" href="warnings.html">warnings</a></code> pragma in a given scope the cumulative effect is additive. </p>
371
<pre class="verbatim"> <a class="l_k" href="functions/use.html">use</a> <a class="l_w" href="warnings.html">warnings</a> <span class="q">qw(void)</span><span class="sc">;</span> <span class="c"># only "void" warnings enabled</span>
373
<a class="l_k" href="functions/use.html">use</a> <a class="l_w" href="warnings.html">warnings</a> <span class="q">qw(io)</span><span class="sc">;</span> <span class="c"># only "void" & "io" warnings enabled</span>
375
<a class="l_k" href="functions/no.html">no</a> <a class="l_w" href="warnings.html">warnings</a> <span class="q">qw(void)</span><span class="sc">;</span> <span class="c"># only "io" warnings enabled</span></pre>
377
<code class="inline"><span class="w">warnings</span></code>
378
pragma in a given scope the cumulative effect is additive.</p>
379
<pre class="verbatim"> <a class="l_k" href="functions/use.html">use</a> <span class="w">warnings</span> <span class="q">qw(void)</span><span class="sc">;</span> <span class="c"># only "void" warnings enabled</span>
381
<a class="l_k" href="functions/use.html">use</a> <span class="w">warnings</span> <span class="q">qw(io)</span><span class="sc">;</span> <span class="c"># only "void" & "io" warnings enabled</span>
383
<a class="l_k" href="functions/no.html">no</a> <span class="w">warnings</span> <span class="q">qw(void)</span><span class="sc">;</span> <span class="c"># only "io" warnings enabled</span></pre>
376
384
<p>To determine which category a specific warning has been assigned to see
377
385
<a href="perldiag.html">perldiag</a>.</p>
378
386
<p>Note: In Perl 5.6.1, the lexical warnings category "deprecated" was a
379
387
sub-category of the "syntax" category. It is now a top-level category
380
388
in its own right.</p>
381
<a name="Fatal-Warnings-warning%2c-fatal"></a><h2>Fatal Warnings
389
<a name="Fatal-Warnings"></a><h2>Fatal Warnings
383
391
<p>The presence of the word "FATAL" in the category list will escalate any
384
392
warnings detected from the categories specified in the lexical scope
386
394
and <code class="inline"><a class="l_k" href="functions/join.html">join</a></code> can all produce a <code class="inline"><span class="q">"Useless use of xxx in void context"</span></code>
389
<pre class="verbatim"> <a class="l_k" href="functions/use.html">use</a> <a class="l_w" href="warnings.html">warnings</a><span class="sc">;</span></pre>
397
<pre class="verbatim"> <a class="l_k" href="functions/use.html">use</a> <span class="w">warnings</span><span class="sc">;</span></pre>
390
398
<pre class="verbatim"> <a class="l_k" href="functions/time.html">time</a><span class="sc">;</span></pre>
391
399
<pre class="verbatim"> <span class="s">{</span>
392
<a class="l_k" href="functions/use.html">use</a> <a class="l_w" href="warnings.html">warnings</a> FATAL <span class="cm">=></span> <span class="q">qw(void)</span><span class="sc">;</span>
400
<a class="l_k" href="functions/use.html">use</a> <span class="w">warnings</span> <span class="w">FATAL</span> <span class="cm">=></span> <span class="q">qw(void)</span><span class="sc">;</span>
393
401
<a class="l_k" href="functions/length.html">length</a> <span class="q">"abc"</span><span class="sc">;</span>
394
402
<span class="s">}</span></pre>
395
403
<pre class="verbatim"> <a class="l_k" href="functions/join.html">join</a> <span class="q">""</span><span class="cm">,</span> <span class="n">1</span><span class="cm">,</span><span class="n">2</span><span class="cm">,</span><span class="n">3</span><span class="sc">;</span></pre>
396
404
<pre class="verbatim"> <a class="l_k" href="functions/print.html">print</a> <span class="q">"done\n"</span><span class="sc">;</span></pre>
397
405
<p>When run it produces this output</p>
398
406
<pre class="verbatim"> Useless use of time in void context at fatal line 3.
399
Useless use of length in void context at fatal line 7. </pre><p>The scope where <code class="inline"><a class="l_k" href="functions/length.html">length</a></code> is used has escalated the <code class="inline">void</code>
407
Useless use of length in void context at fatal line 7.</pre><p>The scope where <code class="inline"><a class="l_k" href="functions/length.html">length</a></code> is used has escalated the <code class="inline"><span class="w">void</span></code>
401
409
category into a fatal error, so the program terminates immediately it
402
410
encounters the warning.</p>
403
411
<p>To explicitly turn off a "FATAL" warning you just disable the warning
404
412
it is associated with. So, for example, to disable the "void" warning
405
413
in the example above, either of these will do the trick:</p>
406
<pre class="verbatim"> <a class="l_k" href="functions/no.html">no</a> <a class="l_w" href="warnings.html">warnings</a> <span class="q">qw(void)</span><span class="sc">;</span>
407
<a class="l_k" href="functions/no.html">no</a> <a class="l_w" href="warnings.html">warnings</a> FATAL <span class="cm">=></span> <span class="q">qw(void)</span><span class="sc">;</span></pre>
414
<pre class="verbatim"> <a class="l_k" href="functions/no.html">no</a> <span class="w">warnings</span> <span class="q">qw(void)</span><span class="sc">;</span>
415
<a class="l_k" href="functions/no.html">no</a> <span class="w">warnings</span> <span class="w">FATAL</span> <span class="cm">=></span> <span class="q">qw(void)</span><span class="sc">;</span></pre>
408
416
<p>If you want to downgrade a warning that has been escalated into a fatal
409
417
error back to a normal warning, you can use the "NONFATAL" keyword. For
410
418
example, the code below will promote all warnings into fatal errors,
411
419
except for those in the "syntax" category.</p>
412
<pre class="verbatim"> <a class="l_k" href="functions/use.html">use</a> <a class="l_w" href="warnings.html">warnings</a> FATAL <span class="cm">=></span> <span class="q">'all'</span><span class="cm">,</span> NONFATAL <span class="cm">=></span> <span class="q">'syntax'</span><span class="sc">;</span></pre>
413
<a name="Reporting-Warnings-from-a-Module-warning%2c-reporting-warning%2c-registering"></a><h2>Reporting Warnings from a Module
420
<pre class="verbatim"> <a class="l_k" href="functions/use.html">use</a> <span class="w">warnings</span> <span class="w">FATAL</span> <span class="cm">=></span> <span class="q">'all'</span><span class="cm">,</span> <span class="w">NONFATAL</span> <span class="cm">=></span> <span class="q">'syntax'</span><span class="sc">;</span></pre>
421
<a name="Reporting-Warnings-from-a-Module"></a><h2>Reporting Warnings from a Module
415
<p>The <code class="inline"><a class="l_w" href="warnings.html">warnings</a></code> pragma provides a number of functions that are useful for
423
<p>The <code class="inline"><span class="w">warnings</span></code>
424
pragma provides a number of functions that are useful for
416
425
module authors. These are used when you want to report a module-specific
417
warning to a calling module has enabled warnings via the <code class="inline"><a class="l_w" href="warnings.html">warnings</a></code>
426
warning to a calling module has enabled warnings via the <code class="inline"><span class="w">warnings</span></code>
419
<p>Consider the module <code class="inline">MyMod::Abc</code>
429
<p>Consider the module <code class="inline"><span class="w">MyMod::Abc</span></code>
421
431
<pre class="verbatim"><a name="package-MyMod::Abc"></a> package <span class="i">MyMod::Abc</span><span class="sc">;</span></pre>
422
<pre class="verbatim"> <a class="l_k" href="functions/use.html">use</a> <a class="l_w" href="warnings/register.html">warnings::register</a><span class="sc">;</span></pre>
432
<pre class="verbatim"> <a class="l_k" href="functions/use.html">use</a> <span class="w">warnings::register</span><span class="sc">;</span></pre>
423
433
<pre class="verbatim"><a name="open"></a> sub <span class="m">open</span> <span class="s">{</span>
424
434
<a class="l_k" href="functions/my.html">my</a> <span class="i">$path</span> = <a class="l_k" href="functions/shift.html">shift</a><span class="sc">;</span>
425
435
if <span class="s">(</span><span class="i">$path</span> !~ <span class="q">m#^/#</span><span class="s">)</span> <span class="s">{</span>
429
439
<span class="s">}</span>
430
440
<span class="s">}</span></pre>
431
441
<pre class="verbatim"> <span class="n">1</span><span class="sc">;</span></pre>
432
<p>The call to <code class="inline"><a class="l_w" href="warnings/register.html">warnings::register</a></code> will create a new warnings category
442
<p>The call to <code class="inline"><span class="w">warnings::register</span></code>
443
will create a new warnings category
433
444
called "MyMod::abc", i.e. the new category name matches the current
434
445
package name. The <code class="inline"><a class="l_k" href="functions/open.html">open</a></code> function in the module will display a warning
435
446
message if it gets given a relative path as a parameter. This warnings
436
will only be displayed if the code that uses <code class="inline">MyMod::Abc</code>
447
will only be displayed if the code that uses <code class="inline"><span class="w">MyMod::Abc</span></code>
438
enabled them with the <code class="inline"><a class="l_w" href="warnings.html">warnings</a></code> pragma like below.</p>
439
<pre class="verbatim"> <a class="l_k" href="functions/use.html">use</a> MyMod::Abc<span class="sc">;</span>
440
<a class="l_k" href="functions/use.html">use</a> <a class="l_w" href="warnings.html">warnings</a> <span class="q">'MyMod::Abc'</span><span class="sc">;</span>
449
enabled them with the <code class="inline"><span class="w">warnings</span></code>
450
pragma like below.</p>
451
<pre class="verbatim"> <a class="l_k" href="functions/use.html">use</a> <span class="w">MyMod::Abc</span><span class="sc">;</span>
452
<a class="l_k" href="functions/use.html">use</a> <span class="w">warnings</span> <span class="q">'MyMod::Abc'</span><span class="sc">;</span>
442
454
<span class="i">abc::open</span><span class="s">(</span><span class="q">"../fred.txt"</span><span class="s">)</span><span class="sc">;</span></pre>
443
455
<p>It is also possible to test whether the pre-defined warnings categories are
444
set in the calling module with the <code class="inline">warnings::enabled</code>
456
set in the calling module with the <code class="inline"><span class="w">warnings::enabled</span></code>
445
457
function. Consider
446
458
this snippet of code:</p>
447
459
<pre class="verbatim"><a name="package-MyMod::Abc"></a> package <span class="i">MyMod::Abc</span><span class="sc">;</span></pre>
455
467
1;</pre><p>The function <code class="inline"><a class="l_k" href="functions/open.html">open</a></code> has been deprecated, so code has been included to
456
468
display a warning message whenever the calling module has (at least) the
457
469
"deprecated" warnings category enabled. Something like this, say.</p>
458
<pre class="verbatim"> <a class="l_k" href="functions/use.html">use</a> <a class="l_w" href="warnings.html">warnings</a> <span class="q">'deprecated'</span><span class="sc">;</span>
459
<a class="l_k" href="functions/use.html">use</a> MyMod::Abc<span class="sc">;</span>
470
<pre class="verbatim"> <a class="l_k" href="functions/use.html">use</a> <span class="w">warnings</span> <span class="q">'deprecated'</span><span class="sc">;</span>
471
<a class="l_k" href="functions/use.html">use</a> <span class="w">MyMod::Abc</span><span class="sc">;</span>
461
473
<span class="i">MyMod::Abc::open</span><span class="s">(</span><span class="i">$filename</span><span class="s">)</span><span class="sc">;</span></pre>
462
<p>Either the <code class="inline">warnings::warn</code>
463
or <code class="inline">warnings::warnif</code>
474
<p>Either the <code class="inline"><span class="w">warnings::warn</span></code>
475
or <code class="inline"><span class="w">warnings::warnif</span></code>
464
476
function should be
465
477
used to actually display the warnings message. This is because they can
466
478
make use of the feature that allows warnings to be escalated into fatal
467
479
errors. So in this case</p>
468
<pre class="verbatim"> <a class="l_k" href="functions/use.html">use</a> MyMod::Abc<span class="sc">;</span>
469
<a class="l_k" href="functions/use.html">use</a> <a class="l_w" href="warnings.html">warnings</a> FATAL <span class="cm">=></span> <span class="q">'MyMod::Abc'</span><span class="sc">;</span>
480
<pre class="verbatim"> <a class="l_k" href="functions/use.html">use</a> <span class="w">MyMod::Abc</span><span class="sc">;</span>
481
<a class="l_k" href="functions/use.html">use</a> <span class="w">warnings</span> <span class="w">FATAL</span> <span class="cm">=></span> <span class="q">'MyMod::Abc'</span><span class="sc">;</span>
471
483
<span class="i">MyMod::Abc::open</span><span class="s">(</span><span class="q">'../fred.txt'</span><span class="s">)</span><span class="sc">;</span></pre>
472
<p>the <code class="inline">warnings::warnif</code>
484
<p>the <code class="inline"><span class="w">warnings::warnif</span></code>
473
485
function will detect this and die after
474
486
displaying the warning message.</p>
475
<p>The three warnings functions, <code class="inline">warnings::warn</code>
476
, <code class="inline">warnings::warnif</code>
487
<p>The three warnings functions, <code class="inline"><span class="w">warnings::warn</span></code>
488
, <code class="inline"><span class="w">warnings::warnif</span></code>
478
and <code class="inline">warnings::enabled</code>
490
and <code class="inline"><span class="w">warnings::enabled</span></code>
479
491
can optionally take an object reference in place
480
492
of a category name. In this case the functions will use the class name
481
493
of the object as the warnings category.</p>
482
494
<p>Consider this example:</p>
483
495
<pre class="verbatim"><a name="package-Original"></a> package <span class="i">Original</span><span class="sc">;</span></pre>
484
<pre class="verbatim"> <a class="l_k" href="functions/no.html">no</a> <a class="l_w" href="warnings.html">warnings</a><span class="sc">;</span>
485
<a class="l_k" href="functions/use.html">use</a> <a class="l_w" href="warnings/register.html">warnings::register</a><span class="sc">;</span></pre>
496
<pre class="verbatim"> <a class="l_k" href="functions/no.html">no</a> <span class="w">warnings</span><span class="sc">;</span>
497
<a class="l_k" href="functions/use.html">use</a> <span class="w">warnings::register</span><span class="sc">;</span></pre>
486
498
<pre class="verbatim"><a name="new"></a> sub <span class="m">new</span>
487
499
<span class="s">{</span>
488
500
<a class="l_k" href="functions/my.html">my</a> <span class="i">$class</span> = <a class="l_k" href="functions/shift.html">shift</a><span class="sc">;</span>
502
514
<span class="s">}</span></pre>
503
515
<pre class="verbatim"> <span class="n">1</span><span class="sc">;</span></pre>
504
516
<pre class="verbatim"><a name="package-Derived"></a> package <span class="i">Derived</span><span class="sc">;</span></pre>
505
<pre class="verbatim"> <a class="l_k" href="functions/use.html">use</a> <a class="l_w" href="warnings/register.html">warnings::register</a><span class="sc">;</span>
506
<a class="l_k" href="functions/use.html">use</a> Original<span class="sc">;</span>
517
<pre class="verbatim"> <a class="l_k" href="functions/use.html">use</a> <span class="w">warnings::register</span><span class="sc">;</span>
518
<a class="l_k" href="functions/use.html">use</a> <span class="w">Original</span><span class="sc">;</span>
507
519
<a class="l_k" href="functions/our.html">our</a> <span class="i">@ISA</span> = <span class="q">qw( Original )</span><span class="sc">;</span>
508
520
<a name="new"></a> sub <span class="m">new</span>
509
521
<span class="s">{</span>
512
524
<span class="s">}</span></pre>
513
525
<pre class="verbatim"> <span class="n">1</span><span class="sc">;</span></pre>
514
526
<p>The code below makes use of both modules, but it only enables warnings from
515
<code class="inline">Derived</code>
527
<code class="inline"><span class="w">Derived</span></code>
517
<pre class="verbatim"> <a class="l_k" href="functions/use.html">use</a> Original<span class="sc">;</span>
518
<a class="l_k" href="functions/use.html">use</a> Derived<span class="sc">;</span>
519
<a class="l_k" href="functions/use.html">use</a> <a class="l_w" href="warnings.html">warnings</a> <span class="q">'Derived'</span><span class="sc">;</span>
520
<a class="l_k" href="functions/my.html">my</a> <span class="i">$a</span> = new Original<span class="sc">;</span>
529
<pre class="verbatim"> <a class="l_k" href="functions/use.html">use</a> <span class="w">Original</span><span class="sc">;</span>
530
<a class="l_k" href="functions/use.html">use</a> <span class="w">Derived</span><span class="sc">;</span>
531
<a class="l_k" href="functions/use.html">use</a> <span class="w">warnings</span> <span class="q">'Derived'</span><span class="sc">;</span>
532
<a class="l_k" href="functions/my.html">my</a> <span class="i">$a</span> = <span class="w">Original</span><span class="w">->new</span><span class="s">(</span><span class="s">)</span><span class="sc">;</span>
521
533
<span class="i">$a</span><span class="i">->doit</span><span class="s">(</span><span class="n">1</span><span class="s">)</span><span class="sc">;</span>
522
<a class="l_k" href="functions/my.html">my</a> <span class="i">$b</span> = new Derived<span class="sc">;</span>
534
<a class="l_k" href="functions/my.html">my</a> <span class="i">$b</span> = <span class="w">Derived</span><span class="w">->new</span><span class="s">(</span><span class="s">)</span><span class="sc">;</span>
523
535
<span class="i">$a</span><span class="i">->doit</span><span class="s">(</span><span class="n">1</span><span class="s">)</span><span class="sc">;</span></pre>
524
<p>When this code is run only the <code class="inline">Derived</code>
536
<p>When this code is run only the <code class="inline"><span class="w">Derived</span></code>
525
537
object, <code class="inline"><span class="i">$b</span></code>
528
<pre class="verbatim"> Odd numbers are unsafe at main.pl line <span class="n">7</span></pre>
540
<pre class="verbatim"> <span class="w">Odd</span> <span class="w">numbers</span> <span class="w">are</span> <span class="w">unsafe</span> <span class="w">at</span> <span class="w">main</span>.<span class="w">pl</span> <span class="w">line</span> <span class="n">7</span></pre>
529
541
<p>Notice also that the warning is reported at the line where the object is first
531
<a name="TODO"></a><h1>TODO</h1>
532
<pre class="verbatim"> perl5db.pl
533
The debugger saves and restores C<$^W> at runtime. I haven't checked
534
whether the debugger will still work with the lexical warnings
535
patch applied.</pre><pre class="verbatim"> <a class="l_w" href="diagnostics.html">diagnostics</a>.pm
536
I *think* I've got <a class="l_w" href="diagnostics.html">diagnostics</a> to work with the lexical <a class="l_w" href="warnings.html">warnings</a>
537
patch<span class="cm">,</span> but there were design decisions made in <a class="l_w" href="diagnostics.html">diagnostics</a> to work
538
around the limitations of C<span class="q"><$^W></span>. Now that those limitations are gone<span class="cm">,</span>
539
the module should be revisited.</pre>
540
<pre class="verbatim"> document calling the warnings::* functions from XS</pre>
541
543
<a name="SEE-ALSO"></a><h1>SEE ALSO</h1>
542
544
<p><a href="warnings.html">warnings</a>, <a href="perldiag.html">perldiag</a>.</p>
543
545
<a name="AUTHOR"></a><h1>AUTHOR</h1>