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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
|
=head1 NAME
Mail::Reporter - base-class and error reporter for Mail::Box
=head1 SYNOPSIS
$folder->log(WARNING => 'go away');
print $folder->trace; # current level
$folder->trace('PROGRESS'); # set level
print $folder->errors;
print $folder->report('PROGRESS');
=head1 DESCRIPTION
The C<Mail::Reporter> class is the base class for all classes, except
L<Mail::Message::Field::Fast|Mail::Message::Field::Fast> because it would become slow... This
base class is used during initiation of the objects, and for configuring
and logging error messages.
=head1 METHODS
The C<Mail::Reporter> class is the base for nearly all other
objects. It can store and report problems, and contains the general
constructor L<new()|Mail::Reporter/"Constructors">.
=head2 Constructors
Mail::Reporter-E<gt>B<new>(OPTIONS)
=over 4
This error container is also the base constructor for all modules, (as long
as there is no need for an other base object) The constructor always accepts
the following OPTIONS related to error reports.
Option--Defined in --Default
log 'WARNINGS'
trace 'WARNINGS'
. log LEVEL
=over 4
Log messages which have a priority higher or equal to the specified
level are stored internally and can be retrieved later. The global
default for this option can be changed with L<defaultTrace()|Mail::Reporter/"Error handling">.
Known levels are C<INTERNAL>, C<ERRORS>, C<WARNINGS>, C<PROGRESS>,
C<NOTICES> C<DEBUG>, and C<NONE>. The C<PROGRESS> level relates to
the reading and writing of folders. C<NONE> will cause only C<INTERNAL>
errors to be logged.
By the way: C<ERROR> is an alias for C<ERRORS>, as C<WARNING> is an alias
for C<WARNINGS>, and C<NOTICE> for C<NOTICES>.
=back
. trace LEVEL
=over 4
Trace messages which have a level higher or equal to the specified level
are directly printed using warn. The global default for this option can
be changed with L<defaultTrace()|Mail::Reporter/"Error handling">.
=back
=back
=head2 Error handling
$obj-E<gt>B<AUTOLOAD>
=over 4
By default, produce a nice warning if the sub-classes cannot resolve
a method.
=back
$obj-E<gt>B<addReport>(OBJECT)
=over 4
Add the report from other OBJECT to the report of this object. This is
useful when complex actions use temporary objects which are not returned
to the main application but where the main application would like to know
about any problems.
=back
$obj-E<gt>B<defaultTrace>([LEVEL]|[LOGLEVEL, TRACELEVEL]|[LEVEL, CALLBACK])
Mail::Reporter-E<gt>B<defaultTrace>([LEVEL]|[LOGLEVEL, TRACELEVEL]|[LEVEL, CALLBACK])
=over 4
Reports the default log and trace level which is used for object as list
of two elements. When not explicitly set, both are set to C<WARNINGS>.
This method has three different uses. When one argument is specified, that
LEVEL is set for both loglevel as tracelevel.
With two arguments, the second determines which configuration you like. If
the second argument is a CODE reference, you install a CALLBACK. The loglevel
will be set to NONE, and all warnings produced in your program will get
passed to the CALLBACK function. That function will get the problem level,
the object or class which reports the problem, and the problem text passed
as arguments.
In any case two values are returned: the first is the log level, the
second represents the trace level. Both are special variables: in numeric
context they deliver a value (the internally used value), and in string
context the string name. Be warned that the string is always in singular
form!
I<Example:> setting loglevels
my ($loglevel, $tracelevel) = Mail::Reporter->defaultTrace;
Mail::Reporter->defaultTrace('NOTICES');
my ($l, $t) = Mail::Reporter->defaultTrace('WARNINGS', 'DEBUG');
print $l; # prints "WARNING" (no S!)
print $l+0; # prints "4"
print "Auch" if $l >= $self->logPriority('ERROR');
Mail::Reporter->defaultTrace('NONE'); # silence all reports
$folder->defaultTrace('DEBUG'); # Still set as global default!
$folder->trace('DEBUG'); # local default
I<Example:> installing a callback
Mail::Reporter->defaultTrace
=back
$obj-E<gt>B<errors>
=over 4
Equivalent to
$folder->report('ERRORS')
=back
$obj-E<gt>B<log>([LEVEL [,STRINGS]])
Mail::Reporter-E<gt>B<log>([LEVEL [,STRINGS]])
=over 4
As instance method this function has three different purposes. Without
any argument, it returns one scalar containing the number which is internally
used to represent the current log level, and the textual representation of
the string at the same time. See Scalar::Util method C<dualvar> for
an explanation.
With one argument, a new level of logging detail is set (specify a number
of one of the predefined strings). With more arguments, it is a report
which may need to be logged or traced.
As class method, only a message can be passed. The global configuration
value set with L<defaultTrace()|Mail::Reporter/"Error handling"> is used to decide whether the message is
shown or ignored.
Each log-entry has a LEVEL and a text string which will
be constructed by joining the STRINGS. If there is no newline, it will
be added.
I<Example:>
print $message->log; # may print "NOTICE"
print $message->log +0; # may print "3"
$message->log('ERRORS'); # sets a new level, returns the numeric value
$message->log(WARNING => "This message is too large.");
$folder ->log(NOTICE => "Cannot read from file $filename.");
$manager->log(DEBUG => "Hi there!", reverse sort @l);
Mail::Message->log(ERROR => 'Unknown');
=back
$obj-E<gt>B<logPriority>(LEVEL)
Mail::Reporter-E<gt>B<logPriority>(LEVEL)
=over 4
One error level (log or trace) has more than one representation: a
numeric value and one or more strings. For instance, C<4>, C<'WARNING'>,
and C<'WARNINGS'> are all the same. You can specify any of these,
and in return you get a dualvar (see Scalar::Util method C<dualvar>)
back, which contains the number and the singular form.
The higher the number, the more important the message.
Only messages about C<INTERNAL> problems are more important than C<NONE>.
I<Example:>
my $r = Mail::Reporter->logPriority('WARNINGS');
my $r = Mail::Reporter->logPriority('WARNING'); # same
my $r = Mail::Reporter->logPriority(4); # same, deprecated
print $r; # prints 'WARNING' (no S!)
print $r + 0; # prints 4
if($r < Mail::Reporter->logPriority('ERROR')) {..} # true
=back
$obj-E<gt>B<logSettings>
=over 4
Returns a list of C<(key => value)> pairs which can be used to initiate
a new object with the same log-settings as this one.
I<Example:>
$head->new($folder->logSettings);
=back
$obj-E<gt>B<notImplemented>
=over 4
A special case of L<log()|Mail::Reporter/"Error handling">, which logs a C<INTERNAL>-error
and then croaks. This is used by extension writers.
=back
$obj-E<gt>B<report>([LEVEL])
=over 4
Get logged reports, as list of strings. If a LEVEL is specified, the log
for that level is returned.
In case no LEVEL is specified, you get all messages each as reference
to a tuple with level and message.
I<Example:>
my @warns = $message->report('WARNINGS');
# previous indirectly callable with
my @warns = $msg->warnings;
print $folder->report('ERRORS');
if($folder->report('DEBUG')) {...}
my @reports = $folder->report;
foreach (@reports) {
my ($level, $text) = @$_;
print "$level report: $text";
}
=back
$obj-E<gt>B<reportAll>([LEVEL])
=over 4
Report all messages which were produced by this object and all the objects
which are maintained by this object. This will return a list of triplets,
each containing a reference to the object which caught the report, the
level of the report, and the message.
I<Example:>
my $folder = Mail::Box::Manager->new->open(folder => 'inbox');
my @reports = $folder->reportAll;
foreach (@reports) {
my ($object, $level, $text) = @$_;
if($object->isa('Mail::Box')) {
print "Folder $object: $level: $message";
} elsif($object->isa('Mail::Message') {
print "Message ".$object->seqnr.": $level: $message";
}
}
=back
$obj-E<gt>B<trace>([LEVEL])
=over 4
Change the trace LEVEL of the object. When no arguments are specified, the
current level is returned only. It will be returned in one scalar which
contains both the number which is internally used to represent the level,
and the string which represents it. See L<logPriority()|Mail::Reporter/"Error handling">.
=back
$obj-E<gt>B<warnings>
=over 4
Equivalent to
$folder->report('WARNINGS')
=back
=head2 Cleanup
$obj-E<gt>B<DESTROY>
=over 4
Cleanup the object.
=back
$obj-E<gt>B<inGlobalDestruction>
=over 4
Returns whether the program is breaking down. This is used in L<DESTROY()|Mail::Reporter/"Cleanup">,
where during global destructions references cannot be used.
=back
=head1 DIAGNOSTICS
I<Error:> Package $package does not implement $method.
Fatal error: the specific package (or one of its superclasses) does not
implement this method where it should. This message means that some other
related classes do implement this method however the class at hand does
not. Probably you should investigate this and probably inform the author
of the package.
=head1 REFERENCES
See the MailBox website at L<http://perl.overmeer.net/mailbox/> for more details.
=head1 COPYRIGHTS
Distribution version 2.068.
Written by Mark Overmeer (mark@overmeer.net). See the ChangeLog for
other contributors.
Copyright (c) 2001-2006 by the author(s). All rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
|