Counter Strike : Global Offensive Source Code
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.

237 lines
7.4 KiB

  1. package Carp;
  2. our $VERSION = '1.0701';
  3. # this file is an utra-lightweight stub. The first time a function is
  4. # called, Carp::Heavy is loaded, and the real short/longmessmess_jmp
  5. # subs are installed
  6. our $MaxEvalLen = 0;
  7. our $Verbose = 0;
  8. our $CarpLevel = 0;
  9. our $MaxArgLen = 64; # How much of each argument to print. 0 = all.
  10. our $MaxArgNums = 8; # How many arguments to print. 0 = all.
  11. require Exporter;
  12. our @ISA = ('Exporter');
  13. our @EXPORT = qw(confess croak carp);
  14. our @EXPORT_OK = qw(cluck verbose longmess shortmess);
  15. our @EXPORT_FAIL = qw(verbose); # hook to enable verbose mode
  16. # if the caller specifies verbose usage ("perl -MCarp=verbose script.pl")
  17. # then the following method will be called by the Exporter which knows
  18. # to do this thanks to @EXPORT_FAIL, above. $_[1] will contain the word
  19. # 'verbose'.
  20. sub export_fail { shift; $Verbose = shift if $_[0] eq 'verbose'; @_ }
  21. # fixed hooks for stashes to point to
  22. sub longmess { goto &longmess_jmp }
  23. sub shortmess { goto &shortmess_jmp }
  24. # these two are replaced when Carp::Heavy is loaded
  25. sub longmess_jmp {
  26. local($@, $!);
  27. eval { require Carp::Heavy };
  28. return $@ if $@;
  29. goto &longmess_real;
  30. }
  31. sub shortmess_jmp {
  32. local($@, $!);
  33. eval { require Carp::Heavy };
  34. return $@ if $@;
  35. goto &shortmess_real;
  36. }
  37. sub croak { die shortmess @_ }
  38. sub confess { die longmess @_ }
  39. sub carp { warn shortmess @_ }
  40. sub cluck { warn longmess @_ }
  41. 1;
  42. __END__
  43. =head1 NAME
  44. carp - warn of errors (from perspective of caller)
  45. cluck - warn of errors with stack backtrace
  46. (not exported by default)
  47. croak - die of errors (from perspective of caller)
  48. confess - die of errors with stack backtrace
  49. =head1 SYNOPSIS
  50. use Carp;
  51. croak "We're outta here!";
  52. use Carp qw(cluck);
  53. cluck "This is how we got here!";
  54. =head1 DESCRIPTION
  55. The Carp routines are useful in your own modules because
  56. they act like die() or warn(), but with a message which is more
  57. likely to be useful to a user of your module. In the case of
  58. cluck, confess, and longmess that context is a summary of every
  59. call in the call-stack. For a shorter message you can use C<carp>
  60. or C<croak> which report the error as being from where your module
  61. was called. There is no guarantee that that is where the error
  62. was, but it is a good educated guess.
  63. You can also alter the way the output and logic of C<Carp> works, by
  64. changing some global variables in the C<Carp> namespace. See the
  65. section on C<GLOBAL VARIABLES> below.
  66. Here is a more complete description of how c<carp> and c<croak> work.
  67. What they do is search the call-stack for a function call stack where
  68. they have not been told that there shouldn't be an error. If every
  69. call is marked safe, they give up and give a full stack backtrace
  70. instead. In other words they presume that the first likely looking
  71. potential suspect is guilty. Their rules for telling whether
  72. a call shouldn't generate errors work as follows:
  73. =over 4
  74. =item 1.
  75. Any call from a package to itself is safe.
  76. =item 2.
  77. Packages claim that there won't be errors on calls to or from
  78. packages explicitly marked as safe by inclusion in C<@CARP_NOT>, or
  79. (if that array is empty) C<@ISA>. The ability to override what
  80. @ISA says is new in 5.8.
  81. =item 3.
  82. The trust in item 2 is transitive. If A trusts B, and B
  83. trusts C, then A trusts C. So if you do not override C<@ISA>
  84. with C<@CARP_NOT>, then this trust relationship is identical to,
  85. "inherits from".
  86. =item 4.
  87. Any call from an internal Perl module is safe. (Nothing keeps
  88. user modules from marking themselves as internal to Perl, but
  89. this practice is discouraged.)
  90. =item 5.
  91. Any call to Perl's warning system (eg Carp itself) is safe.
  92. (This rule is what keeps it from reporting the error at the
  93. point where you call C<carp> or C<croak>.)
  94. =item 6.
  95. C<$Carp::CarpLevel> can be set to skip a fixed number of additional
  96. call levels. Using this is not recommended because it is very
  97. difficult to get it to behave correctly.
  98. =back
  99. =head2 Forcing a Stack Trace
  100. As a debugging aid, you can force Carp to treat a croak as a confess
  101. and a carp as a cluck across I<all> modules. In other words, force a
  102. detailed stack trace to be given. This can be very helpful when trying
  103. to understand why, or from where, a warning or error is being generated.
  104. This feature is enabled by 'importing' the non-existent symbol
  105. 'verbose'. You would typically enable it by saying
  106. perl -MCarp=verbose script.pl
  107. or by including the string C<MCarp=verbose> in the PERL5OPT
  108. environment variable.
  109. Alternately, you can set the global variable C<$Carp::Verbose> to true.
  110. See the C<GLOBAL VARIABLES> section below.
  111. =head1 GLOBAL VARIABLES
  112. =head2 $Carp::MaxEvalLen
  113. This variable determines how many characters of a string-eval are to
  114. be shown in the output. Use a value of C<0> to show all text.
  115. Defaults to C<0>.
  116. =head2 $Carp::MaxArgLen
  117. This variable determines how many characters of each argument to a
  118. function to print. Use a value of C<0> to show the full length of the
  119. argument.
  120. Defaults to C<64>.
  121. =head2 $Carp::MaxArgNums
  122. This variable determines how many arguments to each function to show.
  123. Use a value of C<0> to show all arguments to a function call.
  124. Defaults to C<8>.
  125. =head2 $Carp::Verbose
  126. This variable makes C<carp> and C<cluck> generate stack backtraces
  127. just like C<cluck> and C<confess>. This is how C<use Carp 'verbose'>
  128. is implemented internally.
  129. Defaults to C<0>.
  130. =head2 %Carp::Internal
  131. This says what packages are internal to Perl. C<Carp> will never
  132. report an error as being from a line in a package that is internal to
  133. Perl. For example:
  134. $Carp::Internal{ __PACKAGE__ }++;
  135. # time passes...
  136. sub foo { ... or confess("whatever") };
  137. would give a full stack backtrace starting from the first caller
  138. outside of __PACKAGE__. (Unless that package was also internal to
  139. Perl.)
  140. =head2 %Carp::CarpInternal
  141. This says which packages are internal to Perl's warning system. For
  142. generating a full stack backtrace this is the same as being internal
  143. to Perl, the stack backtrace will not start inside packages that are
  144. listed in C<%Carp::CarpInternal>. But it is slightly different for
  145. the summary message generated by C<carp> or C<croak>. There errors
  146. will not be reported on any lines that are calling packages in
  147. C<%Carp::CarpInternal>.
  148. For example C<Carp> itself is listed in C<%Carp::CarpInternal>.
  149. Therefore the full stack backtrace from C<confess> will not start
  150. inside of C<Carp>, and the short message from calling C<croak> is
  151. not placed on the line where C<croak> was called.
  152. =head2 $Carp::CarpLevel
  153. This variable determines how many additional call frames are to be
  154. skipped that would not otherwise be when reporting where an error
  155. occurred on a call to one of C<Carp>'s functions. It is fairly easy
  156. to count these call frames on calls that generate a full stack
  157. backtrace. However it is much harder to do this accounting for calls
  158. that generate a short message. Usually people skip too many call
  159. frames. If they are lucky they skip enough that C<Carp> goes all of
  160. the way through the call stack, realizes that something is wrong, and
  161. then generates a full stack backtrace. If they are unlucky then the
  162. error is reported from somewhere misleading very high in the call
  163. stack.
  164. Therefore it is best to avoid C<$Carp::CarpLevel>. Instead use
  165. C<@CARP_NOT>, C<%Carp::Internal> and %Carp::CarpInternal>.
  166. Defaults to C<0>.
  167. =head1 BUGS
  168. The Carp routines don't handle exception objects currently.
  169. If called with a first argument that is a reference, they simply
  170. call die() or warn(), as appropriate.