No such thing as a small change | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
I like the concept. I took a similar, though slightly different, approach in Math::Random::OO, where I have several subclasses and didn't want to type out the full constructor each time. In short, I have my main module export a "factory function" (better names welcomed) that encapsulates a call to the constructor. So you can do this:
I did it by writing a quick custom import function like so (though as I post it, I see that I'm not checking for certain errors -- grrr -- bad style, slap on the wrist for me.):
Your module sounds like a generalization of this approach, albeit still requiring the call to new. As for names, I'd prefer if your module were named "Alias" or something similar, as what you're doing is aliasing, not defining or altering a class. How about some syntax like this:
(update:Alias is already used, so I guess it has to be something else.) The first example is simpler than than using "as" as a keyword. The second keeps the real name and options together and still is suggestive that, in the end, you're aliasing it to ShortForm. update:I wasn't familiar with Package::Alias and namespace, both look like they do pretty much the same as what I've got above. update 2:I guess the advantage of what Ovid's trying to do compared to, say, Package::Alias is that he gets it done in a single function call, rather than a "use" and an "alias" afterwards. May I humbly suggest "Nickname" as the module name, with a syntax like I suggest above for brevity in the standard case with no extra import options?
-xdg Code posted by xdg on PerlMonks is public domain. It has no warranties, express or implied. Posted code may not have been tested. Use at your own risk. In reply to Re: Module Naming Dilemma
by xdg
|
|