Debian Codegraph @

upstream/mageia-cauldron/man3pm/Fatal.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\"
56 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "Fatal 3pm"
61 .TH Fatal 3pm 2023-12-30 "perl v5.42.0" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 Fatal \- Replace functions with equivalents which succeed or die
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 .Vb 1
71 \& use Fatal qw(open close);
72 \&
73 \& open(my $fh, "<", $filename); # No need to check errors!
74 \&
75 \& use File::Copy qw(move);
76 \& use Fatal qw(move);
77 \&
78 \& move($file1, $file2); # No need to check errors!
79 \&
80 \& sub juggle { . . . }
81 \& Fatal\->import(\*(Aqjuggle\*(Aq);
82 .Ve
83 .SH "BEST PRACTICE"
84 .IX Header "BEST PRACTICE"
85 \&\fBFatal has been obsoleted by the new autodie pragma.\fR Please use
86 autodie in preference to \f(CW\*(C`Fatal\*(C'\fR. autodie supports lexical scoping,
87 throws real exception objects, and provides much nicer error messages.
88 .PP
89 The use of \f(CW\*(C`:void\*(C'\fR with Fatal is discouraged.
90 .SH DESCRIPTION
91 .IX Header "DESCRIPTION"
92 \&\f(CW\*(C`Fatal\*(C'\fR provides a way to conveniently replace
93 functions which normally return a false value when they fail with
94 equivalents which raise exceptions if they are not successful. This
95 lets you use these functions without having to test their return
96 values explicitly on each call. Exceptions can be caught using
97 \&\f(CW\*(C`eval{}\*(C'\fR. See perlfunc and perlvar for details.
98 .PP
99 The do\-or\-die equivalents are set up simply by calling Fatal\*(Aqs
100 \&\f(CW\*(C`import\*(C'\fR routine, passing it the names of the functions to be
101 replaced. You may wrap both user\-defined functions and overridable
102 CORE operators (except \f(CW\*(C`exec\*(C'\fR, \f(CW\*(C`system\*(C'\fR, \f(CW\*(C`print\*(C'\fR, or any other
103 built\-in that cannot be expressed via prototypes) in this way.
104 .PP
105 If the symbol \f(CW\*(C`:void\*(C'\fR appears in the import list, then functions
106 named later in that import list raise an exception only when
107 these are called in void context\-\-that is, when their return
108 values are ignored. For example
109 .PP
110 .Vb 1
111 \& use Fatal qw/:void open close/;
112 \&
113 \& # properly checked, so no exception raised on error
114 \& if (not open(my $fh, \*(Aq<\*(Aq, \*(Aq/bogotic\*(Aq) {
115 \& warn "Can\*(Aqt open /bogotic: $!";
116 \& }
117 \&
118 \& # not checked, so error raises an exception
119 \& close FH;
120 .Ve
121 .PP
122 The use of \f(CW\*(C`:void\*(C'\fR is discouraged, as it can result in exceptions
123 not being thrown if you \fIaccidentally\fR call a method without
124 void context. Use autodie instead if you need to be able to
125 disable autodying/Fatal behaviour for a small block of code.
126 .SH DIAGNOSTICS
127 .IX Header "DIAGNOSTICS"
128 .ie n .IP "Bad subroutine name for Fatal: %s" 4
129 .el .IP "Bad subroutine name for Fatal: \f(CW%s\fR" 4
130 .IX Item "Bad subroutine name for Fatal: %s"
131 You\*(Aqve called \f(CW\*(C`Fatal\*(C'\fR with an argument that doesn\*(Aqt look like
132 a subroutine name, nor a switch that this version of Fatal
133 understands.
134 .ie n .IP "%s is not a Perl subroutine" 4
135 .el .IP "\f(CW%s\fR is not a Perl subroutine" 4
136 .IX Item "%s is not a Perl subroutine"
137 You\*(Aqve asked \f(CW\*(C`Fatal\*(C'\fR to try and replace a subroutine which does not
138 exist, or has not yet been defined.
139 .ie n .IP "%s is neither a builtin, nor a Perl subroutine" 4
140 .el .IP "\f(CW%s\fR is neither a builtin, nor a Perl subroutine" 4
141 .IX Item "%s is neither a builtin, nor a Perl subroutine"
142 You\*(Aqve asked \f(CW\*(C`Fatal\*(C'\fR to replace a subroutine, but it\*(Aqs not a Perl
143 built\-in, and \f(CW\*(C`Fatal\*(C'\fR couldn\*(Aqt find it as a regular subroutine.
144 It either doesn\*(Aqt exist or has not yet been defined.
145 .ie n .IP "Cannot make the non\-overridable %s fatal" 4
146 .el .IP "Cannot make the non\-overridable \f(CW%s\fR fatal" 4
147 .IX Item "Cannot make the non-overridable %s fatal"
148 You\*(Aqve tried to use \f(CW\*(C`Fatal\*(C'\fR on a Perl built\-in that can\*(Aqt be
149 overridden, such as \f(CW\*(C`print\*(C'\fR or \f(CW\*(C`system\*(C'\fR, which means that
150 \&\f(CW\*(C`Fatal\*(C'\fR can\*(Aqt help you, although some other modules might.
151 See the "SEE ALSO" section of this documentation.
152 .ie n .IP "Internal error: %s" 4
153 .el .IP "Internal error: \f(CW%s\fR" 4
154 .IX Item "Internal error: %s"
155 You\*(Aqve found a bug in \f(CW\*(C`Fatal\*(C'\fR. Please report it using
156 the \f(CW\*(C`perlbug\*(C'\fR command.
157 .SH BUGS
158 .IX Header "BUGS"
159 \&\f(CW\*(C`Fatal\*(C'\fR clobbers the context in which a function is called and always
160 makes it a scalar context, except when the \f(CW\*(C`:void\*(C'\fR tag is used.
161 This problem does not exist in autodie.
162 .PP
163 "Used only once" warnings can be generated when \f(CW\*(C`autodie\*(C'\fR or \f(CW\*(C`Fatal\*(C'\fR
164 is used with package filehandles (eg, \f(CW\*(C`FILE\*(C'\fR). It\*(Aqs strongly recommended
165 you use scalar filehandles instead.
166 .SH AUTHOR
167 .IX Header "AUTHOR"
168 Original module by Lionel Cons (CERN).
169 .PP
170 Prototype updates by Ilya Zakharevich <[email protected]\-state.edu>.
171 .PP
172 autodie support, bugfixes, extended diagnostics, \f(CW\*(C`system\*(C'\fR
173 support, and major overhauling by Paul Fenwick <[email protected]>
174 .SH LICENSE
175 .IX Header "LICENSE"
176 This module is free software, you may distribute it under the
177 same terms as Perl itself.
178 .SH "SEE ALSO"
179 .IX Header "SEE ALSO"
180 autodie for a nicer way to use lexical Fatal.
181 .PP
182 IPC::System::Simple for a similar idea for calls to \f(CWsystem()\fR
183 and backticks.