summaryrefslogtreecommitdiffstats
path: root/upstream/debian-bookworm/man3/diagnostics.3perl
blob: 0282f57caea80236c2f650151249f04cf734fa2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings.  \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote.  \*(C+ will
.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
.    ds -- \(*W-
.    ds PI pi
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
.    ds L" ""
.    ds R" ""
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds -- \|\(em\|
.    ds PI \(*p
.    ds L" ``
.    ds R" ''
.    ds C`
.    ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
.    if \nF \{\
.        de IX
.        tm Index:\\$1\t\\n%\t"\\$2"
..
.        if !\nF==2 \{\
.            nr % 0
.            nr F 2
.        \}
.    \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "diagnostics 3perl"
.TH diagnostics 3perl "2023-11-25" "perl v5.36.0" "Perl Programmers Reference Guide"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
diagnostics, splain \- produce verbose warning diagnostics
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
Using the \f(CW\*(C`diagnostics\*(C'\fR pragma:
.PP
.Vb 2
\&    use diagnostics;
\&    use diagnostics \-verbose;
\&
\&    enable  diagnostics;
\&    disable diagnostics;
.Ve
.PP
Using the \f(CW\*(C`splain\*(C'\fR standalone filter program:
.PP
.Vb 2
\&    perl program 2>diag.out
\&    splain [\-v] [\-p] diag.out
.Ve
.PP
Using diagnostics to get stack traces from a misbehaving script:
.PP
.Vb 1
\&    perl \-Mdiagnostics=\-traceonly my_script.pl
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
.ie n .SS "The ""diagnostics"" Pragma"
.el .SS "The \f(CWdiagnostics\fP Pragma"
.IX Subsection "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 \f(CW\*(C`use warnings\*(C'\fR), 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.
.PP
To use in your program as a pragma, merely invoke
.PP
.Vb 1
\&    use diagnostics;
.Ve
.PP
at the start (or near the start) of your program.  (Note 
that this \fIdoes\fR enable perl's \fB\-w\fR flag.)  Your whole
compilation will then be subject(ed :\-) to the enhanced diagnostics.
These still go out \fB\s-1STDERR\s0\fR.
.PP
Due to the interaction between runtime and compiletime issues,
and because it's probably not a very good idea anyway,
you may not use \f(CW\*(C`no diagnostics\*(C'\fR to turn them off at compiletime.
However, you may control their behaviour at runtime using the 
\&\fBdisable()\fR and \fBenable()\fR methods to turn them off and on respectively.
.PP
The \fB\-verbose\fR flag first prints out the perldiag introduction before
any other diagnostics.  The \f(CW$diagnostics::PRETTY\fR variable can generate nicer
escape sequences for pagers.
.PP
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 \fBwarn()\fR are unaffected,
allowing duplicate user messages to be displayed.
.PP
This module also adds a stack trace to the error message when perl dies.
This is useful for pinpointing what
caused the death.  The \fB\-traceonly\fR (or
just \fB\-t\fR) flag turns off the explanations of warning messages leaving just
the stack traces.  So if your script is dieing, run it again with
.PP
.Vb 1
\&  perl \-Mdiagnostics=\-traceonly my_bad_script
.Ve
.PP
to see the call stack at the time of death.  By supplying the \fB\-warntrace\fR
(or just \fB\-w\fR) flag, any warnings emitted will also come with a stack
trace.
.SS "The \fIsplain\fP Program"
.IX Subsection "The splain Program"
Another program, \fIsplain\fR is actually nothing
more than a link to the (executable) \fIdiagnostics.pm\fR module, as well as
a link to the \fIdiagnostics.pod\fR documentation.  The \fB\-v\fR flag is like
the \f(CW\*(C`use diagnostics \-verbose\*(C'\fR directive.
The \fB\-p\fR flag is like the
\&\f(CW$diagnostics::PRETTY\fR variable.  Since you're post-processing with 
\&\fIsplain\fR, there's no sense in being able to \fBenable()\fR or \fBdisable()\fR processing.
.PP
Output from \fIsplain\fR is directed to \fB\s-1STDOUT\s0\fR, unlike the pragma.
.SH "EXAMPLES"
.IX Header "EXAMPLES"
The following file is certain to trigger a few errors at both
runtime and compiletime:
.PP
.Vb 8
\&    use diagnostics;
\&    print NOWHERE "nothing\en";
\&    print STDERR "\en\etThis message should be unadorned.\en";
\&    warn "\etThis is a user warning";
\&    print "\enDIAGNOSTIC TESTER: Please enter a <CR> here: ";
\&    my $a, $b = scalar <STDIN>;
\&    print "\en";
\&    print $x/$y;
.Ve
.PP
If you prefer to run your program first and look at its problem
afterwards, do this:
.PP
.Vb 2
\&    perl \-w test.pl 2>test.out
\&    ./splain < test.out
.Ve
.PP
Note that this is not in general possible in shells of more dubious heritage, 
as the theoretical
.PP
.Vb 2
\&    (perl \-w test.pl >/dev/tty) >& test.out
\&    ./splain < test.out
.Ve
.PP
Because you just moved the existing \fBstdout\fR to somewhere else.
.PP
If you don't want to modify your source code, but still have on-the-fly
warnings, do this:
.PP
.Vb 1
\&    exec 3>&1; perl \-w test.pl 2>&1 1>&3 3>&\- | splain 1>&2 3>&\-
.Ve
.PP
Nifty, eh?
.PP
If you want to control warnings on the fly, do something like this.
Make sure you do the \f(CW\*(C`use\*(C'\fR first, or you won't be able to get
at the \fBenable()\fR or \fBdisable()\fR methods.
.PP
.Vb 4
\&    use diagnostics; # checks entire compilation phase 
\&        print "\entime for 1st bogus diags: SQUAWKINGS\en";
\&        print BOGUS1 \*(Aqnada\*(Aq;
\&        print "done with 1st bogus\en";
\&
\&    disable diagnostics; # only turns off runtime warnings
\&        print "\entime for 2nd bogus: (squelched)\en";
\&        print BOGUS2 \*(Aqnada\*(Aq;
\&        print "done with 2nd bogus\en";
\&
\&    enable diagnostics; # turns back on runtime warnings
\&        print "\entime for 3rd bogus: SQUAWKINGS\en";
\&        print BOGUS3 \*(Aqnada\*(Aq;
\&        print "done with 3rd bogus\en";
\&
\&    disable diagnostics;
\&        print "\entime for 4th bogus: (squelched)\en";
\&        print BOGUS4 \*(Aqnada\*(Aq;
\&        print "done with 4th bogus\en";
.Ve
.SH "INTERNALS"
.IX Header "INTERNALS"
Diagnostic messages derive from the \fIperldiag.pod\fR file when available at
runtime.  Otherwise, they may be embedded in the file itself when the
splain package is built.   See the \fIMakefile\fR for details.
.PP
If an extant \f(CW$SIG\fR{_\|_WARN_\|_} handler is discovered, it will continue
to be honored, but only after the \fBdiagnostics::splainthis()\fR function 
(the module's \f(CW$SIG\fR{_\|_WARN_\|_} interceptor) has had its way with your
warnings.
.PP
There is a \f(CW$diagnostics::DEBUG\fR variable you may set if you're desperately
curious what sorts of things are being intercepted.
.PP
.Vb 1
\&    BEGIN { $diagnostics::DEBUG = 1 }
.Ve
.SH "BUGS"
.IX Header "BUGS"
Not being able to say \*(L"no diagnostics\*(R" is annoying, but may not be
insurmountable.
.PP
The \f(CW\*(C`\-pretty\*(C'\fR directive is called too late to affect matters.
You have to do this instead, and \fIbefore\fR you load the module.
.PP
.Vb 1
\&    BEGIN { $diagnostics::PRETTY = 1 }
.Ve
.PP
I could start up faster by delaying compilation until it should be
needed, but this gets a \*(L"panic: top_level\*(R" when using the pragma form
in Perl 5.001e.
.PP
While it's true that this documentation is somewhat subserious, if you use
a program named \fIsplain\fR, you should expect a bit of whimsy.
.SH "AUTHOR"
.IX Header "AUTHOR"
Tom Christiansen <\fItchrist@mox.perl.com\fR>, 25 June 1995.