Die die die UNIVERSAL::require!

schwern on 2005-09-29T17:38:58

As I go back through my old modules, sometimes I wonder why I made certain choices. Today its UNIVERSAL::require which is used a whole lot more than I thought.

0.02 Mon Jun 25 15:00:19 EDT 2001
    * -->API CHANGE!<-- require() no longer dies on failure



Why did I decide to do that? I didn't record anything in the logs about it. I can't remember why I'd think $class->require shouldn't die seeing as how "require $class" does. And it introduced the clunky $UNIVERSAL::require::VERSION error global.

Bleh. Trying to decide if its worth the backwards incompat pain to change it.


another list

domm on 2005-09-29T18:41:53

of dists using it:

http://cpants.perl.org/dist/UNIVERSAL-exports

Seems quite similar to what gonzui says...

Re:another list

schwern on 2005-09-29T22:42:47

Curses! I really wish I could just break compat because dying really is the better thing to do. Maybe I'll throw in a "use UNIVERSAL::require qw(die)" or something.

I wish...

perrin on 2005-09-30T00:42:01

that you hadn't put it in UNIVERSAL::, but that's an entirely different issue.

Re:I wish...

schwern on 2005-10-01T19:00:52

If it wasn't in UNIVERSAL the module wouldn't work. The require method has to exist and be in a class' inheritence hierarchy *before* the class to be required is loaded.

And this really is the sort of thing which should be universal.

Re:I wish...

perrin on 2005-10-03T21:47:21

It only has to be in UNIVERSAL because of the particular API you chose. It would be just as useful as something like this:

Module::Loader->load($module_name);

What bugs me about the current approach is that when I use a CPAN module that loads this, it magically adds require() methods to all of my classes, whether I want them or not.

Re:I wish...

schwern on 2005-10-09T20:34:41

It only has to be in UNIVERSAL because of the particular API you chose.
Yep, but I can't exactly back out of that now. Remember, UNIVERSAL::require is an implementation of a Perl 6 RFC. People started using it. Go figure.
What bugs me about the current approach is that when I use a CPAN module that loads this, it magically adds require() methods to all of my classes, whether I want them or not.
require() is a special case. You're highly unlikely to create a method called "require" as its already a keyword. And, really, its something that classes should be able to do themselves.

my vote

rjbs on 2005-09-30T02:58:59

I'd love for you to fix it, or at least make it easier to get the right behavior. Otherwise, I end up writing the code that should be in there, myself.