Introducing warnings::MaybeFatal

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.

2 Comments

Have you considered warnings::fatal::CompileTime or something like that? Seems more straightforward to me.

Leave a comment

About Toby Inkster

user-pic I'm tobyink on CPAN, IRC and PerlMonks.