NAME
Log::Delayed - Delay error handling and write status file
SYNOPSIS
use Log::Delayed; my $Delayed = new Log::Delayed (filename=>"test_dir/.status");
die_delayed ("First error into .status\n");
if ($Delayed->errors()) { print "We got a error\n"; } $Delayed->errors(0); # Clear errors
$Delayed->write_status();
my $current_status = $Delayed->read_status();
$Delayed->exit_if_error();
$Delayed->completed()
DESCRIPTION
Log::Delayed is used to delay error messages for later logging and exiting. This is useful when parsing files and such, and multiple errors want to be presented to the user before exiting the program.
In addition, Log::Delayed optionally makes a status file (.status), which contains the first error detected. This allows calling programs to be passed more useful tracking information then just the shell exit status.
FUNCTIONS
- $dly->new
-
New creates a new Log::Delayed object. Parameters are passed by named form.
The filename=> parameter specifies the file to be written with the exit message, undef for none; defaults to .status.
The global=> boolean parameter forces the $dly->sig_end to be called automatically at program exit, it defaults true.
The overwrite=> boolean parameter defaults to true to overwrite any existing status file and write it even if there are no errors. If overwrite=> is clear, the status file will only be written with errors, which is useful to detect the first error across many applications running together.
The status=> string has the default status. It defaults to "Completed" for backward compatibility; new applications may wish to undef it and use the completed() call instead.
The write_if_ok=> boolean parameter defaults to true to write the .status file if there are no errors to report on exit. If cleared, ok status will not be written. This is useful for forked processes that need to silently exit.
- $dly->completed
-
Call at the end of the normal execution flow to set the status to "Completed\n". Use with the status=>undef parameter in the new call. This allows the status file to indicate if the program didn't complete normally, but also didn't report an error. (Like from calling exit() instead of die().)
- $dly->die_delayed
-
Die_delayed prints any parameters on stderr, then records the error occurrence for later error exiting. If new was called with global=>1 parameter, the exported version of die_delayed may be called without any object.
- $dly->errors
-
Returns the number of errors seen. With a parameter it sets the number of errors seen.
- $dly->exit_if_error
-
exit_if_error exits the program if any errors were detected.
- $dly->global_self
-
Returns the default object, either the one passed, or the default global object - the last one created.
- $dly->read_status
-
read_status reads the filename=> specified with new or this function call. It returns the contents of the file, or undef if no file exists.
- $dly->sig_end
-
sig_end changes the exit status to be bad if any delayed errors were detected, and calls write_status. sig_end is called automatically by the END{} handler if global=>1 was specified with the new constructor.
- $dly->sig_die
-
sig_die records the first error it sees so that write_status will contain Perl related error messages. sig_end is called automatically by the %SIG{__DIE__} handler if global=>1 was specified with the new constructor.
- $dly->write_status
-
write_status writes the filename=> specified with new or this function call with the first error message detected, or "Completed\n" if there were no errors.
DISTRIBUTION
Log-Detect is part of the http://www.veripool.com/ free EDA software tool suite. The latest version is available from CPAN and from http://www.veripool.com/.
Copyright 2000-2007 by Wilson Snyder. This package is free software; you can redistribute it and/or modify it under the terms of either the GNU Lesser General Public License or the Perl Artistic License.
AUTHORS
Wilson Snyder <wsnyder@wsnyder.org>
SEE ALSO
Log::Detect, SIG{__DIE__}
in perlvar