@node diagnostics, gettext, Xbase, Module List
@unnumbered Perl compiler pragma to force verbose warning diagnostics


@unnumberedsec NAME

diagnostics - Perl compiler pragma to force verbose warning diagnostics

splain - standalone program to do the same thing

@unnumberedsec SYNOPSIS

As a pragma:

@example
use diagnostics;
use diagnostics -verbose;
@end example

@example
enable  diagnostics;
disable diagnostics;
@end example

Aa a program:

@example
perl program 2>diag.out
splain [-v] [-p] diag.out
@end example

@unnumberedsec DESCRIPTION

@unnumberedsubsec The diagnostics Pragma

This module extends the terse diagnostics normally emitted by both the
perl compiler and the perl interpeter, augmenting them with the more
explicative and endearing descriptions found in @xref{(perl.info)perldiag,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

@example
use diagnostics;
@end example

at the start (or near the start) of your program.  (Note 
that this @emph{does} enable perl@'s -w flag.)  Your whole
compilation will then be subject(ed :-) to the enhanced diagnostics.
These still go out @strong{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 @code{no diagnostics} to turn them off at compiletime.
However, you may control there behaviour at runtime using the 
disable() and enable() methods to turn them off and on respectively.

The @strong{-verbose} flag first prints out the @xref{(perl.info)perldiag,Perldiag}, introduction before
any other diagnostics.  The $diagnostics::PRETTY variable can generate nicer
escape sequences for pagers.

@unnumberedsubsec The @emph{splain} Program

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

Output from @emph{splain} is directed to @strong{STDOUT}, unlike the pragma.

@unnumberedsec EXAMPLES

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

@example
use diagnostics;
print NOWHERE "nothing\n";
print STDERR "\n\tThis message should be unadorned.\n";
warn "\tThis is a user warning";
print "\nDIAGNOSTIC TESTER: Please enter a <CR> here: ";
my $a, $b = scalar <STDIN>;
print "\n";
print $x/$y;
@end example

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

@example
perl -w test.pl 2>test.out
./splain < test.out
@end example

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

@example
(perl -w test.pl >/dev/tty) >& test.out
./splain < test.out
@end example

Because you just moved the existing @strong{stdout} to somewhere else.

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

@example
exec 3>&1; perl -w test.pl 2>&1 1>&3 3>&- | splain 1>&2 3>&- 
@end example

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.

@example
use diagnostics; # checks entire compilation phase 
	print "\ntime for 1st bogus diags: SQUAWKINGS\n";
	print BOGUS1 @'nada@';
	print "done with 1st bogus\n";
@end example

@example
disable diagnostics; # only turns off runtime warnings
	print "\ntime for 2nd bogus: (squelched)\n";
	print BOGUS2 @'nada@';
	print "done with 2nd bogus\n";
@end example

@example
enable diagnostics; # turns back on runtime warnings
	print "\ntime for 3rd bogus: SQUAWKINGS\n";
	print BOGUS3 @'nada@';
	print "done with 3rd bogus\n";
@end example

@example
disable diagnostics;
	print "\ntime for 4th bogus: (squelched)\n";
	print BOGUS4 @'nada@';
	print "done with 4th bogus\n";
@end example

@unnumberedsec INTERNALS

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

If an extant $SIG@{__WARN__@} handler is discovered, it will continue
to be honored, but only after the diagnostics::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.

@example
BEGIN @{ $diagnostics::DEBUG = 1 @} 
@end example

@unnumberedsec BUGS

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

The @code{-pretty} directive is called too late to affect matters.
You have to to this instead, and @emph{before} you load the module.

@example
BEGIN @{ $diagnostics::PRETTY = 1 @} 
@end example

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 5.001e.  

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

@unnumberedsec AUTHOR

Tom Christiansen @file{<tchrist@@mox.perl.com>}, 25 June 1995.

