man Mail::Reporter () - base-class and error reporter for Mail::Box
NAME
Mail::Reporter - base-class and error reporter for Mail::Box
SYNOPSIS
$folder->log(WARNING => 'go away'); print $folder->trace; # current level $folder->trace('PROGRESS'); # set level print $folder->errors; print $folder->report('PROGRESS');
DESCRIPTION
The CWMail::Reporter class is the base class for all classes, except 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.
METHODS
The CWMail::Reporter class is the base for nearly all other objects. It can store and report problems, and contains the general constructor new().
Constructors
Mail::Reporter->new(OPTIONS) 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 C<'WARNINGS'> trace C<'WARNINGS'>. log LEVEL 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 defaultTrace(). Known levels are CWINTERNAL, CWERRORS, CWWARNINGS, CWPROGRESS, CWNOTICES CWDEBUG, and CWNONE. The CWPROGRESS level relates to the reading and writing of folders. CWNONE will cause only CWINTERNAL errors to be logged. By the way: CWERROR is an alias for CWERRORS, as CWWARNING is an alias for CWWARNINGS, and CWNOTICE for CWNOTICES. . trace LEVEL 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 defaultTrace().
Error handling
$obj->AUTOLOAD By default, produce a nice warning if the sub-classes cannot resolve a method.
$obj->addReport(OBJECT) 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.
$obj->defaultTrace([LEVEL]|[LOGLEVEL, TRACELEVEL]|[LEVEL, CALLBACK])
Mail::Reporter->defaultTrace([LEVEL]|[LOGLEVEL, TRACELEVEL]|[LEVEL, CALLBACK]) 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 CWWARNINGS. 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! 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 defaultExample: installing a callback
Mail::Reporter->defaultTrace
$obj->errors Equivalent to
$folder->report('ERRORS')
$obj->log([LEVEL [,STRINGS]])
Mail::Reporter->log([LEVEL [,STRINGS]]) 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 CWdualvar 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 defaultTrace() 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. 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');
$obj->logPriority(LEVEL)
Mail::Reporter->logPriority(LEVEL) One error level (log or trace) has more than one representation: a numeric value and one or more strings. For instance, CW4, CW'WARNING', and CW'WARNINGS' are all the same. You can specify any of these, and in return you get a dualvar (see Scalar::Util method CWdualvar) back, which contains the number and the singular form. The higher the number, the more important the message. Only messages about CWINTERNAL problems are more important than CWNONE. 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
$obj->logSettings Returns a list of CW(key = value)> pairs which can be used to initiate a new object with the same log-settings as this one. Example:
$head->new($folder->logSettings);
$obj->notImplemented A special case of log(), which logs a CWINTERNAL-error and then croaks. This is used by extension writers.
$obj->report([LEVEL]) 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. 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"; }
$obj->reportAll([LEVEL]) 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. 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"; } }
$obj->trace([LEVEL]) 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 logPriority().
$obj->warnings Equivalent to
$folder->report('WARNINGS')
Cleanup
$obj->DESTROY Cleanup the object.
$obj->inGlobalDestruction Returns whether the program is breaking down. This is used in DESTROY(), where during global destructions references cannot be used.
DIAGNOSTICS
Error: Package CW$package does not implement CW$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.
REFERENCES
See the MailBox website at <http://perl.overmeer.net/mailbox/> for more details.
COPYRIGHTS
Distribution version 2.063. Written by Mark Overmeer (mark@overmeer.net). See the ChangeLog for other contributors.
Copyright (c) 2001-2003 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.