muthm has asked for the wisdom of the Perl Monks concerning the following question:
Hello wise monks.
I was playing around with features and warnings because I would like to create my own Moose version that not only enables all warnings like Moose does (which is great), but also disables experimental::signatures warnings, because I don't want to repeat writing no warnings 'experimental::signatures'; over and over again.
But my question is only about the strange and unexpected results that I get when I use warnings::enabled() for checking whether enabling and disabling warnings from my import sub works.
In fact, for me it looks like warnings::enabled does not treat the enabled/disabled state of 'standard' warning categories like once or void correctly. I am sure there is a good explanation why the following code behaves as it does, and it would certainly help me if I understood why.
Thank you for a ration of your wisdom!#!/usr/bin/env perl use feature 'say'; use feature 'signatures'; # Switch all warnings *off*, and only some warnings *on* explicitly: no warnings; use warnings qw( void once experimental::signatures ); # Let's check whether the warnings are generated: # Checking 'void' warnings: "hello"; # Results in a 'Useless use of a constant ("hello") in void context' # warning (as expected). # Checking 'once' warnings: $x = 1; # Results in a 'Name "main::x" used only once: possible typo' warning # (as expected). # Checking 'experimental::signatures' warnings: sub foo( $param ) { say "foo( $param )" } # Results in a 'The signatures feature is experimental' warning # (as expected; no warning in perl v5.36 since there, the feature is # not experimental anymore.) # Let's see what 'warnings::enabled' returns, # and let 'warnings::warnif' print an own warning for each enabled # category (and they should all be enabled!): for my $category ( qw( void once experimental::signatures ) ) { say "warnings::enabled( $category ) returns ", warnings::enabled( $category ) ? "TRUE" : "**FALSE**", "."; warnings::warnif( $category, "my own warning for $category" ); } # Prints this: # warnings::enabled( void ) returns **FALSE**. # warnings::enabled( once ) returns **FALSE**. # warnings::enabled( experimental::signatures ) returns TRUE. # my own warning for experimental::signatures at [...] # # But no output for the 'void' or 'once' categories. 1;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Warnings are enabled, but they aren't?
by tobyink (Canon) on Feb 27, 2023 at 10:16 UTC | |
by muthm (Sexton) on Feb 27, 2023 at 11:43 UTC |