X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXDebug.pm;h=b42db66dfb4934dd9744b2f9c6fcd00f1b77e8be;hb=502f900651a46b96008028945616a3b610d6cc7a;hp=df3cb02741cef0d31b606a411358cfa4a3376de9;hpb=3eb9538d135d9ff21d8ce7c0e0c6b3e6d7fb59a9;p=spider.git diff --git a/perl/DXDebug.pm b/perl/DXDebug.pm index df3cb027..b42db66d 100644 --- a/perl/DXDebug.pm +++ b/perl/DXDebug.pm @@ -11,13 +11,11 @@ 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); -use FileHandle; use DXUtil; use DXLog (); use Carp; @@ -25,6 +23,28 @@ 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; @@ -38,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(@_)); }; } } @@ -51,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) { @@ -91,5 +112,23 @@ sub isdbg my $s = shift; return $dbglevel{$s}; } + +sub shortmess +{ + return Carp::shortmess(@_); +} + +sub longmess +{ + return Carp::longmess(@_); +} + 1; __END__ + + + + + + +