If require were fixed to return the same value every time (caching the value from the first call), then I'd update all of my OO modules to end with __PACKAGE__; instead of 1; and document how to use that (if you are programming for a version of Perl where require has been fixed).

Though my objects (like many Perl objects) very often have "user preference" type options that are best expressed once (in the use line) so I already provide a way for the module user to get a factory that can construct objects with the user's preferences already taken into account.

An easy way to do this is to allow objects to be constructed from each other so my use lines typically let you list your preferences and where you'd like your master object to be stored. You can just use the one master object or you can use it as a factory (even though it is of the same class as the objects it will be creating).

I'm amused that you appear to think I'd like to write

B::svref_2object(\&function_exported_by_OO_module_of_which_there_shoul +d_not_be_any)->STASH->NAME->new( ... )

in order to avoid typing the name of the module. :)

- tye        


In reply to Re^3: use, require, and constructors (factories++) by tye
in thread use, require, and constructors by YuckFoo

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.