No::Worries::Warn - warning handling without worries
use No::Worries::Warn qw(warnf handler); if (open($fh, "<", $path)) { ... so something in case of success ... } else { warnf("cannot open(%s): %s", $path, $!); ... do something else in case of failure ... } $ ./myprog myprog: cannot open(foo): No such file or directory $ NO_WORRIES=cluck ./myprog myprog: cannot open(foo): No such file or directory at myprog line 16 main::test() called at ./myprog line 19
This module eases warning handling by providing a convenient wrapper around warn() with sprintf()-like API. warnf() is to warn() what printf() is to print() with, in addition, the trimming of leading and trailing spaces.
It also provides a handler for warn() that prepends a prefix ($No::Worries::Warn::Prefix) to all warnings. It also uses the NO_WORRIES environment variable to find out if Carp's carp() or cluck() should be used instead of warn(). Finally, the wrapper can be told to also log warnings to syslog (see $No::Worries::Warn::Syslog).
This handler can be installed simply by importing it:
use No::Worries::Warn qw(warnf handler);
Alternatively, it can be installed "manually":
use No::Worries::Warn qw(warnf); $SIG{__WARN__} = \&No::Worries::Warn::handler;
This module provides the following functions (none of them being exported by default):
report a warning described by the given MESSAGE
idem but with sprintf()-like API
$SIG{__WARN__} compatible warning handler (this function cannot be imported)
This module uses the following global variables (none of them being exported):
prefix to prepend to all warnings (default: the program name)
true if warnings should also be sent to syslog using No::Worries::Syslog's syslog_warning() (default: false)
This module uses the NO_WORRIES environment variable to find out how warnings will be reported. Supported values are:
NO_WORRIES
carp
Carp's carp() will be used instead of warn()
cluck
Carp's cluck() will be used instead of warn()
Carp, No::Worries, No::Worries::Die, No::Worries::Syslog.
Lionel Cons http://cern.ch/lionel.cons
Copyright (C) CERN 2012-2016
To install No::Worries, copy and paste the appropriate command in to your terminal.
cpanm
cpanm No::Worries
CPAN shell
perl -MCPAN -e shell install No::Worries
For more information on module installation, please visit the detailed CPAN module installation guide.