]> dxcluster.net Git - spider.git/blob - perl/DXDebug.pm
tidy up listdups so regexes now work again
[spider.git] / perl / DXDebug.pm
1 #
2 # The system variables - those indicated will need to be changed to suit your
3 # circumstances (and callsign)
4 #
5 # Copyright (c) 1998 - Dirk Koopman G1TLH
6 #
7 # $Id$
8 #
9
10 package DXDebug;
11
12 require Exporter;
13 @ISA = qw(Exporter);
14 @EXPORT = qw(dbginit dbg dbgadd dbgsub dbglist isdbg dbgclose confess croak cluck cluck);
15
16 use strict;
17 use vars qw(%dbglevel $fp);
18
19 use DXUtil;
20 use DXLog ();
21 use Carp qw(cluck);
22
23 %dbglevel = ();
24 $fp = DXLog::new('debug', 'dat', 'd');
25
26 # Avoid generating "subroutine redefined" warnings with the following
27 # hack (from CGI::Carp):
28 if (!defined $DB::VERSION) {
29         local $^W=0;
30         eval qq( sub confess { 
31             \$SIG{__DIE__} = 'DEFAULT'; 
32         DXDebug::_store(\$@, Carp::shortmess(\@_));
33             exit(-1); 
34         }
35         sub croak { 
36                 \$SIG{__DIE__} = 'DEFAULT'; 
37         DXDebug::_store(\$@, Carp::longmess(\@_));
38                 exit(-1); 
39         }
40         sub carp    { DXDebug::_store(Carp::shortmess(\@_)); }
41         sub cluck   { DXDebug::_store(Carp::longmess(\@_)); } 
42         );
43
44     CORE::die(Carp::shortmess($@)) if $@;
45 } else {
46     eval qq( sub confess { Carp::confess(\@_); }; 
47         sub cluck { Carp::cluck(\@_); }; 
48    );
49
50
51
52 sub _store
53 {
54         my $t = time; 
55         for (@_) {
56                 chomp;
57                 my @l = split /\n/;
58                 for (@l) {
59                         my $l = $_;
60                         $l =~ s/([\x00\x08\x0B-\x1f\x7f-\xff])/uc sprintf("%%%02x",ord($1))/eg;                 
61                         print "$_\n" if defined \*STDOUT;
62                         $fp->writeunix($t, "$t^$_"); 
63                 }
64         }
65 }
66
67 sub dbginit
68 {
69         # add sig{__DIE__} handling
70         if (!defined $DB::VERSION) {
71                 $SIG{__WARN__} = sub { _store($@, Carp::shortmess(@_)); };
72                 $SIG{__DIE__} = sub { _store($@, Carp::longmess(@_)); };
73         }
74 }
75
76 sub dbgclose
77 {
78         $SIG{__DIE__} = $SIG{__WARN__} = 'DEFAULT';
79         $fp->close();
80 }
81
82 sub dbg
83 {
84         my $l = shift;
85         if ($dbglevel{$l} || $l eq 'err') {
86             my @in = @_;
87                 my $t = time;
88                 for (@in) {
89                     s/\n$//o;
90                         s/\a//og;   # beeps
91                         print "$_\n" if defined \*STDOUT;
92                         $fp->writeunix($t, "$t^$_");
93                 }
94         }
95 }
96
97 sub dbgadd
98
99         my $entry;
100         
101         foreach $entry (@_) {
102                 $dbglevel{$entry} = 1;
103         }
104 }
105
106 sub dbgsub
107 {
108         my $entry;
109         
110         foreach $entry (@_) {
111                 delete $dbglevel{$entry};
112         }
113 }
114
115 sub dbglist
116 {
117         return keys (%dbglevel);
118 }
119
120 sub isdbg
121 {
122         my $s = shift;
123         return $dbglevel{$s};
124 }
125
126 sub shortmess 
127 {
128         return Carp::shortmess(@_);
129 }
130
131 sub longmess 
132
133         return Carp::longmess(@_);
134 }
135
136 1;
137 __END__
138
139
140
141
142
143
144