Almost-minimal filesystem based blog.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
3.7 KiB

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