Cari di Perl 
    Perl User Manual
Daftar Isi
(Sebelumnya) Print or Check SHA ChecksumsCompiler to convert Perl XS co ... (Berikutnya)
Utilities

Produce verbose warning diagnostics

Daftar Isi

NAME

diagnostics, splain - produce verbose warning diagnostics

SYNOPSIS

Using the diagnostics pragma:

  1. use diagnostics;
  2. use diagnostics -verbose;
  3. enable diagnostics;
  4. disable diagnostics;

Using the splain standalone filter program:

  1. perl program 2>diag.out
  2. splain [-v] [-p] diag.out

Using diagnostics to get stack traces from a misbehaving script:

  1. perl -Mdiagnostics=-traceonly my_script.pl

DESCRIPTION

The diagnostics Pragma

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

To use in your program as a pragma, merely invoke

  1. use diagnostics;

at the start (or near the start) of your program. (Note that this does enable perl's -w flag.) Your wholecompilation 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 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 introduction beforeany other diagnostics. The $diagnostics::PRETTY variable can generate nicerescape sequences for pagers.

Warnings dispatched from perl itself (or more accurately, those that matchdescriptions found in perldiag) are only displayed once (no duplicatedescriptions). 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 whatcaused the death. The -traceonly (orjust -t) flag turns off the explanations of warning messages leaving justthe stack traces. So if your script is dieing, run it again with

  1. perl -Mdiagnostics=-traceonly my_bad_script

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 stacktrace.

The splain Program

While apparently a whole nuther program, splain is actually nothingmore than a link to the (executable) diagnostics.pm module, as well asa link to the diagnostics.pod documentation. The -v flag is likethe use diagnostics -verbose directive.The -p flag is like the$diagnostics::PRETTY 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 bothruntime and compiletime:

  1. use diagnostics;
  2. print NOWHERE "nothing\n";
  3. print STDERR "\n\tThis message should be unadorned.\n";
  4. warn "\tThis is a user warning";
  5. print "\nDIAGNOSTIC TESTER: Please enter a <CR> here: ";
  6. my $a, $b = scalar <STDIN>;
  7. print "\n";
  8. print $x/$y;

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

  1. perl -w test.pl 2>test.out
  2. ./splain < test.out

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

  1. (perl -w test.pl >/dev/tty) >& test.out
  2. ./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-flywarnings, do this:

  1. 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 getat the enable() or disable() methods.

  1. use diagnostics; # checks entire compilation phase
  2. print "\ntime for 1st bogus diags: SQUAWKINGS\n";
  3. print BOGUS1 'nada';
  4. print "done with 1st bogus\n";
  5. disable diagnostics; # only turns off runtime warnings
  6. print "\ntime for 2nd bogus: (squelched)\n";
  7. print BOGUS2 'nada';
  8. print "done with 2nd bogus\n";
  9. enable diagnostics; # turns back on runtime warnings
  10. print "\ntime for 3rd bogus: SQUAWKINGS\n";
  11. print BOGUS3 'nada';
  12. print "done with 3rd bogus\n";
  13. disable diagnostics;
  14. print "\ntime for 4th bogus: (squelched)\n";
  15. print BOGUS4 'nada';
  16. print "done with 4th bogus\n";

INTERNALS

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

If an extant $SIG{__WARN__} handler is discovered, it will continueto be honored, but only after the diagnostics::splainthis() function (the module's $SIG{__WARN__} interceptor) has had its way with yourwarnings.

There is a $diagnostics::DEBUG variable you may set if you're desperatelycurious what sorts of things are being intercepted.

  1. BEGIN { $diagnostics::DEBUG = 1 }

BUGS

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

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

  1. BEGIN { $diagnostics::PRETTY = 1 }

I could start up faster by delaying compilation until it should beneeded, but this gets a "panic: top_level" when using the pragma formin Perl 5.001e.

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

AUTHOR

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

 
Source : perldoc.perl.org - Official documentation for the Perl programming language
Site maintained by Jon Allen (JJ)     See the project page for more details
Documentation maintained by the Perl 5 Porters
(Sebelumnya) Print or Check SHA ChecksumsCompiler to convert Perl XS co ... (Berikutnya)