B::Deparse was chocking on variable names with colons (like foo::::bar)
[p5sagit/p5-mst-13.2.git] / lib / Carp.pod
1 =head1 NAME
2
3 carp    - warn of errors (from perspective of caller)
4
5 cluck   - warn of errors with stack backtrace
6           (not exported by default)
7
8 croak   - die of errors (from perspective of caller)
9
10 confess - die of errors with stack backtrace
11
12 shortmess - return the message that carp and croak produce
13
14 longmess - return the message that cluck and confess produce
15
16 =head1 SYNOPSIS
17
18     use Carp;
19     croak "We're outta here!";
20
21     use Carp qw(cluck);
22     cluck "This is how we got here!";
23
24     print FH Carp::shortmess("This will have caller's details added");
25     print FH Carp::longmess("This will have stack backtrace added");
26
27 =head1 DESCRIPTION
28
29 The Carp routines are useful in your own modules because
30 they act like die() or warn(), but with a message which is more
31 likely to be useful to a user of your module.  In the case of
32 cluck, confess, and longmess that context is a summary of every
33 call in the call-stack.  For a shorter message you can use carp,
34 croak or shortmess which report the error as being from where
35 your module was called.  There is no guarantee that that is where
36 the error was, but it is a good educated guess.
37
38 You can also alter the way the output and logic of C<Carp> works, by
39 changing some global variables in the C<Carp> namespace. See the
40 section on C<GLOBAL VARIABLES> below.
41
42 Here is a more complete description of how shortmess works.  What
43 it does is search the call-stack for a function call stack where
44 it hasn't been told that there shouldn't be an error.  If every
45 call is marked safe, it then gives up and gives a full stack
46 backtrace instead.  In other words it presumes that the first likely
47 looking potential suspect is guilty.  Its rules for telling whether
48 a call shouldn't generate errors work as follows:
49
50 =over 4
51
52 =item 1.
53
54 Any call from a package to itself is safe.
55
56 =item 2.
57
58 Packages claim that there won't be errors on calls to or from
59 packages explicitly marked as safe by inclusion in @CARP_NOT, or
60 (if that array is empty) @ISA.  The ability to override what
61 @ISA says is new in 5.8.
62
63 =item 3.
64
65 The trust in item 2 is transitive.  If A trusts B, and B
66 trusts C, then A trusts C.  So if you do not override @ISA
67 with @CARP_NOT, then this trust relationship is identical to,
68 "inherits from".
69
70 =item 4.
71
72 Any call from an internal Perl module is safe.  (Nothing keeps
73 user modules from marking themselves as internal to Perl, but
74 this practice is discouraged.)
75
76 =item 5.
77
78 Any call to Carp is safe.  (This rule is what keeps it from
79 reporting the error where you call carp/croak/shortmess.)
80
81 =back
82
83 =head2 Forcing a Stack Trace
84
85 As a debugging aid, you can force Carp to treat a croak as a confess
86 and a carp as a cluck across I<all> modules. In other words, force a
87 detailed stack trace to be given.  This can be very helpful when trying
88 to understand why, or from where, a warning or error is being generated.
89
90 This feature is enabled by 'importing' the non-existent symbol
91 'verbose'. You would typically enable it by saying
92
93     perl -MCarp=verbose script.pl
94
95 or by including the string C<MCarp=verbose> in the PERL5OPT
96 environment variable.
97
98 Alternately, you can set the global variable C<$Carp::Verbose> to true.
99 See the C<GLOBAL VARIABLES> section below.
100
101 =head1 GLOBAL VARIABLES
102
103 =head2 $Carp::CarpLevel
104
105 This variable determines how many call frames are to be skipped when
106 reporting where an error occurred on a call to one of C<Carp>'s
107 functions. For example:
108
109     $Carp::CarpLevel = 1;
110     sub bar     { .... or _error('Wrong input') }
111     sub _error  { Carp::carp(@_) }
112
113 This would make Carp report the error as coming from C<bar>'s caller,
114 rather than from C<_error>'s caller, as it normally would.
115
116 Defaults to C<0>.
117
118 =head2 $Carp::MaxEvalLen
119
120 This variable determines how many characters of a string-eval are to
121 be shown in the output. Use a value of C<0> to show all text.
122
123 Defaults to C<0>.
124
125 =head2 $Carp::MaxArgLen
126
127 This variable determines how many characters of each argument to a
128 function to print. Use a value of C<0> to show the full length of the
129 argument.
130
131 Defaults to C<64>.
132
133 =head2 $Carp::MaxArgNums
134
135 This variable determines how many arguments to each function to show.
136 Use a value of C<0> to show all arguments to a function call.
137
138 Defaults to C<8>.
139
140 =head2 $Carp::Verbose
141
142 This variable makes C<Carp> use the C<longmess> function at all times.
143 This effectively means that all calls to C<carp> become C<cluck> and
144 all calls to C<croak> become C<confess>.
145
146 Note, this is analogous to using C<use Carp 'verbose'>.
147
148 Defaults to C<0>.
149
150
151 =head1 BUGS
152
153 The Carp routines don't handle exception objects currently.
154 If called with a first argument that is a reference, they simply
155 call die() or warn(), as appropriate.
156