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.

#!/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;

Thank you for a ration of your wisdom!

In reply to Warnings are enabled, but they aren't? by muthm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.