Corion has asked for the wisdom of the Perl Monks concerning the following question:
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...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Optionally / safely disabling a warning category for a complete package
by haukex (Archbishop) on May 18, 2016 at 08:08 UTC | |
|
Re: Optionally / safely disabling a warning category for a complete package
by haukex (Archbishop) on May 18, 2016 at 09:59 UTC | |
|
Re: Optionally / safely disabling a warning category for a complete package (magic numbers)
by tye (Sage) on May 18, 2016 at 14:55 UTC | |
by tye (Sage) on May 18, 2016 at 19:39 UTC | |
by haukex (Archbishop) on May 18, 2016 at 19:53 UTC | |
by tye (Sage) on May 18, 2016 at 20:37 UTC | |
|
Re: Optionally / safely disabling a warning category for a complete package
by Corion (Patriarch) on May 19, 2016 at 18:43 UTC |