While investigating common::sense, I noticed the exhortation to use FATAL warnings. I don't remember seeing this option before, so I thought I'd try it out:

$ perl -le 'use warnings qw(FATAL); my $a = "2:" + 3; print $a' 5
Hmmm. That didn't work so well. Did I do something wrong?
$ perl -le 'use warnings; my $a = "2:" + 3; print $a' Argument "2:" isn't numeric in addition (+) at -e line 1. 5
Nope, the warning message comes up fine here... well, maybe the "all" is only implied when there actually are no arguments at all.
$ perl -le 'use warnings qw(FATAL all); my $a = "2:" + 3; print $a' Argument "2:" isn't numeric in addition (+) at -e line 1.
Aha. There we go. FATAL only works when giving another option. I have to admit, that was unexpected. At the very least, if FATAL with no more arguments doesn't imply "all", I would hope for a warning of some sort. It is the warnings pragma, after all! :-)

(*) I was looking at common::sense as a point of comparison. I'm not in agreement with all of the authors' conclusions, but the concepts are good: automatically engaging strict, warnings, oft-used features, etc., with a single use call rather than mandating a whole bunch of boilerplate. I'd be tempted to use such a module to import a bunch of other stuff, too, but will probably hold off on that as it would start to hide where our logging is coming from (Log::Log4perl) which would serve to confuse rather than simplify.

Replies are listed 'Best First'.
Re: using FATAL warnings
by ikegami (Patriarch) on Dec 16, 2009 at 18:31 UTC
    You could do
    + my $keyword = 0; + my $usage = 0; foreach my $word ( @_ ) { if ($word eq 'FATAL') { + $usage ||= $keyword; + $keyword = 1; $fatal = 1; $no_fatal = 0; } elsif ($word eq 'NONFATAL') { + $usage ||= $keyword; + $keyword = 1; $fatal = 0; $no_fatal = 1; } elsif ($catmask = $Bits{$word}) { + $keyword = 0; $mask |= $catmask ; $mask |= $DeadBits{$word} if $fatal ; $mask &= ~($DeadBits{$word}|$All) if $no_fatal ; } else { Croaker("Unknown warnings category '$word'")} } + warn("No warning categories specified for FATAL or NONFATAL") + if $usage;
    but it breaks backwards compatibility if someone does
    use warnings FATAL => @fatals;

    As such, this might be better off as a Perl::Critic check.

Re: using FATAL warnings
by TGI (Parson) on Dec 28, 2009 at 19:31 UTC