Install Perl 5.8.8
[msysgit.git] / mingw / html / lib / Carp.html
blobe95174408a5ffd5489824ed47c29d38f3a836747
1 <?xml version="1.0" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <title>carp - warn of errors</title>
6 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7 <link rev="made" href="mailto:" />
8 </head>
10 <body style="background-color: white">
11 <table border="0" width="100%" cellspacing="0" cellpadding="3">
12 <tr><td class="block" style="background-color: #cccccc" valign="middle">
13 <big><strong><span class="block">&nbsp;carp - warn of errors</span></strong></big>
14 </td></tr>
15 </table>
17 <p><a name="__index__"></a></p>
18 <!-- INDEX BEGIN -->
20 <ul>
22 <li><a href="#name">NAME</a></li>
23 <li><a href="#synopsis">SYNOPSIS</a></li>
24 <li><a href="#description">DESCRIPTION</a></li>
25 <ul>
27 <li><a href="#forcing_a_stack_trace">Forcing a Stack Trace</a></li>
28 </ul>
30 <li><a href="#global_variables">GLOBAL VARIABLES</a></li>
31 <ul>
33 <li><a href="#_carp__carplevel">$Carp::CarpLevel</a></li>
34 <li><a href="#_carp__maxevallen">$Carp::MaxEvalLen</a></li>
35 <li><a href="#_carp__maxarglen">$Carp::MaxArgLen</a></li>
36 <li><a href="#_carp__maxargnums">$Carp::MaxArgNums</a></li>
37 <li><a href="#_carp__verbose">$Carp::Verbose</a></li>
38 </ul>
40 <li><a href="#bugs">BUGS</a></li>
41 </ul>
42 <!-- INDEX END -->
44 <hr />
45 <p>
46 </p>
47 <h1><a name="name">NAME</a></h1>
48 <p>carp - warn of errors (from perspective of caller)</p>
49 <p>cluck - warn of errors with stack backtrace
50 (not exported by default)</p>
51 <p>croak - die of errors (from perspective of caller)</p>
52 <p>confess - die of errors with stack backtrace</p>
53 <p>shortmess - return the message that carp and croak produce</p>
54 <p>longmess - return the message that cluck and confess produce</p>
55 <p>
56 </p>
57 <hr />
58 <h1><a name="synopsis">SYNOPSIS</a></h1>
59 <pre>
60 use Carp;
61 croak &quot;We're outta here!&quot;;</pre>
62 <pre>
63 use Carp qw(cluck);
64 cluck &quot;This is how we got here!&quot;;</pre>
65 <pre>
66 print FH Carp::shortmess(&quot;This will have caller's details added&quot;);
67 print FH Carp::longmess(&quot;This will have stack backtrace added&quot;);</pre>
68 <p>
69 </p>
70 <hr />
71 <h1><a name="description">DESCRIPTION</a></h1>
72 <p>The Carp routines are useful in your own modules because
73 they act like <code>die()</code> or warn(), but with a message which is more
74 likely to be useful to a user of your module. In the case of
75 cluck, confess, and longmess that context is a summary of every
76 call in the call-stack. For a shorter message you can use carp,
77 croak or shortmess which report the error as being from where
78 your module was called. There is no guarantee that that is where
79 the error was, but it is a good educated guess.</p>
80 <p>You can also alter the way the output and logic of <code>Carp</code> works, by
81 changing some global variables in the <code>Carp</code> namespace. See the
82 section on <code>GLOBAL VARIABLES</code> below.</p>
83 <p>Here is a more complete description of how shortmess works. What
84 it does is search the call-stack for a function call stack where
85 it hasn't been told that there shouldn't be an error. If every
86 call is marked safe, it then gives up and gives a full stack
87 backtrace instead. In other words it presumes that the first likely
88 looking potential suspect is guilty. Its rules for telling whether
89 a call shouldn't generate errors work as follows:</p>
90 <ol>
91 <li>
92 <p>Any call from a package to itself is safe.</p>
93 </li>
94 <li>
95 <p>Packages claim that there won't be errors on calls to or from
96 packages explicitly marked as safe by inclusion in @CARP_NOT, or
97 (if that array is empty) @ISA. The ability to override what
98 @ISA says is new in 5.8.</p>
99 </li>
100 <li>
101 <p>The trust in item 2 is transitive. If A trusts B, and B
102 trusts C, then A trusts C. So if you do not override @ISA
103 with @CARP_NOT, then this trust relationship is identical to,
104 ``inherits from''.</p>
105 </li>
106 <li>
107 <p>Any call from an internal Perl module is safe. (Nothing keeps
108 user modules from marking themselves as internal to Perl, but
109 this practice is discouraged.)</p>
110 </li>
111 <li>
112 <p>Any call to Carp is safe. (This rule is what keeps it from
113 reporting the error where you call carp/croak/shortmess.)</p>
114 </li>
115 </ol>
117 </p>
118 <h2><a name="forcing_a_stack_trace">Forcing a Stack Trace</a></h2>
119 <p>As a debugging aid, you can force Carp to treat a croak as a confess
120 and a carp as a cluck across <em>all</em> modules. In other words, force a
121 detailed stack trace to be given. This can be very helpful when trying
122 to understand why, or from where, a warning or error is being generated.</p>
123 <p>This feature is enabled by 'importing' the non-existent symbol
124 'verbose'. You would typically enable it by saying</p>
125 <pre>
126 perl -MCarp=verbose script.pl</pre>
127 <p>or by including the string <code>MCarp=verbose</code> in the PERL5OPT
128 environment variable.</p>
129 <p>Alternately, you can set the global variable <code>$Carp::Verbose</code> to true.
130 See the <code>GLOBAL VARIABLES</code> section below.</p>
132 </p>
133 <hr />
134 <h1><a name="global_variables">GLOBAL VARIABLES</a></h1>
136 </p>
137 <h2><a name="_carp__carplevel">$Carp::CarpLevel</a></h2>
138 <p>This variable determines how many call frames are to be skipped when
139 reporting where an error occurred on a call to one of <code>Carp</code>'s
140 functions. For example:</p>
141 <pre>
142 $Carp::CarpLevel = 1;
143 sub bar { .... or _error('Wrong input') }
144 sub _error { Carp::carp(@_) }</pre>
145 <p>This would make Carp report the error as coming from <code>bar</code>'s caller,
146 rather than from <code>_error</code>'s caller, as it normally would.</p>
147 <p>Defaults to <code>0</code>.</p>
149 </p>
150 <h2><a name="_carp__maxevallen">$Carp::MaxEvalLen</a></h2>
151 <p>This variable determines how many characters of a string-eval are to
152 be shown in the output. Use a value of <code>0</code> to show all text.</p>
153 <p>Defaults to <code>0</code>.</p>
155 </p>
156 <h2><a name="_carp__maxarglen">$Carp::MaxArgLen</a></h2>
157 <p>This variable determines how many characters of each argument to a
158 function to print. Use a value of <code>0</code> to show the full length of the
159 argument.</p>
160 <p>Defaults to <code>64</code>.</p>
162 </p>
163 <h2><a name="_carp__maxargnums">$Carp::MaxArgNums</a></h2>
164 <p>This variable determines how many arguments to each function to show.
165 Use a value of <code>0</code> to show all arguments to a function call.</p>
166 <p>Defaults to <code>8</code>.</p>
168 </p>
169 <h2><a name="_carp__verbose">$Carp::Verbose</a></h2>
170 <p>This variable makes <code>Carp</code> use the <code>longmess</code> function at all times.
171 This effectively means that all calls to <code>carp</code> become <code>cluck</code> and
172 all calls to <code>croak</code> become <code>confess</code>.</p>
173 <p>Note, this is analogous to using <code>use Carp 'verbose'</code>.</p>
174 <p>Defaults to <code>0</code>.</p>
176 </p>
177 <hr />
178 <h1><a name="bugs">BUGS</a></h1>
179 <p>The Carp routines don't handle exception objects currently.
180 If called with a first argument that is a reference, they simply
181 call <code>die()</code> or warn(), as appropriate.</p>
182 <table border="0" width="100%" cellspacing="0" cellpadding="3">
183 <tr><td class="block" style="background-color: #cccccc" valign="middle">
184 <big><strong><span class="block">&nbsp;carp - warn of errors</span></strong></big>
185 </td></tr>
186 </table>
188 </body>
190 </html>