The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

warnings::everywhere

VERSION

version 0.001

SYNOPSIS

 no warnings::anywhere qw(uninitialized);
 use Module::That::Spits::Out::Warnings;
 use Other::Unnecessarily::Chatty::Module;
 use warnings::everywhere qw(uninitialized);
 # Write your own bondage-and-discipline code that really, really
 # cares about the difference between undef and the empty string

DESCRIPTION

Warnings are great - in your own code. Tools like prove, and libraries like Moose and Modern::Perl, turn them on for you so you can spot things like ambiguous syntax, variables you only used once, deprecated syntax and other useful things.

By default use warnings turns on all warnings, including some that you might not care about, like uninitialised variables. You could explicitly say

 use warnings;
 no warnings qw(uninitialized);

or you could use a module like common::sense which disables some warnings and makes others fatal, or you could roll your own system. Either way, for your own code, there are plenty of ways around unwanted warnings.

Not so for other code, though.

The test suite at $WORK produces a large number of 'use of uninitialized variable' warnings from (at the last count) four separate modules. Some of them are because warnings got switched on for that module, even though the module itself didn't say anything about warnings (probably because the test suite was run with prove). Others are there because the module explicitly said use warnings, and then proceeded to blithely throw around variables without checking whether they were defined first.

Either way, this isn't my code, and it's not something I'm going to fix. These warnings are just spam.

This is where warnings::everywhere comes in.

Usage

At its simplest, say

 use warnings::everywhere qw(all);

and all modules imported from there onwards will have all warnings switched on. Modules imported previously will be unaffected. You can turn specific warnings off by saying e.g.

 no warnings::everywhere qw(uninitialized);

or, depending on how frustrated and/or grammatically-sensitive you happen to be feeling,

 no warnings::anywhere qw(uninitialized);

or

 no goddamn::warnings::anywhere qw(uninitialized);

Parameters are the same as use warnings: a list of categories as per perllexwarn, where all means all warnings.

Limitations

warnings::everywhere works by fiddling with the contents of the global hashes %warnings::Bits and %warnings::DeadBits. As such, there are limitations on what it can and cannot do:

It cannot affect modules that are already loaded.

If you say

 use Chatty::Module;
 no warnings::anywhere qw(uninitialized);

that's no good - Chatty::Module has already called use warnings and uninitialized variables was in the list of enabled warnings at that point, so it will still spam you.

Similarly, this is no help:

 use Module::That::Uses::Chatty::Module;
 no warnings::anywhere qw(uninitialized);
 use Chatty::Module;

Chatty::Module was pulled in by that other module already by the time perl gets to your use statement, so it's ignored.

It cannot make all modules use warnings

All it does is fiddle with the exact behaviour of use warnings, so a module that doesn't say use warnings, or import a module that injects warnings like Moose, will be unaffected.

It's not lexical

While it looks like a pragma, it's not - it fiddles with global settings, after all. So you can't say

 {
     no warnings::anywhere qw(uninitialized);
     Chatty::Module->do_things;
 }
 Unchatty::Module->do_stuff(undef);

and expect to get a warning from the last line. That warning's been turned off for good.

NAME

warnings::everywhere - a way of ensuring consistent global warning settings

VERSION

This is version 0.001.

SUBROUTINES

warnings::anywhere provides the following functions, mostly for diagnostic use. They are not exported or exportable.

categories_enabled
 Out: @categories

Returns a sorted list of warning categories enabled globally. Before you've fiddled with anything, this will be the list of warning categories from perllexwarn, minus all which isn't a category itself.

Fatal warnings are ignored for the purpose of this function. FIXME: recognise fatal warnings.

categories_disabled
 Out: @categories

Returns a sorted list of warning categories disabled globally. Before you've fiddled with anything, this will be the empty list.

Fatal warnings are ignored for the purpose of this function. FIXME:: recognise fatal warnings.

enable_warning_category
 In: $category

Supplied with a valid warning category, enables it for all future uses of use warnings.

TODO: what do we do about all?

disable_warning_category
 In: $category

Supplied with a valid warning category, disables it for future uses of use warnings - even calls to explicitly enable it.

DIAGNOSTICS

Unrecognised warning category $category

Your version of Perl doesn't recognise the warning category $category. Either you're using a different version of Perl than you thought, or a third-party module that defined that warning isn't loaded yet.

SEE ALSO

common::sense

AUTHOR

Sam Kington <skington@cpan.org>

The source code for this module is hosted on GitHub https://github.com/skington/warnings_everywhere - this is probably the best place to look for suggestions and feedback.

COPYRIGHT

Copyright (c) 2013 Sam Kington.

LICENSE

This library is free software and may be distributed under the same terms as perl itself.

AUTHOR

Sam Kington <skington@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Sam Kington <skington@cpan.org>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.