stas        02/05/12 21:47:25

  Modified:    src/docs credits.pod
               src/docs/general Changes.pod perl_reference.pod
  Log:
    o use the caller() trick instead of $^S to figure out whether we are
      inside the eval() block. [Michael G. Schwern]
  
  Revision  Changes    Path
  1.3       +2 -0      modperl-docs/src/docs/credits.pod
  
  Index: credits.pod
  ===================================================================
  RCS file: /home/cvs/modperl-docs/src/docs/credits.pod,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- credits.pod       12 May 2002 10:38:17 -0000      1.2
  +++ credits.pod       13 May 2002 04:47:24 -0000      1.3
  @@ -376,6 +376,8 @@
   
   =item * Michael Finke
   
  +=item * Michael G. Schwern
  +
   =item * Michael Hall
   
   =item * Michael Rendell
  
  
  
  1.5       +4 -1      modperl-docs/src/docs/general/Changes.pod
  
  Index: Changes.pod
  ===================================================================
  RCS file: /home/cvs/modperl-docs/src/docs/general/Changes.pod,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Changes.pod       12 May 2002 10:50:32 -0000      1.4
  +++ Changes.pod       13 May 2002 04:47:25 -0000      1.5
  @@ -17,9 +17,12 @@
   
     o inlined Mike Guy's news article about closures
   
  +  o use the caller() trick instead of $^S to figure out whether we are
  +    inside the eval() block. [Michael G. Schwern]
  +
   * correct headers.pod
   
  -  o rewrite the headers of this chapter (Per Einar Ellefsen)
  +  o rewrite the headers of this chapter [Per Einar Ellefsen]
   
   * multiuser.pod
   
  
  
  
  1.5       +28 -14    modperl-docs/src/docs/general/perl_reference.pod
  
  Index: perl_reference.pod
  ===================================================================
  RCS file: /home/cvs/modperl-docs/src/docs/general/perl_reference.pod,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- perl_reference.pod        12 May 2002 10:29:20 -0000      1.4
  +++ perl_reference.pod        13 May 2002 04:47:25 -0000      1.5
  @@ -2232,14 +2232,27 @@
   However this won't work under C<Apache::Registry> - you're always in
   an eval block there!
   
  -The other problem with C<$SIG{__DIE__}> also relates to its global nature.
  -Because you might have more than one application running under mod_perl,
  -you can't be sure which has set a C<$SIG{__DIE__}> handler when and for
  -what. This can become extremely confusing when you start scaling up
  -from a set of simple registry scripts that might rely on CGI::Carp for
  -global exception handling (which uses C<$SIG{__DIE__}> to trap exceptions)
  -to having many applications installed with a variety of exception
  -handling mechanisms in place.
  +C<$^S> isn't totally reliable in certain Perl versions.  e.g. 5.005_03
  +and 5.6.1 both do the wrong thing with it in certain situations.
  +Instead, you use can use the caller() function to figure out if we are
  +called in the eval() context:
  +
  +  $SIG{__DIE__} = sub {
  +      my $in_eval = 0;
  +      for(my $stack = 1;  my $sub = (CORE::caller($stack))[3];  $stack++) {
  +          $in_eval = 1 if $sub =~ /^\(eval\)/;
  +      }
  +      my_die_handler(@_) unless $in_eval;
  +  };
  +
  +The other problem with C<$SIG{__DIE__}> also relates to its global
  +nature.  Because you might have more than one application running
  +under mod_perl, you can't be sure which has set a C<$SIG{__DIE__}>
  +handler when and for what. This can become extremely confusing when
  +you start scaling up from a set of simple registry scripts that might
  +rely on CGI::Carp for global exception handling (which uses
  +C<$SIG{__DIE__}> to trap exceptions) to having many applications
  +installed with a variety of exception handling mechanisms in place.
   
   You should warn people about this danger of C<$SIG{__DIE__}> and
   inform them of better ways to code. The following material is an
  @@ -2255,19 +2268,20 @@
   that string into something meaningful (unless of course all you want
   your exception handler to do is dump the error to the browser). The
   other problem is that you have no way of automatically detecting where
  -the exception occurred using C<eval{}> construct. In a C<$SIG{__DIE__}>
  -block you always have the use of the caller() function to detect where
  -the error occurred. But we can fix that...
  +the exception occurred using C<eval{}> construct. In a
  +C<$SIG{__DIE__}> block you always have the use of the caller()
  +function to detect where the error occurred. But we can fix that...
   
   A little known fact about exceptions in perl 5.005 is that you can
   call die with an object. The exception handler receives that object in
   C<$@>. This is how you are advised to handle exceptions now, as it
  -provides an extremely flexible and scalable exceptions solution, potentially
  -providing almost all of the power Java exceptions.
  +provides an extremely flexible and scalable exceptions solution,
  +potentially providing almost all of the power Java exceptions.
   
   [As a footnote here, the only thing that is really missing here from
   Java exceptions is a guaranteed Finally clause, although its possible
  -to get about 98.62% of the way towards providing that using C<eval{}>.]
  +to get about 98.62% of the way towards providing that using
  +C<eval{}>.]
   
   =head3 A Little Housekeeping
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to