Introducing warnings::MaybeFatal

This is a very old article. It has been imported from older blogging software, and the formatting, images, etc may have been lost. Some links may be broken. Some of the information may no longer be correct. Opinions expressed in this article may no longer be held.

OK, so you’ve written your module like this:

package MyUtils;
use strict;
use warnings FATAL => qw( all );
sub frobnicate { ... }
1;

It passes its test suite, and all is fine and dandy. You use the frobnicate function in a long-running data processing script, and after the first 45 minutes it suddenly dies saying Use of uninitialized value $quux in addition at lib/MyUtils.pm line 13. D’oh!

This is where warnings::MaybeFatal comes in.

package MyUtils;
use strict;
use warnings qw( all );
use warnings::MaybeFatal;
sub frobnicate { ... }
1;

It fatalizes warnings, but only at compile time. So if a warning occurs while MyUtils.pm is compiling, it will immediately croak. However, if a warning occurs during a normal call to the frobnicate() function, it will simply output a warning to STDERR and carry on.