line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2001-2022 by [Mark Overmeer ]. |
2
|
|
|
|
|
|
|
# For other contributors see ChangeLog. |
3
|
|
|
|
|
|
|
# See the manual pages for details on the licensing terms. |
4
|
|
|
|
|
|
|
# Pod stripped from pm file by OODoc 2.03. |
5
|
|
|
|
|
|
|
# This code is part of distribution Mail-Message. Meta-POD processed with |
6
|
|
|
|
|
|
|
# OODoc into POD and HTML manual-pages. See README.md |
7
|
|
|
|
|
|
|
# Copyright Mark Overmeer. Licensed under the same terms as Perl itself. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Mail::Reporter; |
10
|
53
|
|
|
53
|
|
1745
|
use vars '$VERSION'; |
|
53
|
|
|
|
|
118
|
|
|
53
|
|
|
|
|
2324
|
|
11
|
|
|
|
|
|
|
$VERSION = '3.012'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
53
|
|
|
53
|
|
362
|
use strict; |
|
53
|
|
|
|
|
143
|
|
|
53
|
|
|
|
|
1191
|
|
15
|
53
|
|
|
53
|
|
279
|
use warnings; |
|
53
|
|
|
|
|
107
|
|
|
53
|
|
|
|
|
1656
|
|
16
|
|
|
|
|
|
|
|
17
|
53
|
|
|
53
|
|
376
|
use Carp; |
|
53
|
|
|
|
|
125
|
|
|
53
|
|
|
|
|
4019
|
|
18
|
53
|
|
|
53
|
|
364
|
use Scalar::Util 'dualvar'; |
|
53
|
|
|
|
|
120
|
|
|
53
|
|
|
|
|
32886
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my @levelname = (undef, qw(DEBUG NOTICE PROGRESS WARNING ERROR NONE INTERNAL)); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my %levelprio = (ERRORS => 5, WARNINGS => 4, NOTICES => 2); |
24
|
|
|
|
|
|
|
for(my $l = 1; $l < @levelname; $l++) |
25
|
|
|
|
|
|
|
{ $levelprio{$levelname[$l]} = $l; |
26
|
|
|
|
|
|
|
$levelprio{$l} = $l; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new(@) |
30
|
729
|
|
|
729
|
1
|
6709
|
{ my $class = shift; |
31
|
|
|
|
|
|
|
#confess "Parameter list has odd length: @_" if @_ % 2; |
32
|
729
|
|
|
|
|
4564
|
(bless {MR_log => 1, MR_trace => 1}, $class)->init({@_}); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my($default_log, $default_trace, $trace_callback); |
36
|
|
|
|
|
|
|
sub init($) |
37
|
711
|
|
|
711
|
0
|
1128
|
{ my ($self, $args) = @_; |
38
|
711
|
|
66
|
|
|
5296
|
$self->{MR_log} = $levelprio{$args->{log} || $default_log}; |
39
|
711
|
|
66
|
|
|
2103
|
$self->{MR_trace} = $levelprio{$args->{trace} || $default_trace}; |
40
|
711
|
|
|
|
|
1326
|
$self; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
#------------------------------------------ |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _trace_warn($$$) |
47
|
2
|
|
|
2
|
|
4
|
{ my ($who, $level, $text) = @_; |
48
|
2
|
|
|
|
|
16
|
warn "$level: $text\n"; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub defaultTrace(;$$) |
52
|
58
|
|
|
58
|
1
|
6066
|
{ my $thing = shift; |
53
|
|
|
|
|
|
|
|
54
|
58
|
100
|
|
|
|
246
|
return ($default_log, $default_trace) |
55
|
|
|
|
|
|
|
unless @_; |
56
|
|
|
|
|
|
|
|
57
|
57
|
|
|
|
|
94
|
my $level = shift; |
58
|
57
|
50
|
|
|
|
142
|
my $prio = $thing->logPriority($level) |
59
|
|
|
|
|
|
|
or croak "Unknown trace-level $level."; |
60
|
|
|
|
|
|
|
|
61
|
57
|
100
|
|
|
|
191
|
if( ! @_) |
|
|
100
|
|
|
|
|
|
62
|
54
|
|
|
|
|
97
|
{ $default_log = $default_trace = $prio; |
63
|
54
|
|
|
|
|
119
|
$trace_callback = \&_trace_warn; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
elsif(ref $_[0]) |
66
|
1
|
|
|
|
|
3
|
{ $default_log = $thing->logPriority('NONE'); |
67
|
1
|
|
|
|
|
2
|
$default_trace = $prio; |
68
|
1
|
|
|
|
|
3
|
$trace_callback = shift; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
else |
71
|
2
|
|
|
|
|
4
|
{ $default_log = $prio; |
72
|
2
|
|
|
|
|
3
|
$default_trace = $thing->logPriority(shift); |
73
|
2
|
|
|
|
|
4
|
$trace_callback = \&_trace_warn; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
57
|
|
|
|
|
146
|
($default_log, $default_trace); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__PACKAGE__->defaultTrace('WARNINGS'); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
#------------------------------------------ |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub trace(;$$) |
85
|
4
|
|
|
4
|
1
|
1564
|
{ my $self = shift; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
return $self->logPriority($self->{MR_trace}) |
88
|
4
|
100
|
|
|
|
14
|
unless @_; |
89
|
|
|
|
|
|
|
|
90
|
1
|
|
|
|
|
2
|
my $level = shift; |
91
|
1
|
50
|
|
|
|
4
|
my $prio = $levelprio{$level} |
92
|
|
|
|
|
|
|
or croak "Unknown trace-level $level."; |
93
|
|
|
|
|
|
|
|
94
|
1
|
|
|
|
|
4
|
$self->{MR_trace} = $prio; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
#------------------------------------------ |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# Implementation detail: the Mail::Box::Parser::C code avoids calls back |
101
|
|
|
|
|
|
|
# to Perl by checking the trace-level itself. In the perl code of this |
102
|
|
|
|
|
|
|
# module however, just always call the log() method, and let it check |
103
|
|
|
|
|
|
|
# whether or not to display it. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub log(;$@) |
106
|
42
|
|
|
42
|
1
|
5146
|
{ my $thing = shift; |
107
|
|
|
|
|
|
|
|
108
|
42
|
100
|
|
|
|
103
|
if(ref $thing) # instance call |
109
|
|
|
|
|
|
|
{ return $thing->logPriority($thing->{MR_log}) |
110
|
40
|
100
|
|
|
|
129
|
unless @_; |
111
|
|
|
|
|
|
|
|
112
|
37
|
|
|
|
|
53
|
my $level = shift; |
113
|
37
|
50
|
|
|
|
105
|
my $prio = $levelprio{$level} |
114
|
|
|
|
|
|
|
or croak "Unknown log-level $level"; |
115
|
|
|
|
|
|
|
|
116
|
37
|
50
|
|
|
|
87
|
return $thing->{MR_log} = $prio |
117
|
|
|
|
|
|
|
unless @_; |
118
|
|
|
|
|
|
|
|
119
|
37
|
|
|
|
|
98
|
my $text = join '', @_; |
120
|
|
|
|
|
|
|
$trace_callback->($thing, $level, $text) |
121
|
37
|
100
|
|
|
|
99
|
if $prio >= $thing->{MR_trace}; |
122
|
53
|
|
|
53
|
|
789
|
use Carp; |
|
53
|
|
|
|
|
130
|
|
|
53
|
|
|
|
|
38554
|
|
123
|
37
|
50
|
|
|
|
90
|
$thing->{MR_trace} or confess; |
124
|
|
|
|
|
|
|
|
125
|
6
|
|
|
|
|
21
|
push @{$thing->{MR_report}[$prio]}, $text |
126
|
37
|
100
|
|
|
|
97
|
if $prio >= $thing->{MR_log}; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
else # class method |
129
|
2
|
|
|
|
|
3
|
{ my $level = shift; |
130
|
2
|
50
|
|
|
|
6
|
my $prio = $levelprio{$level} |
131
|
|
|
|
|
|
|
or croak "Unknown log-level $level"; |
132
|
|
|
|
|
|
|
|
133
|
2
|
100
|
|
|
|
7
|
$trace_callback->($thing, $level, join('',@_)) |
134
|
|
|
|
|
|
|
if $prio >= $default_trace; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
39
|
|
|
|
|
91
|
$thing; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
#------------------------------------------ |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub report(;$) |
145
|
11
|
|
|
11
|
1
|
716
|
{ my $self = shift; |
146
|
11
|
|
50
|
|
|
28
|
my $reports = $self->{MR_report} || return (); |
147
|
|
|
|
|
|
|
|
148
|
11
|
100
|
|
|
|
19
|
if(@_) |
149
|
7
|
|
|
|
|
9
|
{ my $level = shift; |
150
|
7
|
50
|
|
|
|
15
|
my $prio = $levelprio{$level} |
151
|
|
|
|
|
|
|
or croak "Unknown report level $level."; |
152
|
|
|
|
|
|
|
|
153
|
7
|
50
|
|
|
|
14
|
return $reports->[$prio] ? @{$reports->[$prio]} : (); |
|
7
|
|
|
|
|
33
|
|
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
4
|
|
|
|
|
6
|
my @reports; |
157
|
4
|
|
|
|
|
9
|
for(my $prio = 1; $prio < @$reports; $prio++) |
158
|
20
|
100
|
|
|
|
38
|
{ next unless $reports->[$prio]; |
159
|
9
|
|
|
|
|
11
|
my $level = $levelname[$prio]; |
160
|
9
|
|
|
|
|
12
|
push @reports, map { [ $level, $_ ] } @{$reports->[$prio]}; |
|
12
|
|
|
|
|
30
|
|
|
9
|
|
|
|
|
13
|
|
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
4
|
|
|
|
|
11
|
@reports; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
#------------------------------------------- |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub addReport($) |
170
|
8
|
|
|
8
|
1
|
18
|
{ my ($self, $other) = @_; |
171
|
8
|
|
100
|
|
|
30
|
my $reports = $other->{MR_report} || return (); |
172
|
|
|
|
|
|
|
|
173
|
1
|
|
|
|
|
4
|
for(my $prio = 1; $prio < @$reports; $prio++) |
174
|
5
|
100
|
|
|
|
10
|
{ push @{$self->{MR_report}[$prio]}, @{$reports->[$prio]} |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
8
|
|
175
|
|
|
|
|
|
|
if exists $reports->[$prio]; |
176
|
|
|
|
|
|
|
} |
177
|
1
|
|
|
|
|
3
|
$self; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
#------------------------------------------- |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub reportAll(;$) |
184
|
2
|
|
|
2
|
1
|
1676
|
{ my $self = shift; |
185
|
2
|
|
|
|
|
5
|
map { [ $self, @$_ ] } $self->report(@_); |
|
8
|
|
|
|
|
17
|
|
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
#------------------------------------------- |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
191
|
1
|
|
|
1
|
1
|
2561
|
sub errors(@) {shift->report('ERRORS')} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
#------------------------------------------- |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
|
196
|
1
|
|
|
1
|
1
|
3
|
sub warnings(@) {shift->report('WARNINGS')} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
#------------------------------------------- |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub notImplemented(@) |
202
|
0
|
|
|
0
|
1
|
0
|
{ my $self = shift; |
203
|
0
|
|
0
|
|
|
0
|
my $package = ref $self || $self; |
204
|
0
|
|
|
|
|
0
|
my $sub = (caller 1)[3]; |
205
|
|
|
|
|
|
|
|
206
|
0
|
|
|
|
|
0
|
$self->log(ERROR => "Package $package does not implement $sub."); |
207
|
0
|
|
|
|
|
0
|
confess "Please warn the author, this shouldn't happen."; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
#------------------------------------------ |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
sub logPriority($) |
214
|
71
|
100
|
|
71
|
1
|
3284
|
{ my $level = $levelprio{$_[1]} or return undef; |
215
|
69
|
|
|
|
|
465
|
dualvar $level, $levelname[$level]; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
#------------------------------------------- |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub logSettings() |
222
|
128
|
|
|
128
|
1
|
220
|
{ my $self = shift; |
223
|
128
|
|
|
|
|
709
|
(log => $self->{MR_log}, trace => $self->{MR_trace}); |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
#------------------------------------------- |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
sub AUTOLOAD(@) |
230
|
0
|
|
|
0
|
|
0
|
{ my $thing = shift; |
231
|
0
|
|
|
|
|
0
|
our $AUTOLOAD; |
232
|
0
|
|
0
|
|
|
0
|
my $class = ref $thing || $thing; |
233
|
0
|
|
|
|
|
0
|
(my $method = $AUTOLOAD) =~ s/^.*\:\://; |
234
|
|
|
|
|
|
|
|
235
|
0
|
|
|
|
|
0
|
$Carp::MaxArgLen=20; |
236
|
0
|
|
|
|
|
0
|
confess "Method $method() is not defined for a $class.\n"; |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
#------------------------------------------- |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
#------------------------------------------- |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
|
245
|
3143
|
|
|
3143
|
|
61977
|
sub DESTROY {shift} |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
1; |