I not a fan of the idea of exporting procedural-style class constructors from modules, since it kind of hides the OO, and a symbol like "newButton" could be handy to users of your library elsewhere. IMHO exporting symbols can get real messy, real fast.

There is always the not-so-great indirect object syntax:

$b = new Foo::Button @args
but that can sometimes be more trouble than its worth.

What about the syntax length bothers you? Are your modules nested deeply? (ex: Olga::Ming::Widgets::Button) If so, you could create your own class loader for your framework. I have done this with the object framework I have been working on and it works quite well. Here is the syntax :

use iI::Framework qw( Web.Request Web.ModPerl.DispatchHandler );
Then the iI::Framework module's import method simply changes all the "."s to "/"s and requires each module. After that the modules can then be refered to as "Request" and "DispatchHandler" instead of "iI::Web::Request" and "iI::Web::ModPerl::DispatchHandler". Its a little weird (maybe not terribly perl-ish), but it keeps my module name length down and still allows me to organize the almost 100 different classes I have into a neat tidy folder heirarchy.

-stvn

In reply to Re: Foo::Button->new vs. newButton() by stvn
in thread Foo::Button->new vs. newButton() by bakunin

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.