No::Worries::Warn(3)
π No::Worries::Warn(3) β warning handling without worries π
okay so bestie, this is a page from the User Contributed Perl Documentation (we love a community-contributed moment) and it's about making Perl warnings not be a whole dramatic situation. let's get into it π«Ά
β¨ SYNOPSIS β¨
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
literally the glow-up from "huh?" to "ohhhh i see exactly where it went wrong" π
πΈ DESCRIPTION πΈ
So this module eases warning handling by providing a convenient wrapper around warn() with a sprintf()-like API. and the way that warnf() is to warn() what printf() is to print()? iconic. it also trims leading and trailing spaces, which is honestly the self-care every warning deserves β¨
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) π
and the best part? this handler can be installed simply by importing it:
use No::Worries::Warn qw(warnf handler);
alternatively, bestie, it can be installed "manually" (yes, the quotes are doing a lot of work there):
use No::Worries::Warn qw(warnf);
$SIG{__WARN__} = \&No::Worries::Warn::handler;
π¦ FUNCTIONS π¦
This module provides the following functions β and no, none of them are exported by default, you gotta ask for them by name π
warnf(MESSAGE)β report a warning described by the givenMESSAGEwarnf(FORMAT, ARGUMENTS...)β idem but with asprintf()-like APIhandler(MESSAGE)β$SIG{__WARN__}compatible warning handler (this function cannot be imported β it's giving exclusive, invite-only energy π)
π GLOBAL VARIABLES π
This module uses the following global variables (none of them being exported, same rule as above):
$Prefixβ prefix to prepend to all warnings (default: the program name π·οΈ)$Syslogβ true if warnings should also be sent to syslog using No::Worries::Syslog'ssyslog_warning()(default: false β so, off unless you say so π€)
π ENVIRONMENT VARIABLES π
This module uses the "NO_WORRIES" environment variable to control how warnings should be reported. Supported values are:
"carp"β Carp'scarp()will be used instead ofwarn()"cluck"β Carp'scluck()will be used instead ofwarn()
so basically you literally just set an env var and the whole vibe of your warnings changes. no code edits. no cap. π₯
π SEE ALSO π
Carp, No::Worries, No::Worries::Die, No::Worries::Syslog β the whole friend group, go say hi π«Ά
π AUTHOR π
Lionel Cons <http://cern.ch/lionel.cons>
Copyright (C) CERN 2012-2019
okay that's the whole page, and before you go: this beauty is perl v5.32.1, dated 2021-10-18, and it lives at No::Worries::Warn(3) β go forth and warn responsibly, bestie πβ¨π
π¦ where this page comes from
- epel 9: perl-No-Worries 1.7-1.el9 Β· GPL+ or Artistic
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms