2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml">
5 <title>splain - produce verbose warning diagnostics
</title>
6 <meta http-equiv=
"content-type" content=
"text/html; charset=utf-8" />
7 <link rev=
"made" href=
"mailto:" />
10 <body style=
"background-color: white">
11 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
12 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
13 <big><strong><span class=
"block"> splain - produce verbose warning diagnostics
</span></strong></big>
17 <p><a name=
"__index__"></a></p>
22 <li><a href=
"#name">NAME
</a></li>
23 <li><a href=
"#synopsis">SYNOPSIS
</a></li>
24 <li><a href=
"#description">DESCRIPTION
</a></li>
27 <li><a href=
"#the_diagnostics_pragma">The
<code>diagnostics
</code> Pragma
</a></li>
28 <li><a href=
"#the_splain_program">The
<em>splain
</em> Program
</a></li>
31 <li><a href=
"#examples">EXAMPLES
</a></li>
32 <li><a href=
"#internals">INTERNALS
</a></li>
33 <li><a href=
"#bugs">BUGS
</a></li>
34 <li><a href=
"#author">AUTHOR
</a></li>
41 <h1><a name=
"name">NAME
</a></h1>
42 <p>diagnostics, splain - produce verbose warning diagnostics
</p>
46 <h1><a name=
"synopsis">SYNOPSIS
</a></h1>
47 <p>Using the
<code>diagnostics
</code> pragma:
</p>
50 use diagnostics -verbose;
</pre>
53 disable diagnostics;
</pre>
54 <p>Using the
<code>splain
</code> standalone filter program:
</p>
56 perl program
2>diag.out
57 splain [-v] [-p] diag.out
</pre>
58 <p>Using diagnostics to get stack traces from a misbehaving script:
</p>
60 perl -Mdiagnostics=-traceonly my_script.pl
</pre>
64 <h1><a name=
"description">DESCRIPTION
</a></h1>
67 <h2><a name=
"the_diagnostics_pragma">The
<code>diagnostics
</code> Pragma
</a></h2>
68 <p>This module extends the terse diagnostics normally emitted by both the
69 perl compiler and the perl interpreter (from running perl with a -w
70 switch or
<code>use warnings
</code>), augmenting them with the more
71 explicative and endearing descriptions found in
<a href=
"file://C|\msysgit\mingw\html/pod/perldiag.html">the perldiag manpage
</a>. Like the
72 other pragmata, it affects the compilation phase of your program rather
73 than merely the execution phase.
</p>
74 <p>To use in your program as a pragma, merely invoke
</p>
76 use diagnostics;
</pre>
77 <p>at the start (or near the start) of your program. (Note
78 that this
<em>does
</em> enable perl's
<strong>-w
</strong> flag.) Your whole
79 compilation will then be subject(ed :-) to the enhanced diagnostics.
80 These still go out
<strong>STDERR
</strong>.
</p>
81 <p>Due to the interaction between runtime and compiletime issues,
82 and because it's probably not a very good idea anyway,
83 you may not use
<code>no diagnostics
</code> to turn them off at compiletime.
84 However, you may control their behaviour at runtime using the
85 <code>disable()
</code> and
<code>enable()
</code> methods to turn them off and on respectively.
</p>
86 <p>The
<strong>-verbose
</strong> flag first prints out the
<a href=
"file://C|\msysgit\mingw\html/pod/perldiag.html">the perldiag manpage
</a> introduction before
87 any other diagnostics. The $diagnostics::PRETTY variable can generate nicer
88 escape sequences for pagers.
</p>
89 <p>Warnings dispatched from perl itself (or more accurately, those that match
90 descriptions found in
<a href=
"file://C|\msysgit\mingw\html/pod/perldiag.html">the perldiag manpage
</a>) are only displayed once (no duplicate
91 descriptions). User code generated warnings a la
<code>warn()
</code> are unaffected,
92 allowing duplicate user messages to be displayed.
</p>
93 <p>This module also adds a stack trace to the error message when perl dies.
94 This is useful for pinpointing what caused the death. The
<strong>-traceonly
</strong> (or
95 just
<strong>-t
</strong>) flag turns off the explanations of warning messages leaving just
96 the stack traces. So if your script is dieing, run it again with
</p>
98 perl -Mdiagnostics=-traceonly my_bad_script
</pre>
99 <p>to see the call stack at the time of death. By supplying the
<strong>-warntrace
</strong>
100 (or just
<strong>-w
</strong>) flag, any warnings emitted will also come with a stack
104 <h2><a name=
"the_splain_program">The
<em>splain
</em> Program
</a></h2>
105 <p>While apparently a whole nuther program,
<em>splain
</em> is actually nothing
106 more than a link to the (executable)
<em>diagnostics.pm
</em> module, as well as
107 a link to the
<em>diagnostics.pod
</em> documentation. The
<strong>-v
</strong> flag is like
108 the
<code>use diagnostics -verbose
</code> directive.
109 The
<strong>-p
</strong> flag is like the
110 $diagnostics::PRETTY variable. Since you're post-processing with
111 <em>splain
</em>, there's no sense in being able to
<code>enable()
</code> or
<code>disable()
</code> processing.
</p>
112 <p>Output from
<em>splain
</em> is directed to
<strong>STDOUT
</strong>, unlike the pragma.
</p>
116 <h1><a name=
"examples">EXAMPLES
</a></h1>
117 <p>The following file is certain to trigger a few errors at both
118 runtime and compiletime:
</p>
121 print NOWHERE
"nothing\n
";
122 print STDERR
"\n\tThis message should be unadorned.\n
";
123 warn
"\tThis is a user warning
";
124 print
"\nDIAGNOSTIC TESTER: Please enter a
<CR
> here:
";
125 my $a, $b = scalar
<STDIN
>;
126 print
"\n
";
128 <p>If you prefer to run your program first and look at its problem
129 afterwards, do this:
</p>
131 perl -w test.pl
2>test.out
132 ./splain
< test.out
</pre>
133 <p>Note that this is not in general possible in shells of more dubious heritage,
134 as the theoretical
</p>
136 (perl -w test.pl
>/dev/tty)
>& test.out
137 ./splain
< test.out
</pre>
138 <p>Because you just moved the existing
<strong>stdout
</strong> to somewhere else.
</p>
139 <p>If you don't want to modify your source code, but still have on-the-fly
140 warnings, do this:
</p>
142 exec
3>&1; perl -w test.pl
2>&1 1>&3 3>&- | splain
1>&2 3>&-
</pre>
144 <p>If you want to control warnings on the fly, do something like this.
145 Make sure you do the
<a href=
"file://C|\msysgit\mingw\html/pod/perlfunc.html#item_use"><code>use
</code></a> first, or you won't be able to get
146 at the
<code>enable()
</code> or
<code>disable()
</code> methods.
</p>
148 use diagnostics; # checks entire compilation phase
149 print
"\ntime for
1st bogus diags: SQUAWKINGS\n
";
151 print
"done with
1st bogus\n
";
</pre>
153 disable diagnostics; # only turns off runtime warnings
154 print
"\ntime for
2nd bogus: (squelched)\n
";
156 print
"done with
2nd bogus\n
";
</pre>
158 enable diagnostics; # turns back on runtime warnings
159 print
"\ntime for
3rd bogus: SQUAWKINGS\n
";
161 print
"done with
3rd bogus\n
";
</pre>
164 print
"\ntime for
4th bogus: (squelched)\n
";
166 print
"done with
4th bogus\n
";
</pre>
170 <h1><a name=
"internals">INTERNALS
</a></h1>
171 <p>Diagnostic messages derive from the
<em>perldiag.pod
</em> file when available at
172 runtime. Otherwise, they may be embedded in the file itself when the
173 splain package is built. See the
<em>Makefile
</em> for details.
</p>
174 <p>If an extant $SIG{__WARN__} handler is discovered, it will continue
175 to be honored, but only after the diagnostics::splainthis() function
176 (the module's $SIG{__WARN__} interceptor) has had its way with your
178 <p>There is a $diagnostics::DEBUG variable you may set if you're desperately
179 curious what sorts of things are being intercepted.
</p>
181 BEGIN { $diagnostics::DEBUG =
1 }
</pre>
185 <h1><a name=
"bugs">BUGS
</a></h1>
186 <p>Not being able to say ``no diagnostics'' is annoying, but may not be
188 <p>The
<code>-pretty
</code> directive is called too late to affect matters.
189 You have to do this instead, and
<em>before
</em> you load the module.
</p>
191 BEGIN { $diagnostics::PRETTY =
1 }
</pre>
192 <p>I could start up faster by delaying compilation until it should be
193 needed, but this gets a ``panic: top_level'' when using the pragma form
195 <p>While it's true that this documentation is somewhat subserious, if you use
196 a program named
<em>splain
</em>, you should expect a bit of whimsy.
</p>
200 <h1><a name=
"author">AUTHOR
</a></h1>
201 <p>Tom Christiansen
<<em><a href=
"mailto:tchrist@mox.perl.com">tchrist@mox.perl.com
</a></em>>,
25 June
1995.
</p>
202 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
203 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
204 <big><strong><span class=
"block"> splain - produce verbose warning diagnostics
</span></strong></big>