diagnostics(3)

NAME

diagnostics - Perl compiler pragma to force verbose warn
ing diagnostics

splain - standalone program to do the same thing

SYNOPSIS

As a pragma:
    use diagnostics;
    use diagnostics -verbose;
    enable  diagnostics;
    disable diagnostics;
Aa a program:
    perl program 2>diag.out
    splain [-v] [-p] diag.out

DESCRIPTION

The "diagnostics" Pragma

This module extends the terse diagnostics normally emitted
by both the perl compiler and the perl interpreter, aug
menting 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
use diagnostics;
at the start (or near the start) of your program. (Note
that this does enable perl's -w flag.) Your whole compi
lation will then be subject(ed :-) to the enhanced diag
nostics. 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 "no diagnostics" 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 introduc tion before any other diagnostics. The $diagnos
tics::PRETTY 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 ala warn() are unaffected, allowing
duplicate user messages to be displayed.
The splain Program
While apparently a whole nuther program, splain is actu
ally nothing more than a link to the (executable) diagnos_ tics.pm module, as well as a link to the diagnostics.pod documentation. The -v flag is like the "use diagnostics
-verbose" directive. The -p flag is like the $diagnos
tics::PRETTY variable. Since you're post-processing with
splain, there's no sense in being able to enable() or dis_ able() 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:
use diagnostics;
print NOWHERE "nothing0;
print STDERR "This message should be unadorned.0;
warn "This is a user warning";
print "0IAGNOSTIC TESTER: Please enter a <CR> here: ";
my $a, $b = scalar <STDIN>;
print "0;
print $x/$y;
If you prefer to run your program first and look at its
problem afterwards, do this:

perl -w test.pl 2>test.out
./splain < test.out
Note that this is not in general possible in shells of
more dubious heritage, as the theoretical

(perl -w test.pl >/dev/tty) >& test.out
./splain < test.out
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:

exec 3>&1; perl -w test.pl 2>&1 1>&3 3>&- | splain
1>&2 3>&
Nifty, eh?
If you want to control warnings on the fly, do something
like this. Make sure you do the "use" first, or you won't
be able to get at the enable() or disable() methods.

use diagnostics; # checks entire compilation phase
print "0ime for 1st bogus diags: SQUAWKINGS0;
print BOGUS1 'nada';
print "done with 1st bogus0;
disable diagnostics; # only turns off runtime warnings
print "0ime for 2nd bogus: (squelched)0;
print BOGUS2 'nada';
print "done with 2nd bogus0;
enable diagnostics; # turns back on runtime warnings
print "0ime for 3rd bogus: SQUAWKINGS0;
print BOGUS3 'nada';
print "done with 3rd bogus0;
disable diagnostics;
print "0ime for 4th bogus: (squelched)0;
print BOGUS4 'nada';
print "done with 4th bogus0;

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 $SIG{__WARN__} handler is discovered, it will
continue to be honored, but only after the diagnos_
tics::splainthis() function (the module's $SIG{__WARN__} interceptor) has had its way with your warnings.

There is a $diagnostics::DEBUG variable you may set if
you're desperately curious what sorts of things are being
intercepted.
BEGIN { $diagnostics::DEBUG = 1 }

BUGS

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

The "-pretty" directive is called too late to affect mat
ters. You have to do this instead, and before you load
the module.
BEGIN { $diagnostics::PRETTY = 1 }
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 subse
rious, if you use a program named splain, you should
expect a bit of whimsy.

AUTHOR

Tom Christiansen <tchrist@mox.perl.com>, 25 June 1995.
Copyright © 2010-2025 Platon Technologies, s.r.o.           Home | Man pages | tLDP | Documents | Utilities | About
Design by styleshout