Loads of Christmas cheer

by Jerrad Pierce

Apologies for calendar spottiness. Crummy term papers are finally in, and we now return you to your regularly scheduled programming.

DynaLoader makes the use of giant C libraries like the POSIX module a lot less hairy by only loading those functions you use/request, as opposed to only exposing those you request as is the case with a traditional import. That's interesting and all, but XS is so arcane. What about us mortals?

After reading Friday's entry, I thought to myself that there ought to be some simple way of consolidating the examples into a single script that wouldn't load unnecessary code. At this point I rediscovered SelfLoader, a pure perl analog to DynaLoader. SelfLoader provides deferred compilation (and some of the potential pitfalls that entails) of rarely used code and is ideal for large libraries; where, it seems to this author, it is unfortunately underused. This magic is achieved through AUTOLOAD and string eval, meaning we are also able to defer dependencies with no extra effort if they are used where needed e.g; lines 65 & 74. An additional feature—of debatable merit some would argue—when using SelfLoader to provide for minimal loading and export of a library's functions is that because it uses AUTOLOAD, one needn't bother with potentially long and cumbersome import lists.

A few other adjustments, and this single script is ready for primetime on both barebones servers and decked-out desktops alike.