Mailing List Archive

warnings::warn using only standard warnings categories?
Can /warnings::warn/   be used with only standard warnings categories
(not a module-custom cat)?

warnings::warn() dies unless warnings::register() was previously called,
but if the package does not wish to create any new warnings categories
then warnings::register should not be used, I assume.

|#!/usr/bin/env perl||
||
||package Foo;||
||sub import {||
||  use Carp;||
||  use warnings;||
||  my $enabled = warnings::enabled("deprecated");||
||
||  warnings::warn "This is deprecated" if $enabled; #dies with "package
'Foo' not registered for warnings"||||
||}||
||
||package main;||
||
||use warnings FATAL => 'all';||
||Foo->import("blah");||
||die "SHOULD NOT GET HERE (due to FATAL => all)";||
|
Re: warnings::warn using only standard warnings categories? [ In reply to ]
Jim Avera wrote:
>
> Can warnings::warn be used with only standard warnings categories (not a module-custom cat)?

Yes. <https://perldoc.perl.org/warnings> shows several examples, such as:

warnings::warn("deprecated", "open is deprecated, use new instead");


> use warnings FATAL => 'all';
> Foo->import("blah");
> die "SHOULD NOT GET HERE (due to FATAL => all)";

Fatal warnings are documented to be buggy and unreliable. Instead of stopping at the supposedly fatal warning, the following says BAR on all versions of perl I have installed, all the way down to 5.10.1:

perl -E 'use warnings FATAL => "all"; warn "foo"; say "BAR";'


--
Arne Johannessen
<https://arne.johannessen.de/>