2 # The system variables - those indicated will need to be changed to suit your
3 # circumstances (and callsign)
5 # Copyright (c) 1998 - Dirk Koopman G1TLH
14 @EXPORT = qw(dbginit dbg dbgadd dbgsub dbglist dbgdump isdbg dbgclose confess croak cluck);
17 use vars qw(%dbglevel $fp $callback);
27 # Avoid generating "subroutine redefined" warnings with the following
28 # hack (from CGI::Carp):
29 if (!defined $DB::VERSION) {
31 eval qq( sub confess {
32 \$SIG{__DIE__} = 'DEFAULT';
34 DXDebug::dbg(Carp::shortmess(\@_));
38 \$SIG{__DIE__} = 'DEFAULT';
40 DXDebug::dbg(Carp::longmess(\@_));
43 sub carp { DXDebug::dbg(Carp::shortmess(\@_)); }
44 sub cluck { DXDebug::dbg(Carp::longmess(\@_)); }
47 CORE::die(Carp::shortmess($@)) if $@;
49 eval qq( sub confess { die Carp::longmess(\@_); };
50 sub croak { die Carp::shortmess(\@_); };
51 sub cluck { warn Carp::longmess(\@_); };
52 sub carp { warn Carp::shortmess(\@_); };
64 my @l = split /\n/, $r;
66 s/([\x00-\x08\x0B-\x1f\x7f-\xff])/uc sprintf("%%%02x",ord($1))/eg;
67 print "$_\n" if defined \*STDOUT;
69 &$callback($str) if $callback;
70 $fp->writeunix($t, $str);
79 # add sig{__DIE__} handling
80 if (!defined $DB::VERSION) {
81 $SIG{__WARN__} = sub {
82 if ($_[0] =~ /Deep\s+recursion/i) {
84 dbg(Carp::longmess(@_));
88 dbg(Carp::shortmess(@_));
92 $SIG{__DIE__} = sub { dbg($@); dbg(Carp::longmess(@_)); };
95 $fp = DXLog::new('debug', 'dat', 'd');
100 $SIG{__DIE__} = $SIG{__WARN__} = 'DEFAULT';
109 if ($fp && ($dbglevel{$l} || $l eq 'err')) {
111 for (my $o = 0; $o < length $l; $o += 16) {
112 my $c = substr $l, $o, 16;
113 my $h = unpack "H*", $c;
114 $c =~ s/[\x00-\x1f\x7f-\xff]/./g;
115 my $left = 16 - length $c;
116 $h .= ' ' x (2 * $left) if $left > 0;
117 dbg($m . sprintf("%4d:", $o) . "$h $c");
118 $m = ' ' x (length $m);
128 foreach $entry (@_) {
129 $dbglevel{$entry} = 1;
137 foreach $entry (@_) {
138 delete $dbglevel{$entry};
144 return keys (%dbglevel);
150 return $dbglevel{$_[0]};
155 return Carp::shortmess(@_);
160 return Carp::longmess(@_);