Skip Menu |

This queue is for tickets about the UNIVERSAL-require CPAN distribution.

Report information
The Basics
Id: 44444
Status: resolved
Priority: 0/
Queue: UNIVERSAL-require

People
Owner: Nobody in particular
Requestors: kane [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.11
Fixed in: (no value)



Subject: UNIVERSAL::require does not reset $@
The synopsis suggests to use U::require as: $module->require or die $@; However, ->require does not reset $@ if the module is already loaded. So if a user would (as DBIx::Class currently does) do something like this: $module->require or die $@; ... eval { ... some code that dies ... }; warn $@ if $@ ... $module->require or die $@; The code will die for completely the wrong reasons. The fix is to add an eval { 1 }; at the top of sub require { }, so the code in the synopsis can still be used, and is backwards compatible.
On Fri Mar 20 12:17:39 2009, KANE wrote: Show quoted text
> The synopsis suggests to use U::require as: > > $module->require or die $@; > > However, ->require does not reset $@ if the module is already loaded. > So if a user would (as DBIx::Class currently does) do something like this: > > $module->require or die $@; > ... > eval { ... some code that dies ... }; > warn $@ if $@ > ... > $module->require or die $@; > > The code will die for completely the wrong reasons.
But the code won't die, because the second require succeeds. And if it fails $@ will get reset. I don't see the user visible bug here. But I can imagine code like this: $module->require; die $@ if $@; Suspiciously similar to your eval/warn code above. It suffers from the general assumption that $@ should not be used to indicate an exception has happened. You should always test the eval or method directly (and I will now quickly fix all the instances inside UNIVERSAL::require which violate this). Anyhow, the work is done and it removes a common trap.
0.13 has been released.