Michael G Schwern
2012-04-10 19:20:20 UTC
In a series of patches, Father Chrysostomos and I enhanced use_ok() so that it
can apply lexical effects to more closely emulate the real `use`. For example,
use_ok('strict');
Previously this would just load strict and call import, but strictures would
not actually be applied to your scope. Now strictures *will* be applied
making it work more like a regular use.
Testing has shown it's caused just a handful of compatibility problems, and it
hasn't gone out in a stable release yet. Because the new use_ok() is so much
more complex than before I'm having second thoughts about whether it's worth
it and would like opinions.
There are two questions:
1. Should the lexical effect patches to use_ok() be rolled back?
2. Should use_ok() be discouraged in the documentation?
The new use_ok(), while it works remarkably well, is significantly more
complex than previously and it touches magical variables $^H and %^H. There
is a danger of invoking bugs by touching those variables.
It continues to have compatibility issues, for example...
BEGIN { use_ok 'Some::Module' }
this will apply lexical effect while...
BEGIN { use strict }
will not but
BEGIN { require strict; strict->import }
will. Confusing.
use_ok() has low utility to begin with. If you want exports and lexical
effects to be properly applied you have to wrap it in a BEGIN block. And as
has been pointed out before, if use_ok() fails you probably want the program
to halt. So the full invocation should be...
BEGIN {
use_ok("Some::Module") or die;
}
At which point you might as well write...
use Some::Module;
And if you really want the load to be a passing test, you can add...
pass("Loaded Some::Module");
If all you want to do is check that a module can compile, there is the much
simpler require_ok().
Apologies to Father Chrysostomos if his work is reverted, it has been top
notch. If it is reverted, it may find life in another module where a complete
emulation of use is desired as a user function or method.
can apply lexical effects to more closely emulate the real `use`. For example,
use_ok('strict');
Previously this would just load strict and call import, but strictures would
not actually be applied to your scope. Now strictures *will* be applied
making it work more like a regular use.
Testing has shown it's caused just a handful of compatibility problems, and it
hasn't gone out in a stable release yet. Because the new use_ok() is so much
more complex than before I'm having second thoughts about whether it's worth
it and would like opinions.
There are two questions:
1. Should the lexical effect patches to use_ok() be rolled back?
2. Should use_ok() be discouraged in the documentation?
The new use_ok(), while it works remarkably well, is significantly more
complex than previously and it touches magical variables $^H and %^H. There
is a danger of invoking bugs by touching those variables.
It continues to have compatibility issues, for example...
BEGIN { use_ok 'Some::Module' }
this will apply lexical effect while...
BEGIN { use strict }
will not but
BEGIN { require strict; strict->import }
will. Confusing.
use_ok() has low utility to begin with. If you want exports and lexical
effects to be properly applied you have to wrap it in a BEGIN block. And as
has been pointed out before, if use_ok() fails you probably want the program
to halt. So the full invocation should be...
BEGIN {
use_ok("Some::Module") or die;
}
At which point you might as well write...
use Some::Module;
And if you really want the load to be a passing test, you can add...
pass("Loaded Some::Module");
If all you want to do is check that a module can compile, there is the much
simpler require_ok().
Apologies to Father Chrysostomos if his work is reverted, it has been top
notch. If it is reverted, it may find life in another module where a complete
emulation of use is desired as a user function or method.
--
31. Not allowed to let sock puppets take responsibility for any of my
actions.
-- The 213 Things Skippy Is No Longer Allowed To Do In The U.S. Army
http://skippyslist.com/list/
31. Not allowed to let sock puppets take responsibility for any of my
actions.
-- The 213 Things Skippy Is No Longer Allowed To Do In The U.S. Army
http://skippyslist.com/list/