Dist-Zilla Hates Tidy
It is discovery of silly mistakes day here in the Dist-pen.
Over the past few posts I have been running down a persnickety bug in my Database::Accessor system. I had first seen it while expanding and cleaning up my test cases and I thought at first I fixed it with a simple 'lib' statement and a slight change to my embedded classes. As I dug down into my test cases the bug came up again I reverted that embedded class change and added in a kludged that so at least my test cases all passed. I wasn't satisfied with this and did some more hacking and found my 'fix' was not I had a real bug, which I fixed in the end.
Today I found the root cause of my bug, I went back to play on my Windows box today and before I did a pull of my fixed code I did a quick diff and found this
– eval "require $classname";
++ eval qq{package
Database::Accessor::DAD::_ensure;
require $classname; # load the driver
};
You will not see the exact bug here but if I go back into the history of the code to this point, I had made this change
– eval "require $classname";
++ eval {
++ "require $classname";
++ };
Ah I had warped that 'require' in {}; Here I am thinking it was running my Windos box because I hard all those hard coded paths in therem Now I know why it was running I did not have those {} there.
Now why on earth did I add them in. Well I can tell you it was all because of this Perl::Tidy fail;
xt/author/critic.t .............. 1/?
# Failed test 'Test::Perl::Critic for "blib/lib/Database/Accessor.pm"'
# at /usr/local/share/perl/5.18.2/Test/Perl/Critic.pm line 104.
…
# Expression form of "eval" at line 112, near 'eval "require $classname";'.
# BuiltinFunctions::ProhibitStringyEval (Severity: 5)
# The string form of `eval' is recompiled every time it is executed,
# whereas the block form is only compiled once. Also, the string form
# doesn't give compile-time warnings.
#
# eval "print $foo"; # not ok
# eval {print $foo}; # ok
Like the dolt that I am I went and fixed that problem and quickly broke all of my code. I guess I should really blame Conway or maybe D'Foy or even Hancock but then again that would be like blaming the person who invented the hammer about bashing you own finger.
So lesson here is never trust 100% in code checkers as sometimes they are not right.
I was using eval not as a try block but in its original form 'eval EXPR' which I remember from my perl4 days as a way to execute a string the same way we do '$mycall->$some_method'. Wraping that in those darn {} basically turns my 'requires' into an out of scope local look-up that the rest of name-space can't see.
So I guess I have to tweak my Perl::Tidy a little and trust my code more.
Leave a comment