Fix leak into global scope (Fix reversion in #3908)

Here is a candidate fix.

I am a bit stumped on the test because I'm on my windows machine right now and I'm getting intermittent tap failures, but I took a stab at a test that guards against `cooked` leaking into the global scope.