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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |