You are viewing a plain text version of this content. The canonical link for it is here.
Posted to docs-cvs@perl.apache.org by st...@apache.org on 2002/05/12 07:11:34 UTC
cvs commit: modperl-docs/src/docs/general Changes.pod perl_reference.pod
stas 02/05/11 22:11:34
Modified: src/docs/general Changes.pod perl_reference.pod
Log:
added a section on overriding functions to trace their failure.
Revision Changes Path
1.2 +4 -0 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Changes.pod 29 Apr 2002 16:48:06 -0000 1.1
+++ Changes.pod 12 May 2002 05:11:33 -0000 1.2
@@ -11,6 +11,10 @@
=head1 ???
+* perf_reference:
+
+ o added a section on overriding functions to trace their failure.
+
* started the general documents docset [Thomas Klausner]
=cut
1.3 +60 -0 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- perl_reference.pod 11 May 2002 11:54:45 -0000 1.2
+++ perl_reference.pod 12 May 2002 05:11:33 -0000 1.3
@@ -2573,6 +2573,66 @@
=back
+
+=head1 Customized __DIE__ hanlder
+
+As we saw in the previous sections it's a bad idea to do:
+
+ require Carp;
+ $SIG{__DIE__} = \&Carp::confess;
+
+since it breaks the error propogations within eval {} blocks,. But
+starting from perl 5.6.x you can use another solution to trace
+errors. For example you get an error:
+
+ "exit" is not exported by the GLOB(0x88414cc) module at (eval 397) line 1
+
+and you have no clue where it comes from, you can override the exit()
+function and plug the tracer inside:
+
+ require Carp;
+ use subs qw(CORE::GLOBAL::die);
+ *CORE::GLOBAL::die = sub {
+ if ($_[0] =~ /"exit" is not exported/){
+ local *CORE::GLOBAL::die = sub { CORE::die(@_) };
+ Carp::confess(@_); # Carp uses die() internally!
+ } else {
+ CORE::die(@_); # could write &CORE::die to forward @_
+ }
+ };
+
+Now we can test that it works properly without breaking the eval {}
+blocks error propogation:
+
+ eval { foo(); }; warn $@ if $@;
+ print "\n";
+ eval { poo(); }; warn $@ if $@;
+
+ sub foo{ bar(); }
+ sub bar{ die qq{"exit" is not exported}}
+
+ sub poo{ tar(); }
+ sub tar{ die "normal exit"}
+
+prints:
+
+ $ perl -w test
+ Subroutine die redefined at test line 5.
+ "exit" is not exported at test line 6
+ main::__ANON__('"exit" is not exported') called at test line 17
+ main::bar() called at test line 16
+ main::foo() called at test line 12
+ eval {...} called at test line 12
+
+ normal exit at test line 5.
+
+the 'local' in:
+
+ local *CORE::GLOBAL::die = sub { CORE::die(@_) };
+
+is important, so you won't lose the overloaded C<CORE::GLOBAL::die>.
+
+
=head1 Maintainers
Maintainer is the person(s) you should contact with updates,
---------------------------------------------------------------------
To unsubscribe, e-mail: docs-cvs-unsubscribe@perl.apache.org
For additional commands, e-mail: docs-cvs-help@perl.apache.org