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:

use Math::Random::OO qw( Uniform UniformInt Normal Bootstrap ); $uniform = Uniform(-1,1); $uni_int = UniformInt(1,6); $normal = Normal(1,1); $boot = Bootstrap( 2, 3, 3, 4, 4, 4, 5, 5, 5 );

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.):

sub import { my ($class, @symbols) = @_; my $caller = caller; for (@symbols) { no strict 'refs'; my $subclass = "Math::Random::OO::$_"; eval "require $subclass"; *{"${caller}::$_"} = eval "sub { return ${subclass}->new(\@_) }"; } }

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:

use Alias 'My::Long::Class::Name' => 'ShortForm'; use Alias [ 'My::Long::Class::Name', @options ] => 'ShortForm';

(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?

use Nickname 'My::Long::Class::Name' => 'ShortForm'; use Nickname [ 'My::Long::Class::Name', @options ] => 'ShortForm';

-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
in thread Module Naming Dilemma by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.