I want to have fatal errors that can be reduced to warnings (or, conversely, warnings that can be extended to fatal errors) depending on the user's preferences. I am currently using dieand overriding it as follows:
my $force;
BEGIN {
no warnings 'once';
Getopt::Long::Configure('pass_through');
GetOptions('force', \$force);
*CORE::GLOBAL::die = sub { warn @_ } if $force;
Getopt::Long::Configure('no_pass_through');
}
use My::Module;
...
die "maybe";
...
exit(1) if $force;
exit(0);
I do not like this approach, mainly because there are several places where I still want to die (for example, missing command line arguments). I would rather change the (most) instances dieto warnand make a conditional use warnings FATAL => 'all' 1 . The problem is that it is use warningslexically limited, so it is inefficient:
if (!$force) {
use warnings FATAL => 'all';
}
Trying to use a postfix condition is a syntax error:
use warnings FATAL => 'all' unless $force;
use :
$force or use warnings FATAL => 'all';
( /, script if/else ..), , use warnings . ( , , , .)
1: , use warnings::register use warnings FATAL => 'My::Module' script, .