1N/Adiagnostics, splain - produce verbose warning diagnostics 1N/AUsing the C<diagnostics> pragma: 1N/A use diagnostics -verbose; 1N/A disable diagnostics; 1N/AUsing the C<splain> standalone filter program: 1N/A perl program 2>diag.out 1N/A splain [-v] [-p] diag.out 1N/A=head2 The C<diagnostics> Pragma 1N/AThis module extends the terse diagnostics normally emitted by both the 1N/Aperl compiler and the perl interpreter, augmenting them with the more 1N/Aexplicative and endearing descriptions found in L<perldiag>. Like the 1N/Aother pragmata, it affects the compilation phase of your program rather 1N/Athan merely the execution phase. 1N/ATo use in your program as a pragma, merely invoke 1N/Aat the start (or near the start) of your program. (Note 1N/Athat this I<does> enable perl's B<-w> flag.) Your whole 1N/Acompilation will then be subject(ed :-) to the enhanced diagnostics. 1N/AThese still go out B<STDERR>. 1N/ADue to the interaction between runtime and compiletime issues, 1N/Aand because it's probably not a very good idea anyway, 1N/Ayou may not use C<no diagnostics> to turn them off at compiletime. 1N/AHowever, you may control their behaviour at runtime using the 1N/Adisable() and enable() methods to turn them off and on respectively. 1N/AThe B<-verbose> flag first prints out the L<perldiag> introduction before 1N/Aany other diagnostics. The $diagnostics::PRETTY variable can generate nicer 1N/Aescape sequences for pagers. 1N/AWarnings dispatched from perl itself (or more accurately, those that match 1N/Adescriptions found in L<perldiag>) are only displayed once (no duplicate 1N/Adescriptions). User code generated warnings a la warn() are unaffected, 1N/Aallowing duplicate user messages to be displayed. 1N/A=head2 The I<splain> Program 1N/AWhile apparently a whole nuther program, I<splain> is actually nothing 1N/Aa link to the F<diagnostics.pod> documentation. The B<-v> flag is like 1N/Athe C<use diagnostics -verbose> directive. 1N/AThe B<-p> flag is like the 1N/A$diagnostics::PRETTY variable. Since you're post-processing with 1N/AI<splain>, there's no sense in being able to enable() or disable() processing. 1N/AOutput from I<splain> is directed to B<STDOUT>, unlike the pragma. 1N/AThe following file is certain to trigger a few errors at both 1N/Aruntime and compiletime: 1N/A print NOWHERE "nothing\n"; 1N/A print STDERR "\n\tThis message should be unadorned.\n"; 1N/A warn "\tThis is a user warning"; 1N/A print "\nDIAGNOSTIC TESTER: Please enter a <CR> here: "; 1N/A my $a, $b = scalar <STDIN>; 1N/AIf you prefer to run your program first and look at its problem 1N/ANote that this is not in general possible in shells of more dubious heritage, 1N/ABecause you just moved the existing B<stdout> to somewhere else. 1N/AIf you don't want to modify your source code, but still have on-the-fly 1N/A exec 3>&1; perl -w test.pl 2>&1 1>&3 3>&- | splain 1>&2 3>&- 1N/AIf you want to control warnings on the fly, do something like this. 1N/AMake sure you do the C<use> first, or you won't be able to get 1N/Aat the enable() or disable() methods. 1N/A use diagnostics; # checks entire compilation phase 1N/A print "\ntime for 1st bogus diags: SQUAWKINGS\n"; 1N/A print BOGUS1 'nada'; 1N/A print "done with 1st bogus\n"; 1N/A disable diagnostics; # only turns off runtime warnings 1N/A print "\ntime for 2nd bogus: (squelched)\n"; 1N/A print BOGUS2 'nada'; 1N/A print "done with 2nd bogus\n"; 1N/A enable diagnostics; # turns back on runtime warnings 1N/A print "\ntime for 3rd bogus: SQUAWKINGS\n"; 1N/A print BOGUS3 'nada'; 1N/A print "done with 3rd bogus\n"; 1N/A disable diagnostics; 1N/A print "\ntime for 4th bogus: (squelched)\n"; 1N/A print BOGUS4 'nada'; 1N/A print "done with 4th bogus\n"; 1N/ADiagnostic messages derive from the F<perldiag.pod> file when available at 1N/Aruntime. Otherwise, they may be embedded in the file itself when the 1N/Asplain package is built. See the F<Makefile> for details. 1N/AIf an extant $SIG{__WARN__} handler is discovered, it will continue 1N/Ato be honored, but only after the diagnostics::splainthis() function 1N/A(the module's $SIG{__WARN__} interceptor) has had its way with your 1N/AThere is a $diagnostics::DEBUG variable you may set if you're desperately 1N/Acurious what sorts of things are being intercepted. 1N/A BEGIN { $diagnostics::DEBUG = 1 } 1N/ANot being able to say "no diagnostics" is annoying, but may not be 1N/AThe C<-pretty> directive is called too late to affect matters. 1N/AYou have to do this instead, and I<before> you load the module. 1N/A BEGIN { $diagnostics::PRETTY = 1 } 1N/AI could start up faster by delaying compilation until it should be 1N/Aneeded, but this gets a "panic: top_level" when using the pragma form 1N/AWhile it's true that this documentation is somewhat subserious, if you use 1N/Aa program named I<splain>, you should expect a bit of whimsy. 1N/ATom Christiansen <F<tchrist@mox.perl.com>>, 25 June 1995. 1N/A# handy for development testing of new warnings etc 1N/Aif ($^O
eq 'MacOS') {
1N/A # just updir one from each lib dir, we'll find it ... 1N/Amy $
WHOAMI =
ref bless [];
# nobody's business, prolly not even mine 1N/A or die "Usage: $0 [-v] [-p] [-f splainpod]";
1N/A warn "Happy happy podfile from real $PODFILE\n" if $
DEBUG;
1N/A /^
__END__\s*
# wish diag dbase were more accessible/; 1N/A die "couldn't find diagnostic data in $PODFILE @INC $0";
1N/A 'amp' =>
'&',
# ampersand 1N/A 'lt' =>
'<',
# left chevron, less-than 1N/A 'gt' =>
'>',
# right chevron, greater-than 1N/A 'quot' =>
'"',
# double quote 1N/A "Aacute" =>
"A\\*'",
# capital A, acute accent 1N/A 'amp' =>
'&',
# ampersand 1N/A 'lt' =>
'<',
# left chevron, less-than 1N/A 'gt' =>
'>',
# right chevron, greater-than 1N/A 'quot' =>
'"',
# double quote 1N/A "Aacute" =>
"\xC1" # capital A, acute accent 1N/A 'amp' =>
'&',
# ampersand 1N/A 'lt' =>
'<',
# left chevron, less-than 1N/A 'gt' =>
'>',
# right chevron, greater-than 1N/A 'quot' =>
'"',
# double quote 1N/A "Aacute" =>
"A" # capital A, acute accent 1N/A #local \$^W = 0; # recursive warnings we do NOT need! 1N/A sub noop {
return $_[
0] }
# spensive for a noop 1N/A # strip formatting directives from =item line 1N/A for my $i (
0..$
#toks){ 1N/A $
toks[$i] = $i == $
#toks ? '.*' : '.*?'; 1N/A }
elsif( $
toks[$i] =~
'%.(\d+)s' ){
1N/A " s{^$lhs}\n {\Q$header\E}s\n\t&& return 1;\n";
1N/A " m{^\Q$header\E} && return 1;\n";
1N/A print STDERR "$WHOAMI: Duplicate entry: \"$header\"\n" 1N/A die "No diagnostics?" unless %
msg;
1N/A # Apply patterns in order of decreasing sum of lengths of fixed parts 1N/A # Seems the best way of hitting the right one. 1N/A $^W =
1;
# yup, clobbered the global variable; 1N/A # tough, if you want diags, you want diags. 1N/A print STDERR "$0: I'm afraid it's too late for prettiness.\n";
1N/A warn "Unknown flag: $_";
1N/A # See if we are coming from anywhere within an eval. If so we don't 1N/A # want to explain the exception because it's going to get caught. 1N/A # We don't want to unset these if we're coming from an eval because 1N/A # then we've turned off diagnostics. 1N/A # Switch off our die/warn handlers so we don't wind up in our own 1N/A # Have carp skip over death_trap() when showing the stack trace. 1N/A confess "Uncaught exception from user code:\n\t$exception";
1N/A # up we go; where we stop, nobody knows, but i think we die now 1N/A # but i'm deeply afraid of the &$olddie guy reraising and us getting 1N/A # into an indirect recursion loop 1N/A ### &finish_compilation unless %msg; 1N/A # return unless defined; 1N/A # get rid of the where-are-we-in-input part 1N/A # Discard 1st " at <file> line <no>" and all text beyond 1N/A # but be aware of messsages containing " at this-or-that" 1N/A for my $i (
1..$
#secs ){ 1N/A # remove parenthesis occurring at the end of some messages 1N/A " an unknown diagnostic message.\n\n";
1N/A "\n$msg{DESCRIPTION}\n";
1N/A warn "Unknown escape: E<$1> in $_";