X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXDebug.pm;fp=perl%2FDXDebug.pm;h=b42db66dfb4934dd9744b2f9c6fcd00f1b77e8be;hb=0bd9d2811cc42417676a1b11b121681c2377d70a;hp=80ef17ef3336f6fb9fb9bb8407a8649ae7b79696;hpb=da56601b23d5e19b5df80fe1248e5477f5b6de6b;p=spider.git diff --git a/perl/DXDebug.pm b/perl/DXDebug.pm index 80ef17ef..b42db66d 100644 --- a/perl/DXDebug.pm +++ b/perl/DXDebug.pm @@ -11,8 +11,7 @@ package DXDebug; require Exporter; @ISA = qw(Exporter); -@EXPORT = qw(dbginit dbg dbgadd dbgsub dbglist isdbg dbgclose); -@EXPORT_OK = qw(dbginit dbg dbgadd dbgsub dbglist isdbg dbgclose); +@EXPORT = qw(dbginit dbg dbgadd dbgsub dbglist isdbg dbgclose confess croak cluck cluck); use strict; use vars qw(%dbglevel $fp); @@ -24,11 +23,31 @@ use Carp; %dbglevel = (); $fp = DXLog::new('debug', 'dat', 'd'); +# 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; - $fp->writeunix($t, "$t^$@") if $@; - $fp->writeunix($t, "$t^$!") if $!; for (@_) { $fp->writeunix($t, "$t^$_"); print STDERR $_; @@ -39,7 +58,8 @@ sub dbginit { # add sig{__DIE__} handling if (!defined $DB::VERSION) { - $SIG{__WARN__} = $SIG{__DIE__} = \&_store; + $SIG{__WARN__} = sub { _store(Carp::shortmess(@_)); }; + $SIG{__DIE__} = sub { _store(Carp::shortmess(@_)); }; } } @@ -52,7 +72,7 @@ sub dbgclose sub dbg { my $l = shift; - if ($dbglevel{$l}) { + if ($dbglevel{$l} || $l eq 'err') { my @in = @_; my $t = time; for (@in) { @@ -92,5 +112,23 @@ sub isdbg my $s = shift; return $dbglevel{$s}; } + +sub shortmess +{ + return Carp::shortmess(@_); +} + +sub longmess +{ + return Carp::longmess(@_); +} + 1; __END__ + + + + + + +