| 1 | # Copyrights 2001-2023 by [Mark Overmeer <markov@cpan.org>]. | ||||||||||||||||||||
| 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 | 56 | ▶ | use vars '$VERSION'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 56 | $VERSION = '3.013'; | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 56 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 56 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 56 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | 56 | ▶ | use Scalar::Util 'dualvar'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 56 | my @levelname = (undef, qw(DEBUG NOTICE PROGRESS WARNING ERROR NONE INTERNAL)); | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 56 | my %levelprio = (ERRORS => 5, WARNINGS => 4, NOTICES => 2); | |||||||||||||||||||
| 24 | 56 | ▶ | for(my $l = 1; $l < @levelname; $l++) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 25 | 392 | { $levelprio{$levelname[$l]} = $l; | |||||||||||||||||||
| 26 | 392 | $levelprio{$l} = $l; | |||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | sub new(@) | ||||||||||||||||||||
| 30 | 863 | ▶ | { my $class = shift; | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 31 | #confess "Parameter list has odd length: @_" if @_ % 2; | ||||||||||||||||||||
| 32 | 863 | (bless {MR_log => 1, MR_trace => 1}, $class)->init({@_}); | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 56 | my($default_log, $default_trace, $trace_callback); | |||||||||||||||||||
| 36 | sub init($) | ||||||||||||||||||||
| 37 | 845 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||
|
Subroutine
init: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||
| 38 | 845 | ▶ | $self->{MR_log} = $levelprio{$args->{log} || $default_log}; | ||||||||||||||||||
|
Condition66%2/3
$args->{'log'} || $default_log
MC/DC0%0/2
$args->{'log'} || $default_log
$args->{'log'}
$default_log
Truth table66%2/3
A || B
A= $args->{'log'}B= $default_log
| |||||||||||||||||||||
| 39 | 845 | ▶ | $self->{MR_trace} = $levelprio{$args->{trace} || $default_trace}; | ||||||||||||||||||
|
Condition66%2/3
$args->{'trace'} || $default_trace
MC/DC0%0/2
$args->{'trace'} || $default_trace
$args->{'trace'}
$default_trace
Truth table66%2/3
A || B
A= $args->{'trace'}B= $default_trace
| |||||||||||||||||||||
| 40 | 845 | $self; | |||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | #------------------------------------------ | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | sub _trace_warn($$$) | ||||||||||||||||||||
| 47 | 2 | ▶ | { my ($who, $level, $text) = @_; | ||||||||||||||||||
|
Subroutine
_trace_warn: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 48 | 2 | warn "$level: $text\n"; | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | sub defaultTrace(;$$) | ||||||||||||||||||||
| 52 | 61 | ▶ | { my $thing = shift; | ||||||||||||||||||
|
Subroutine
defaultTrace: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 61 | ▶ | return ($default_log, $default_trace) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 55 | unless @_; | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 60 | my $level = shift; | |||||||||||||||||||
| 58 | 60 | ▶ | my $prio = $thing->logPriority($level) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | or croak "Unknown trace-level $level."; | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 60 | ▶ | if( ! @_) | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 62 | 57 | { $default_log = $default_trace = $prio; | |||||||||||||||||||
| 63 | 57 | $trace_callback = \&_trace_warn; | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | elsif(ref $_[0]) | ||||||||||||||||||||
| 66 | 1 | { $default_log = $thing->logPriority('NONE'); | |||||||||||||||||||
| 67 | 1 | $default_trace = $prio; | |||||||||||||||||||
| 68 | 1 | $trace_callback = shift; | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | else | ||||||||||||||||||||
| 71 | 2 | { $default_log = $prio; | |||||||||||||||||||
| 72 | 2 | $default_trace = $thing->logPriority(shift); | |||||||||||||||||||
| 73 | 2 | $trace_callback = \&_trace_warn; | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 60 | ($default_log, $default_trace); | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 56 | __PACKAGE__->defaultTrace('WARNINGS'); | |||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | #------------------------------------------ | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | sub trace(;$$) | ||||||||||||||||||||
| 85 | 4 | ▶ | { my $self = shift; | ||||||||||||||||||
|
Subroutine
trace: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | return $self->logPriority($self->{MR_trace}) | ||||||||||||||||||||
| 88 | 4 | ▶ | unless @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 1 | my $level = shift; | |||||||||||||||||||
| 91 | 1 | ▶ | my $prio = $levelprio{$level} | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 92 | or croak "Unknown trace-level $level."; | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 1 | $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 | 57 | ▶ | { my $thing = shift; | ||||||||||||||||||
|
Subroutine
log: called CC=10 SCAR=23.2
Pod
documented
| |||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 57 | ▶ | if(ref $thing) # instance call | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 109 | { return $thing->logPriority($thing->{MR_log}) | ||||||||||||||||||||
| 110 | 55 | ▶ | unless @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | 52 | my $level = shift; | |||||||||||||||||||
| 113 | 52 | ▶ | my $prio = $levelprio{$level} | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 114 | or croak "Unknown log-level $level"; | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | 52 | ▶ | return $thing->{MR_log} = $prio | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 117 | unless @_; | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | 52 | my $text = join '', @_; | |||||||||||||||||||
| 120 | $trace_callback->($thing, $level, $text) | ||||||||||||||||||||
| 121 | 52 | ▶ | if $prio >= $thing->{MR_trace}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 122 | 56 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 123 | 52 | ▶ | $thing->{MR_trace} or confess; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | 6 | push @{$thing->{MR_report}[$prio]}, $text | |||||||||||||||||||
| 126 | 52 | ▶ | if $prio >= $thing->{MR_log}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 127 | } | ||||||||||||||||||||
| 128 | else # class method | ||||||||||||||||||||
| 129 | 2 | { my $level = shift; | |||||||||||||||||||
| 130 | 2 | ▶ | my $prio = $levelprio{$level} | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 131 | or croak "Unknown log-level $level"; | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | 2 | ▶ | $trace_callback->($thing, $level, join('',@_)) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 134 | if $prio >= $default_trace; | ||||||||||||||||||||
| 135 | } | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | 54 | $thing; | |||||||||||||||||||
| 138 | } | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | #------------------------------------------ | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | sub report(;$) | ||||||||||||||||||||
| 145 | 11 | ▶ | { my $self = shift; | ||||||||||||||||||
|
Subroutine
report: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||
| 146 | 11 | ▶ | my $reports = $self->{MR_report} || return (); | ||||||||||||||||||
|
Condition50%1/2
$self->{'MR_report'} || (return ())
MC/DC0%0/1
$self->{'MR_report'} || (return ())
$self->{'MR_report'}
Truth table50%1/2
A
A= $self->{'MR_report'}
| |||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | 11 | ▶ | if(@_) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 149 | 7 | { my $level = shift; | |||||||||||||||||||
| 150 | 7 | ▶ | my $prio = $levelprio{$level} | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 151 | or croak "Unknown report level $level."; | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | 7 | ▶ | return $reports->[$prio] ? @{$reports->[$prio]} : (); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 154 | } | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | 4 | my @reports; | |||||||||||||||||||
| 157 | 4 | ▶ | for(my $prio = 1; $prio < @$reports; $prio++) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 158 | 20 | ▶ | { next unless $reports->[$prio]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 159 | 9 | my $level = $levelname[$prio]; | |||||||||||||||||||
| 160 | 9 | push @reports, map { [ $level, $_ ] } @{$reports->[$prio]}; | |||||||||||||||||||
| 161 | } | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | 4 | @reports; | |||||||||||||||||||
| 164 | } | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | #------------------------------------------- | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | sub addReport($) | ||||||||||||||||||||
| 170 | 13 | ▶ | { my ($self, $other) = @_; | ||||||||||||||||||
|
Subroutine
addReport: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||
| 171 | 13 | ▶ | my $reports = $other->{MR_report} || return (); | ||||||||||||||||||
|
Condition100%2/2
$other->{'MR_report'} || (return ())
MC/DC100%1/1
$other->{'MR_report'} || (return ())
$other->{'MR_report'}
Truth table100%2/2
A
A= $other->{'MR_report'}
| |||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | 1 | ▶ | for(my $prio = 1; $prio < @$reports; $prio++) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 174 | 5 | ▶ | { push @{$self->{MR_report}[$prio]}, @{$reports->[$prio]} | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 175 | if exists $reports->[$prio]; | ||||||||||||||||||||
| 176 | } | ||||||||||||||||||||
| 177 | 1 | $self; | |||||||||||||||||||
| 178 | } | ||||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | #------------------------------------------- | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | sub reportAll(;$) | ||||||||||||||||||||
| 184 | 2 | ▶ | { my $self = shift; | ||||||||||||||||||
|
Subroutine
reportAll: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 185 | 2 | map { [ $self, @$_ ] } $self->report(@_); | |||||||||||||||||||
| 186 | } | ||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | #------------------------------------------- | ||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | |||||||||||||||||||||
| 191 | 1 | ▶ | sub errors(@) {shift->report('ERRORS')} | ||||||||||||||||||
|
Subroutine
errors: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 192 | |||||||||||||||||||||
| 193 | #------------------------------------------- | ||||||||||||||||||||
| 194 | |||||||||||||||||||||
| 195 | |||||||||||||||||||||
| 196 | 1 | ▶ | sub warnings(@) {shift->report('WARNINGS')} | ||||||||||||||||||
|
Subroutine
warnings: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 197 | |||||||||||||||||||||
| 198 | #------------------------------------------- | ||||||||||||||||||||
| 199 | |||||||||||||||||||||
| 200 | |||||||||||||||||||||
| 201 | sub notImplemented(@) | ||||||||||||||||||||
| 202 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||
|
Subroutine
notImplemented: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 203 | 0 | ▶ | my $package = ref $self || $self; | ||||||||||||||||||
|
Condition0%0/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table0%0/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||
| 204 | 0 | my $sub = (caller 1)[3]; | |||||||||||||||||||
| 205 | |||||||||||||||||||||
| 206 | 0 | $self->log(ERROR => "Package $package does not implement $sub."); | |||||||||||||||||||
| 207 | 0 | confess "Please warn the author, this shouldn't happen."; | |||||||||||||||||||
| 208 | } | ||||||||||||||||||||
| 209 | |||||||||||||||||||||
| 210 | #------------------------------------------ | ||||||||||||||||||||
| 211 | |||||||||||||||||||||
| 212 | |||||||||||||||||||||
| 213 | sub logPriority($) | ||||||||||||||||||||
| 214 | 74 | ▶ | { my $level = $levelprio{$_[1]} or return undef; | ||||||||||||||||||
|
Subroutine
logPriority: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||
| 215 | 72 | dualvar $level, $levelname[$level]; | |||||||||||||||||||
| 216 | } | ||||||||||||||||||||
| 217 | |||||||||||||||||||||
| 218 | #------------------------------------------- | ||||||||||||||||||||
| 219 | |||||||||||||||||||||
| 220 | |||||||||||||||||||||
| 221 | sub logSettings() | ||||||||||||||||||||
| 222 | 173 | ▶ | { my $self = shift; | ||||||||||||||||||
|
Subroutine
logSettings: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 223 | 173 | (log => $self->{MR_log}, trace => $self->{MR_trace}); | |||||||||||||||||||
| 224 | } | ||||||||||||||||||||
| 225 | |||||||||||||||||||||
| 226 | #------------------------------------------- | ||||||||||||||||||||
| 227 | |||||||||||||||||||||
| 228 | |||||||||||||||||||||
| 229 | sub AUTOLOAD(@) | ||||||||||||||||||||
| 230 | 0 | ▶ | { my $thing = shift; | ||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 231 | 0 | our $AUTOLOAD; | |||||||||||||||||||
| 232 | 0 | ▶ | my $class = ref $thing || $thing; | ||||||||||||||||||
|
Condition0%0/3
ref $thing || $thing
MC/DC0%0/2
ref $thing || $thing
ref $thing
$thing
Truth table0%0/3
A || B
A= ref $thingB= $thing
| |||||||||||||||||||||
| 233 | 0 | (my $method = $AUTOLOAD) =~ s/^.*\:\://; | |||||||||||||||||||
| 234 | |||||||||||||||||||||
| 235 | 0 | $Carp::MaxArgLen=20; | |||||||||||||||||||
| 236 | 0 | confess "Method $method() is not defined for a $class.\n"; | |||||||||||||||||||
| 237 | } | ||||||||||||||||||||
| 238 | |||||||||||||||||||||
| 239 | #------------------------------------------- | ||||||||||||||||||||
| 240 | |||||||||||||||||||||
| 241 | |||||||||||||||||||||
| 242 | #------------------------------------------- | ||||||||||||||||||||
| 243 | |||||||||||||||||||||
| 244 | |||||||||||||||||||||
| 245 | 3717 | ▶ | sub DESTROY {shift} | ||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 246 | |||||||||||||||||||||
| 247 | 56 | 1; | |||||||||||||||||||