Codex

SPLAIN

Section: Perl Programmers Reference Guide (1)

Updated: 2016-01-15

Index?action=index Return to Main Contents


NAME

diagnostics, splain - produce verbose warning diagnostics

SYNOPSIS

Using the pragma:
Using the standalone filter program:

Using diagnostics to get stack traces from a misbehaving script:

DESCRIPTION

The diagnostics Pragma

This module extends the terse diagnostics normally emitted by both the perl compiler and the perl interpreter (from running perl with a -w switch or ), augmenting them with the more explicative and endearing descriptions found in perldiag. Like the other pragmata, it affects the compilation phase of your program rather than merely the execution phase.

To use in your program as a pragma, merely invoke

at the start (or near the start) of your program. (Note that this does enable perl's -w flag.) Your whole compilation will then be subject(ed :-) to the enhanced diagnostics. These still go out STDERR.

Due to the interaction between runtime and compiletime issues, and because it's probably not a very good idea anyway, you may not use to turn them off at compiletime. However, you may control their behaviour at runtime using the disable() and enable() methods to turn them off and on respectively.
The -verbose flag first prints out the perldiag introduction before any other diagnostics. The variable can generate nicer escape sequences for pagers.

Warnings dispatched from perl itself (or more accurately, those that match descriptions found in perldiag) are only displayed once (no duplicate descriptions). User code generated warnings a la warn() are unaffected, allowing duplicate user messages to be displayed.

This module also adds a stack trace to the error message when perl dies. This is useful for pinpointing what caused the death. The -traceonly (or just -t) flag turns off the explanations of warning messages leaving just the stack traces. So if your script is dieing, run it again with

to see the call stack at the time of death. By supplying the -warntrace (or just -w) flag, any warnings emitted will also come with a stack trace.

The splain Program

While apparently a whole nuther program, splain is actually nothing more than a link to the (executable) diagnostics.pm module, as well as a link to the diagnostics.pod documentation. The -v flag is like the directive. The -p flag is like the variable. Since you're post-processing with splain, there's no sense in being able to enable() or disable() processing.

Output from splain is directed to STDOUT, unlike the pragma.

EXAMPLES

The following file is certain to trigger a few errors at both runtime and compiletime:

If you prefer to run your program first and look at its problem afterwards, do this:

Note that this is not in general possible in shells of more dubious heritage, as the theoretical

Because you just moved the existing stdout to somewhere else.

If you don't want to modify your source code, but still have on-the-fly warnings, do this:

Nifty, eh?

If you want to control warnings on the fly, do something like this. Make sure you do the first, or you won't be able to get at the enable() or disable() methods.

INTERNALS

Diagnostic messages derive from the perldiag.pod file when available at runtime. Otherwise, they may be embedded in the file itself when the splain package is built. See the Makefile for details.

If an extant {__WARN__} handler is discovered, it will continue to be honored, but only after the diagnostics::splainthis() function (the module's {__WARN__} interceptor) has had its way with your warnings.
There is a variable you may set if you're desperately curious what sorts of things are being intercepted.

BUGS

Not being able to say ``no diagnostics'' is annoying, but may not be insurmountable.

The directive is called too late to affect matters. You have to do this instead, and before you load the module.

I could start up faster by delaying compilation until it should be needed, but this gets a ``panic: top_level'' when using the pragma form in Perl 5.001e.

While it's true that this documentation is somewhat subserious, if you use a program named splain, you should expect a bit of whimsy.

AUTHOR

Tom Christiansen <[email protected]>, 25 June 1995.


Index

NAME

SYNOPSIS

DESCRIPTION

The diagnostics Pragma

The splain Program

EXAMPLES

INTERNALS

BUGS

AUTHOR


More Man Pages