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