I was serious when I wrote Why Test::Harness Should Not Enable Global Warnings.
Test::Harness's behavior here is still nonsense, and that's the politest word I have for it.
Here's a warning from one of my test suites:
Name "SQL::Translator::Schema::DEBUG" used only once: possible typo at /home/chromatic/.perl5/perls/perl-5.14.2/lib/site_perl/5.14.2/Class/Base.pm line 51, <DATA> line 998.
Tell me that's useful information.
I know what the problem is. The problem is this section of code in Class::Base's
new()
method:
no strict 'refs';
my $debug = defined $config->{ debug }
? $config->{ debug }
: defined $config->{ DEBUG }
? $config->{ DEBUG }
: ( ${"$class\::DEBUG"} || 0 );
... which attempts to access a global variable in the caller's namespace.
You can get rid of the warning by patching Class::Base
to add
no warnings 'once';
(patch submitted to RT, in fact) or by declaring that global variable in SQL::Translator::Schema
or by changing the way the latter invokes its parent constructor to pass in a
default debug
parameter. That's all reasonably easy. It's even
possible to rewrite this code so that it doesn't trigger this warning.
Do note that I don't use Class::Base
directly. I don't use
SQL::Translator::Schema
directly. No, I use DBICx::TestDatabase
which uses DBIx::Class
which uses SQL::Translator.
Do note also that this warning doesn't mark the spot where a bug may lurk. Read the code. The logic is fine. It's sound.
Yet every time I run my test suite through the test harness (not
prove
, which does the right thing), this warning pops up. It's not
an error. It's not a bug. It's a visual blip that interrupts my expected stream
of success messages. It's in a dependency of a dependency of a dependency, and
writing code to shut up that warning is busy work that has little practical
value except getting that message out of my test output to stop interrupting me
when all I want to know is "Do my tests still pass after that change?"
Sure, maybe it's naughty, naughty, naughty that Class::Base
doesn't use the warnings
pragma, and I'm certainly not a fan of OO
modules poking into package global variables for their configuration
information, especially in dependencies, but for goodness's sake,
Nonsense is really the politest word for it.
While building DWIM Perl I have installed the modules one by one on purpose. I looked at the test output of each one of them and sent a bug report, and sometimes even a patch when I saw warnings. I think that cleanup work has its value in the general health of CPAN.
Specifically in this case, I installed SQL::Translator::Schema but I have not seen that warning. (using 5.12.4). I'd happily apply your patch but first I'd like to see the warning happening to me as well. When do you encounter it?