Here I am preparing a new release of UNIVERSAL::require and I just can't
document that the right thing to do is:
$module->require or die $UNIVERSAL::require::ERROR;
Yuck. So early in the module's development and already the interface is
fucked. Not only is that a lot to type, a lot of people don't realize
UNIVERSAL::require does not die. And why should they? require() dies.
UNIVERSAL::require should die.
I'd rather fix it now than never be able to. Here's the plan.
-1) UNIVERSAL::require is getting its own distribution separate from
UNIVERSAL::exports both to highlight the module better and to avoid
any upgrade pain around UNIVERSAL::require from effecting
UNIVERSAL::exports.
0) I've looked through the modules using UNIVERSAL::require (cpansearch++)
and noticed only a few cases where the code wasn't dying on failure.
So the potential impact of changing require() to die is small.
1) Add use() which will be just like require() except...
* It calls import()
* It dies on failure to load.
2) Add require_or_die() which is just like require() except...
* It dies on failure to load.
3) Email all known users of UNIVERSAL::require (CPANTS++, cpansearch++) and
telling them to switch to require_or_die() or use() and bump up their
required version to 0.04.
4) Declare that the behavior of require() will change in the future to
match require_on_die() unless there's a storm of protest.
That gives folks an upgrade path and enough lead time to adjust their code
to the change.
*cry* (Score:1)
Re:*cry* (Score:2)
That's the plan.
If you look at the Makefile.PL for UNIVERSAL::require [cpan.org] you'll notice logic in there which checks if the currently installed version of the module is older than the last API change. If so, it warns about the API change and sleeps for a moment so there's a hope of it being seen. Additionally, I'll put this warning in the version
Re:*cry* (Score:1)
Re:*cry* (Score:2)
What happens? Thus is the curse of UNIVERSAL. I also can't use a different package name, such as UNIVERSAL::use or UNIVERSAL::load, if its going to have a require() method because then UNIVERSAL::require and UNIVERSAL::use could not be used together in the same package.
Re:*cry* (Score:2)
storm of protest (Score:1)
Not a fan of this change. What's wrong with saying
$foo->require or die $@;That's not too much to type. It breaks this kind of useful idiom:$this->require or $that->require or die "No alternatives found: $@";and it breaks this kind of portability even moreIt also makes it difficult to write a custom error message - I have to wrap the call in an eval, and so we're back where we starte
Re:storm of protest (Score:1)
No we're not. Now you're wrapping it in eval{}, not in eval "". That's a big win.
rjbs
Re:storm of protest (Score:1)
use Module::Load;
my $module = 'Data:Dumper';
load Data::Dumper; # loads that module
load 'Data::Dumper'; # ditto
load $module # tritto
You can read the docs here [cpan.org]
Re:storm of protest (Score:1)
eval { $fooo->require }. The only win here is if we declared$foo, not$fooo.eval { $foo->reqiure }is still a runtime error.Re:storm of protest (Score:2)
Its not about the amount of typing (well... part of it is). Its about the expectation that require() should die. Even *I'm* surprised to find out that $foo->require doesn't die and I WROTE THE MODULE!
Error checking should be something you turn off, not something you turn on. Especially when it comes to dealing with the World Outside Your Program. Files, networks, etc... things not totally under your program's control a
Er... all of them? (Score:1)
Er... are you assuming that all users of UNIVERSAL::require have their code on CPAN?
Re:Er... all of them? (Score:1)
Re:Er... all of them? (Score:1)
Re:Er... all of them? (Score:1)
You want us to drop every silly web application we've ever written for every client into CPAN?
Stuff that contains business logic that only applies to a guava farmer working in the north-western tasmania local government area of Tasman, who uses Quickbooks and has Internet Explorer specific functionality?
Re:Er... all of them? (Score:2)
Re:Er... all of them? (Score:1)
I might be getting something wrong, though, and I'm not sure whether you'd be able to prevent the instalation from within Makefile.PL. Probably.
Re:Er... all of them? (Score:2)
There is t
Re:Er... all of them? (Score:1)
There is the simple expedient of just not producing a Makefile.
Indeed
Re:Er... all of them? (Score:2)
In that case then its being installed as a dependency of something which itself has not yet been installed. When the dependent thing gets installed its own tests will run and detect if the incompatibility caused a problem.
Oh... you do have tests, right?
Re:Er... all of them? (Score:1)
That, however, poses a problem, as the module was already installed... but maybe you can somehow detect, er... something else O:-)