I've just released Future::HTTP using signatures. Basically, this needs the following stanza to tell Perl that I know what I'm doing:

no warnings 'experimental::signatures'; use feature 'signatures';

As I want to support versions of Perl older than 5.22 and also only use a restricted set of signature features, I also wrote Filter::signatures, which implements a very restricted version of signatures as a source filter.

The problem now arises when my code is run under (say) Perl 5.14. That version of Perl does not know about the experimental::signatures warning category. But I don't care about warnings not knowing about that category because if it doesn't know about a category, disabling that category can't make things worse. The following approaches don't work:

eval { no warnings 'experimental::signatures' };

This gives a compile time error as "no warnings" happens when the source code is parsed.

eval "no warnings 'experimental::signatures'";

This catches the error, but runs too late because the warnings get raised during compile time and then get disabled at runtime.

BEGIN { eval "no warnings 'experimental::signatures'"; }

This runs at the right time, but as the warnings are lexically scoped, the warnings only get disabled for the BEGIN block.

So far, I've settled on Filter::signatures simply disabling the exact statement of no warnings 'experimental::signatures'; when it finds it. This is the same approach the module already takes to defang use feature 'signatures'; on versions of Perl that don't have signature support. But that path leads down the ugly and very slippery slope of rewriting more and more of Perl code and I'd prefer to keep the modifications of the source filter as small as possible.

I guess my question boils down to how to disable a warning category for a complete package without wrapping the whole package in a BEGIN scope, and ideally without using a source filter...


In reply to Optionally / safely disabling a warning category for a complete package by Corion

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.