+# Avoid generating "subroutine redefined" warnings with the following
+# hack (from CGI::Carp):
+if (!defined $DB::VERSION) {
+ local $^W=0;
+ eval qq( sub confess {
+ \$SIG{__DIE__} = 'DEFAULT';
+ DXDebug::_store(Carp::longmess(\@_));
+ exit(-1);
+ }
+ sub confess {
+ \$SIG{__DIE__} = 'DEFAULT';
+ DXDebug::_store(Carp::shortmess(\@_));
+ exit(-1);
+ }
+ sub carp { DXDebug::_store(Carp::shortmess(\@_)); }
+ sub cluck { DXDebug::_store(Carp::longmess(\@_)); }
+ );
+
+ CORE::die(Carp::shortmess($@)) if $@;
+}
+
+
+sub _store
+{
+ my $t = time;
+ for (@_) {
+ $fp->writeunix($t, "$t^$_");
+ print STDERR $_;
+ }
+}
+
+sub dbginit
+{
+ # add sig{__DIE__} handling
+ if (!defined $DB::VERSION) {
+ $SIG{__WARN__} = sub { _store(Carp::shortmess(@_)); };
+ $SIG{__DIE__} = sub { _store(Carp::shortmess(@_)); };
+ }
+}
+
+sub dbgclose
+{
+ $SIG{__DIE__} = $SIG{__WARN__} = 'DEFAULT';
+ $fp->close();
+}
+