line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################################## |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# This library is free software; you can redistribute it and/or |
4
|
|
|
|
|
|
|
# modify it under the terms of the GNU Library General Public |
5
|
|
|
|
|
|
|
# License as published by the Free Software Foundation; either |
6
|
|
|
|
|
|
|
# version 2 of the License, or (at your option) any later version. |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# This library is distributed in the hope that it will be useful, |
9
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
11
|
|
|
|
|
|
|
# Library General Public License for more details. |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# You should have received a copy of the GNU Library General Public |
14
|
|
|
|
|
|
|
# License along with this library; if not, write to the |
15
|
|
|
|
|
|
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
16
|
|
|
|
|
|
|
# Boston, MA 02111-1307, USA. |
17
|
|
|
|
|
|
|
# |
18
|
|
|
|
|
|
|
# Copyright (C) 1998-2004 Jabber Software Foundation http://jabber.org/ |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
############################################################################## |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
package Net::XMPP3::Debug; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 NAME |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Net::XMPP3::Debug - XMPP Debug Module |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 SYNOPSIS |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Net::XMPP3::Debug is a module that provides a developer easy access |
31
|
|
|
|
|
|
|
to logging debug information. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 DESCRIPTION |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Debug is a helper module for the Net::XMPP3 modules. It provides |
36
|
|
|
|
|
|
|
the Net::XMPP3 modules with an object to control where, how, and |
37
|
|
|
|
|
|
|
what is logged. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 Basic Functions |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$Debug = new Net::XMPP3::Debug(); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$Debug->Init(level=>2, |
44
|
|
|
|
|
|
|
file=>"stdout", |
45
|
|
|
|
|
|
|
header=>"MyScript"); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$Debug->Log0("Connection established"); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 METHODS |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 Basic Functions |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
new(hash) - creates the Debug object. The hash argument is passed |
54
|
|
|
|
|
|
|
to the Init function. See that function description |
55
|
|
|
|
|
|
|
below for the valid settings. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Init(level=>integer, - initializes the debug object. The level |
58
|
|
|
|
|
|
|
file=>string, determines the maximum level of debug |
59
|
|
|
|
|
|
|
header=>string, messages to log: |
60
|
|
|
|
|
|
|
setdefault=>0|1, 0 - Base level Output (default) |
61
|
|
|
|
|
|
|
usedefault=>0|1, 1 - High level API calls |
62
|
|
|
|
|
|
|
time=>0|1) 2 - Low level API calls |
63
|
|
|
|
|
|
|
... |
64
|
|
|
|
|
|
|
N - Whatever you want.... |
65
|
|
|
|
|
|
|
The file determines where the debug log |
66
|
|
|
|
|
|
|
goes. You can either specify a path to |
67
|
|
|
|
|
|
|
a file, or "stdout" (the default). "stdout" |
68
|
|
|
|
|
|
|
tells Debug to send all of the debug info |
69
|
|
|
|
|
|
|
sent to this object to go to stdout. |
70
|
|
|
|
|
|
|
header is a string that will preappended |
71
|
|
|
|
|
|
|
to the beginning of all log entries. This |
72
|
|
|
|
|
|
|
makes it easier to see what generated the |
73
|
|
|
|
|
|
|
log entry (default is "Debug"). |
74
|
|
|
|
|
|
|
setdefault saves the current filehandle |
75
|
|
|
|
|
|
|
and makes it available for other Debug |
76
|
|
|
|
|
|
|
objects to use. To use the default set |
77
|
|
|
|
|
|
|
usedefault to 1. The time parameter |
78
|
|
|
|
|
|
|
specifies whether or not to add a timestamp |
79
|
|
|
|
|
|
|
to the beginning of each logged line. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
LogN(array) - Logs the elements of the array at the corresponding |
82
|
|
|
|
|
|
|
debug level N. If you pass in a reference to an |
83
|
|
|
|
|
|
|
array or hash then they are printed in a readable |
84
|
|
|
|
|
|
|
way. (ie... Log0, Log2, Log100, etc...) |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 EXAMPLE |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
$Debug = new Net::XMPP3:Debug(level=>2, |
89
|
|
|
|
|
|
|
header=>"Example"); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$Debug->Log0("test"); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$Debug->Log2("level 2 test"); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$hash{a} = "atest"; |
96
|
|
|
|
|
|
|
$hash{b} = "btest"; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
$Debug->Log1("hashtest",\%hash); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
You would get the following log: |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Example: test |
103
|
|
|
|
|
|
|
Example: level 2 test |
104
|
|
|
|
|
|
|
Example: hashtest { a=>"atest" b=>"btest" } |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
If you had set the level to 1 instead of 2 you would get: |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Example: test |
109
|
|
|
|
|
|
|
Example: hashtest { a=>"atest" b=>"btest" } |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 AUTHOR |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Ryan Eatmon |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 COPYRIGHT |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This module is free software, you can redistribute it and/or modify it |
118
|
|
|
|
|
|
|
under the LGPL. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
require 5.003; |
123
|
11
|
|
|
11
|
|
74
|
use strict; |
|
11
|
|
|
|
|
21
|
|
|
11
|
|
|
|
|
669
|
|
124
|
11
|
|
|
11
|
|
64
|
use FileHandle; |
|
11
|
|
|
|
|
20
|
|
|
11
|
|
|
|
|
92
|
|
125
|
11
|
|
|
11
|
|
4555
|
use Carp; |
|
11
|
|
|
|
|
21
|
|
|
11
|
|
|
|
|
714
|
|
126
|
11
|
|
|
11
|
|
55
|
use vars qw( %HANDLES $DEFAULT $DEFAULTLEVEL $DEFAULTTIME $AUTOLOAD ); |
|
11
|
|
|
|
|
21
|
|
|
11
|
|
|
|
|
14611
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
$DEFAULTLEVEL = -1; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub new |
131
|
|
|
|
|
|
|
{ |
132
|
18
|
|
|
18
|
0
|
14778
|
my $proto = shift; |
133
|
18
|
|
|
|
|
52
|
my $self = { }; |
134
|
18
|
|
|
|
|
60
|
bless($self, $proto); |
135
|
|
|
|
|
|
|
|
136
|
18
|
|
|
|
|
105
|
$self->Init(@_); |
137
|
|
|
|
|
|
|
|
138
|
18
|
|
|
|
|
61
|
return $self; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
############################################################################## |
143
|
|
|
|
|
|
|
# |
144
|
|
|
|
|
|
|
# Init - opens the fielhandle and initializes the Debug object. |
145
|
|
|
|
|
|
|
# |
146
|
|
|
|
|
|
|
############################################################################## |
147
|
|
|
|
|
|
|
sub Init |
148
|
|
|
|
|
|
|
{ |
149
|
18
|
|
|
18
|
0
|
39
|
my $self = shift; |
150
|
|
|
|
|
|
|
|
151
|
18
|
|
|
|
|
37
|
my %args; |
152
|
18
|
|
|
|
|
101
|
while($#_ >= 0) { $args{ lc pop(@_) } = pop(@_); } |
|
51
|
|
|
|
|
228
|
|
153
|
|
|
|
|
|
|
|
154
|
18
|
100
|
|
|
|
106
|
delete($args{file}) if (lc($args{file}) eq "stdout"); |
155
|
|
|
|
|
|
|
|
156
|
18
|
100
|
|
|
|
98
|
$args{time} = 0 if !exists($args{time}); |
157
|
18
|
100
|
|
|
|
92
|
$args{setdefault} = 0 if !exists($args{setdefault}); |
158
|
18
|
100
|
|
|
|
91
|
$args{usedefault} = 0 if !exists($args{usedefault}); |
159
|
|
|
|
|
|
|
|
160
|
18
|
|
|
|
|
152
|
$self->{TIME} = $args{time}; |
161
|
|
|
|
|
|
|
|
162
|
18
|
100
|
|
|
|
80
|
if ($args{usedefault} == 1) |
163
|
|
|
|
|
|
|
{ |
164
|
11
|
|
|
|
|
30
|
$args{setdefault} = 0; |
165
|
11
|
|
|
|
|
37
|
$self->{USEDEFAULT} = 1; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
else |
168
|
|
|
|
|
|
|
{ |
169
|
7
|
|
|
|
|
22
|
$self->{LEVEL} = 0; |
170
|
7
|
50
|
|
|
|
42
|
$self->{LEVEL} = $args{level} if exists($args{level}); |
171
|
|
|
|
|
|
|
|
172
|
7
|
|
|
|
|
75
|
$self->{HANDLE} = new FileHandle(">&STDERR"); |
173
|
7
|
|
|
|
|
596
|
$self->{HANDLE}->autoflush(1); |
174
|
7
|
50
|
|
|
|
419
|
if (exists($args{file})) |
175
|
|
|
|
|
|
|
{ |
176
|
0
|
0
|
|
|
|
0
|
if (exists($Net::XMPP3::Debug::HANDLES{$args{file}})) |
177
|
|
|
|
|
|
|
{ |
178
|
0
|
|
|
|
|
0
|
$self->{HANDLE} = $Net::XMPP3::Debug::HANDLES{$args{file}}; |
179
|
0
|
|
|
|
|
0
|
$self->{HANDLE}->autoflush(1); |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
else |
182
|
|
|
|
|
|
|
{ |
183
|
0
|
0
|
|
|
|
0
|
if (-e $args{file}) |
184
|
|
|
|
|
|
|
{ |
185
|
0
|
0
|
|
|
|
0
|
if (-w $args{file}) |
186
|
|
|
|
|
|
|
{ |
187
|
0
|
|
|
|
|
0
|
$self->{HANDLE} = new FileHandle(">$args{file}"); |
188
|
0
|
0
|
|
|
|
0
|
if (defined($self->{HANDLE})) |
189
|
|
|
|
|
|
|
{ |
190
|
0
|
|
|
|
|
0
|
$self->{HANDLE}->autoflush(1); |
191
|
0
|
|
|
|
|
0
|
$Net::XMPP3::Debug::HANDLES{$args{file}} = $self->{HANDLE}; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
else |
194
|
|
|
|
|
|
|
{ |
195
|
0
|
|
|
|
|
0
|
print STDERR "ERROR: Debug filehandle could not be opened.\n"; |
196
|
0
|
|
|
|
|
0
|
print STDERR" Debugging disabled.\n"; |
197
|
0
|
|
|
|
|
0
|
print STDERR " ($!)\n"; |
198
|
0
|
|
|
|
|
0
|
$self->{LEVEL} = -1; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
else |
202
|
|
|
|
|
|
|
{ |
203
|
0
|
|
|
|
|
0
|
print STDERR "ERROR: You do not have permission to write to $args{file}.\n"; |
204
|
0
|
|
|
|
|
0
|
print STDERR" Debugging disabled.\n"; |
205
|
0
|
|
|
|
|
0
|
$self->{LEVEL} = -1; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
else |
209
|
|
|
|
|
|
|
{ |
210
|
0
|
|
|
|
|
0
|
$self->{HANDLE} = new FileHandle(">$args{file}"); |
211
|
0
|
0
|
|
|
|
0
|
if (defined($self->{HANDLE})) |
212
|
|
|
|
|
|
|
{ |
213
|
0
|
|
|
|
|
0
|
$self->{HANDLE}->autoflush(1); |
214
|
0
|
|
|
|
|
0
|
$Net::XMPP3::Debug::HANDLES{$args{file}} = $self->{HANDLE}; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
else |
217
|
|
|
|
|
|
|
{ |
218
|
0
|
|
|
|
|
0
|
print STDERR "ERROR: Debug filehandle could not be opened.\n"; |
219
|
0
|
|
|
|
|
0
|
print STDERR" Debugging disabled.\n"; |
220
|
0
|
|
|
|
|
0
|
print STDERR " ($!)\n"; |
221
|
0
|
|
|
|
|
0
|
$self->{LEVEL} = -1; |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
} |
227
|
18
|
100
|
|
|
|
86
|
if ($args{setdefault} == 1) |
228
|
|
|
|
|
|
|
{ |
229
|
7
|
|
|
|
|
20
|
$Net::XMPP3::Debug::DEFAULT = $self->{HANDLE}; |
230
|
7
|
|
|
|
|
24
|
$Net::XMPP3::Debug::DEFAULTLEVEL = $self->{LEVEL}; |
231
|
7
|
|
|
|
|
18
|
$Net::XMPP3::Debug::DEFAULTTIME = $self->{TIME}; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
18
|
|
|
|
|
53
|
$self->{HEADER} = "Debug"; |
235
|
18
|
50
|
|
|
|
127
|
$self->{HEADER} = $args{header} if exists($args{header}); |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
############################################################################## |
240
|
|
|
|
|
|
|
# |
241
|
|
|
|
|
|
|
# Log - takes the limit and the array to log and logs them |
242
|
|
|
|
|
|
|
# |
243
|
|
|
|
|
|
|
############################################################################## |
244
|
|
|
|
|
|
|
sub Log |
245
|
|
|
|
|
|
|
{ |
246
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
247
|
0
|
|
|
|
|
0
|
my (@args) = @_; |
248
|
|
|
|
|
|
|
|
249
|
0
|
|
|
|
|
0
|
my $fh = $self->{HANDLE}; |
250
|
0
|
0
|
|
|
|
0
|
$fh = $Net::XMPP3::Debug::DEFAULT if exists($self->{USEDEFAULT}); |
251
|
|
|
|
|
|
|
|
252
|
0
|
|
|
|
|
0
|
my $string = ""; |
253
|
|
|
|
|
|
|
|
254
|
0
|
|
|
|
|
0
|
my $testTime = $self->{TIME}; |
255
|
0
|
0
|
|
|
|
0
|
$testTime = $Net::XMPP3::Debug::DEFAULTTIME if exists($self->{USEDEFAULT}); |
256
|
|
|
|
|
|
|
|
257
|
0
|
0
|
|
|
|
0
|
$string .= "[".&Net::XMPP3::GetTimeStamp("local",time,"short")."] " |
258
|
|
|
|
|
|
|
if ($testTime == 1); |
259
|
0
|
|
|
|
|
0
|
$string .= $self->{HEADER}.": "; |
260
|
|
|
|
|
|
|
|
261
|
0
|
|
|
|
|
0
|
my $arg; |
262
|
|
|
|
|
|
|
|
263
|
0
|
|
|
|
|
0
|
foreach $arg (@args) |
264
|
|
|
|
|
|
|
{ |
265
|
0
|
0
|
|
|
|
0
|
if (ref($arg) eq "HASH") |
266
|
|
|
|
|
|
|
{ |
267
|
0
|
|
|
|
|
0
|
$string .= " {"; |
268
|
0
|
|
|
|
|
0
|
my $key; |
269
|
0
|
|
|
|
|
0
|
foreach $key (sort {$a cmp $b} keys(%{$arg})) |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
270
|
|
|
|
|
|
|
{ |
271
|
0
|
|
|
|
|
0
|
$string .= " ".$key."=>'".$arg->{$key}."'"; |
272
|
|
|
|
|
|
|
} |
273
|
0
|
|
|
|
|
0
|
$string .= " }"; |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
else |
276
|
|
|
|
|
|
|
{ |
277
|
0
|
0
|
|
|
|
0
|
if (ref($arg) eq "ARRAY") |
278
|
|
|
|
|
|
|
{ |
279
|
0
|
|
|
|
|
0
|
$string .= " [ ".join(" ",@{$arg})." ]"; |
|
0
|
|
|
|
|
0
|
|
280
|
|
|
|
|
|
|
} else { |
281
|
0
|
|
|
|
|
0
|
$string .= $arg; |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
} |
284
|
|
|
|
|
|
|
} |
285
|
0
|
|
|
|
|
0
|
print $fh "$string\n"; |
286
|
0
|
|
|
|
|
0
|
return 1; |
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
############################################################################## |
291
|
|
|
|
|
|
|
# |
292
|
|
|
|
|
|
|
# AUTOLOAD - if a function is called that is not defined then this function |
293
|
|
|
|
|
|
|
# will examine the function name and either give an error or call |
294
|
|
|
|
|
|
|
# the appropriate function. |
295
|
|
|
|
|
|
|
# |
296
|
|
|
|
|
|
|
############################################################################## |
297
|
|
|
|
|
|
|
sub AUTOLOAD |
298
|
|
|
|
|
|
|
{ |
299
|
2015
|
|
|
2015
|
|
3133
|
my $self = shift; |
300
|
2015
|
50
|
|
|
|
5914
|
return if ($AUTOLOAD =~ /::DESTROY$/); |
301
|
2015
|
|
|
|
|
9533
|
my ($function) = ($AUTOLOAD =~ /\:\:(.*)$/); |
302
|
2015
|
50
|
|
|
|
8164
|
croak("$function not defined") if !($function =~ /Log\d+/); |
303
|
2015
|
|
|
|
|
6471
|
my ($level) = ($function =~ /Log(\d+)/); |
304
|
2015
|
100
|
|
|
|
18563
|
return 0 if ($level > (exists($self->{USEDEFAULT}) ? $Net::XMPP3::Debug::DEFAULTLEVEL : $self->{LEVEL})); |
|
|
50
|
|
|
|
|
|
305
|
0
|
|
|
|
|
0
|
$self->Log(@_); |
306
|
|
|
|
|
|
|
} |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
############################################################################## |
310
|
|
|
|
|
|
|
# |
311
|
|
|
|
|
|
|
# GetHandle - returns the filehandle being used by this object. |
312
|
|
|
|
|
|
|
# |
313
|
|
|
|
|
|
|
############################################################################## |
314
|
|
|
|
|
|
|
sub GetHandle |
315
|
|
|
|
|
|
|
{ |
316
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
317
|
1
|
|
|
|
|
7
|
return $self->{HANDLE}; |
318
|
|
|
|
|
|
|
} |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
############################################################################## |
322
|
|
|
|
|
|
|
# |
323
|
|
|
|
|
|
|
# GetLevel - returns the debug level used by this object. |
324
|
|
|
|
|
|
|
# |
325
|
|
|
|
|
|
|
############################################################################## |
326
|
|
|
|
|
|
|
sub GetLevel |
327
|
|
|
|
|
|
|
{ |
328
|
1
|
|
|
1
|
0
|
145
|
my $self = shift; |
329
|
1
|
|
|
|
|
7
|
return $self->{LEVEL}; |
330
|
|
|
|
|
|
|
} |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
############################################################################## |
334
|
|
|
|
|
|
|
# |
335
|
|
|
|
|
|
|
# GetTime - returns the debug time used by this object. |
336
|
|
|
|
|
|
|
# |
337
|
|
|
|
|
|
|
############################################################################## |
338
|
|
|
|
|
|
|
sub GetTime |
339
|
|
|
|
|
|
|
{ |
340
|
1
|
|
|
1
|
0
|
4
|
my $self = shift; |
341
|
1
|
|
|
|
|
12
|
return $self->{TIME}; |
342
|
|
|
|
|
|
|
} |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
1; |