UNIVERSAL::new for command line MU

Using object-oriented modules from the command line can be a PITA. I have to type the module name twice: once to load it and once to construct objects with it. In a program, that's not huge overhead, but in a one-liner, it annoys me every time.

So I wrote UNIVERSAL::new and a handy alias U. It lets you call "new" on a module name and have it loaded on the fly. Like this:

It is indeed elegant but unfortunately quite slow. I was regretting the need to write a long module name just yesterday when I was doing some simple searches in the mailbox using perl -MMail::MboxParser -E '... Mail::MboxParser->new("mbox") ... . It definitely looks much better with just -MU in the start but the original one liner was instantaneous (just measured it now and it was running in ~0.05s) while the new one is not -- it adds about 0.8s, which is noticeable amount of time, to the running time.

So this is still very nice for longer running one-liners but if you want to not only type it fast but also run it fast, it's better to stick to writing the module name twice.

I've tested it with just "time" under Debian Linux. The machine is relatively new machine (i7 2600 with lots of RAM) but doesn't use SSD, so the disk access latency could be the issue.

Another possible explanation could be the difference in the Perl versions used as you're probably using something much more recent than 5.10.1 that Debian Squeeze has. Do you know if later versions improved anything that could affect this? Looking at the (few lines of) code in the module I don't see anything immediately obvious but I'm hardly an expert in Perl internals...

And FWIW, of course I don't normally care about 0.8s difference neither. But the difference between "instantaneous" and "taking some time" is still noticeable and a bit annoying.

I'm loading modules with Module::Runtime, which works around some bugs in older Perls, including 5.10.1. That could be an issue. I'll do some more testing and see. For this, I wouldn't cringe too much to do a string eval require if that shaves a big chunk of time off.