NAME
Forks::Super::Debug - debugging and logging routines for Forks::Super distro
VERSION
0.54
VARIABLES
$DEBUG
Many routines in the Forks::Super module look at this variable to decide whether to invoke the "debug" function. So if this variable is set to true, a lot of information about what the Forks::Super module is doing will be written to the debugging output stream.
If the environment variable FORKS_SUPER_DEBUG
is set, the $DEBUG
variable will take on its value. Otherwise, the default value of this variable is zero.
$DEBUG_FH
An output file handle for all debugging messages. Initially, this module tries to open $DEBUG_FH
as an output handle to the current tty (CON
on MSWin32). If that fails, it will try to dup file descriptor 2 (which is usually STDERR
) or alias $DEBUG_FH
directly to *STDERR
.
The initial setting can be overwritten at runtime. See t/15-debug.t
in this distribution for an example.
FUNCTIONS
debug
Output the given message to the current $DEBUG_FH
file handle. Usually you check whether $DEBUG
is set to a true value before calling this function.
carp_once
Like "carp" in Carp, but remembers what warning messages have already been printed and suppresses duplicate messages. This is useful for heavily used code paths that usually work, but tend to produce an enormous number of warnings when they don't.
use Forks::Super::Debug 'carp_once';
for (1 .. 9999) {
$var = &some_function_that_should_be_zero_but_sometimes_isnt;
if ($var != 0) {
carp_once "var was $var, not zero!";
}
}
should produce at most one warning in the lifetime of the program,
carp_once
can take a list reference as an optional first argument to provide additional context for the warning message. This code, for example, will produce one warning message for every different value of $!
that can be produced.
while (<$fh>) {
local $! = 0;
do_something($_);
if ($!) {
carp_once [$!], "do_something() did something!: $!";
}
}
EXPORTS
This module exports the $DEBUG
variable and the debug
and carp_once
methods. The :all
tag exports all of these symbols.
SEE ALSO
AUTHOR
Marty O'Brien, <mob@cpan.org>
LICENSE AND COPYRIGHT
Copyright (c) 2009-2011, Marty O'Brien.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
See http://dev.perl.org/licenses/ for more information.