1Carp::Clan(3) User Contributed Perl Documentation Carp::Clan(3)
2
3
4
6 Carp::Clan - Report errors from perspective of caller of a "clan" of
7 modules
8
10 carp - warn of errors (from perspective of caller)
11
12 cluck - warn of errors with stack backtrace
13
14 croak - die of errors (from perspective of caller)
15
16 confess - die of errors with stack backtrace
17
18 use Carp::Clan qw(^MyClan::);
19 croak "We're outta here!";
20
21 use Carp::Clan;
22 confess "This is how we got here!";
23
25 This module is based on ""Carp.pm"" from Perl 5.005_03. It has been
26 modified to skip all package names matching the pattern given in the
27 "use" statement inside the ""qw()"" term (or argument list).
28
29 Suppose you have a family of modules or classes named "Pack::A",
30 "Pack::B" and so on, and each of them uses ""Carp::Clan qw(^Pack::);""
31 (or at least the one in which the error or warning gets raised).
32
33 Thus when for example your script "tool.pl" calls module "Pack::A", and
34 module "Pack::A" calls module "Pack::B", an exception raised in module
35 "Pack::B" will appear to have originated in "tool.pl" where "Pack::A"
36 was called, and not in "Pack::A" where "Pack::B" was called, as the
37 unmodified ""Carp.pm"" would try to make you believe ":-)".
38
39 This works similarly if "Pack::B" calls "Pack::C" where the exception
40 is raised, etcetera.
41
42 In other words, this blames all errors in the ""Pack::*"" modules on
43 the user of these modules, i.e., on you. ";-)"
44
45 The skipping of a clan (or family) of packages according to a pattern
46 describing its members is necessary in cases where these modules are
47 not classes derived from each other (and thus when examining @ISA - as
48 in the original ""Carp.pm"" module - doesn't help).
49
50 The purpose and advantage of this is that a "clan" of modules can work
51 together (and call each other) and throw exceptions at various depths
52 down the calling hierarchy and still appear as a monolithic block (as
53 though they were a single module) from the perspective of the caller.
54
55 In case you just want to ward off all error messages from the module in
56 which you ""use Carp::Clan"", i.e., if you want to make all error
57 messages or warnings to appear to originate from where your module was
58 called (this is what you usually used to ""use Carp;"" for ";-)"),
59 instead of in your module itself (which is what you can do with a "die"
60 or "warn" anyway), you do not need to provide a pattern, the module
61 will automatically provide the correct one for you.
62
63 I.e., just ""use Carp::Clan;"" without any arguments and call "carp" or
64 "croak" as appropriate, and they will automatically defend your module
65 against all blames!
66
67 In other words, a pattern is only necessary if you want to make several
68 modules (more than one) work together and appear as though they were
69 only one.
70
71 Forcing a Stack Trace
72 As a debugging aid, you can force ""Carp::Clan"" to treat a "croak" as
73 a "confess" and a "carp" as a "cluck". In other words, force a detailed
74 stack trace to be given. This can be very helpful when trying to
75 understand why, or from where, a warning or error is being generated.
76
77 This feature is enabled either by "importing" the non-existent symbol
78 'verbose', or by setting the global variable "$Carp::Clan::Verbose" to
79 a true value.
80
81 You would typically enable it by saying
82
83 use Carp::Clan qw(verbose);
84
85 Note that you can both specify a "family pattern" and the string
86 "verbose" inside the ""qw()"" term (or argument list) of the "use"
87 statement, but consider that a pattern of packages to skip is pointless
88 when "verbose" causes a full stack trace anyway.
89
91 The ""Carp::Clan"" routines don't handle exception objects currently.
92 If called with a first argument that is a reference, they simply call
93 ""die()"" or ""warn()"", as appropriate.
94
95
96
97perl v5.16.3 2009-10-24 Carp::Clan(3)