1No::Worries::Warn(3)  User Contributed Perl Documentation No::Worries::Warn(3)
2
3
4

NAME

6       No::Worries::Warn - warning handling without worries
7

SYNOPSIS

9         use No::Worries::Warn qw(warnf handler);
10
11         if (open($fh, "<", $path)) {
12             ... so something in case of success ...
13         } else {
14             warnf("cannot open(%s): %s", $path, $!);
15             ... do something else in case of failure ...
16         }
17
18         $ ./myprog
19         myprog: cannot open(foo): No such file or directory
20
21         $ NO_WORRIES=cluck ./myprog
22         myprog: cannot open(foo): No such file or directory at myprog line 16
23             main::test() called at ./myprog line 19
24

DESCRIPTION

26       This module eases warning handling by providing a convenient wrapper
27       around warn() with sprintf()-like API. warnf() is to warn() what
28       printf() is to print() with, in addition, the trimming of leading and
29       trailing spaces.
30
31       It also provides a handler for warn() that prepends a prefix
32       ($No::Worries::Warn::Prefix) to all warnings. It also uses the
33       "NO_WORRIES" environment variable to find out if Carp's carp() or
34       cluck() should be used instead of warn(). Finally, the wrapper can be
35       told to also log warnings to syslog (see $No::Worries::Warn::Syslog).
36
37       This handler can be installed simply by importing it:
38
39         use No::Worries::Warn qw(warnf handler);
40
41       Alternatively, it can be installed "manually":
42
43         use No::Worries::Warn qw(warnf);
44         $SIG{__WARN__} = \&No::Worries::Warn::handler;
45

FUNCTIONS

47       This module provides the following functions (none of them being
48       exported by default):
49
50       warnf(MESSAGE)
51           report a warning described by the given MESSAGE
52
53       warnf(FORMAT, ARGUMENTS...)
54           idem but with sprintf()-like API
55
56       handler(MESSAGE)
57           $SIG{__WARN__} compatible warning handler (this function cannot be
58           imported)
59

GLOBAL VARIABLES

61       This module uses the following global variables (none of them being
62       exported):
63
64       $Prefix
65           prefix to prepend to all warnings (default: the program name)
66
67       $Syslog
68           true if warnings should also be sent to syslog using
69           No::Worries::Syslog's syslog_warning() (default: false)
70

ENVIRONMENT VARIABLES

72       This module uses the "NO_WORRIES" environment variable to control how
73       warnings should be reported. Supported values are:
74
75       "carp"
76           Carp's carp() will be used instead of warn()
77
78       "cluck"
79           Carp's cluck() will be used instead of warn()
80

SEE ALSO

82       Carp, No::Worries, No::Worries::Die, No::Worries::Syslog.
83

AUTHOR

85       Lionel Cons <http://cern.ch/lionel.cons>
86
87       Copyright (C) CERN 2012-2017
88
89
90
91perl v5.28.0                      2017-08-01              No::Worries::Warn(3)
Impressum