|
|
| laziness, impatience, and hubris | |
| PerlMonks |
Re: Conditional and opt-in breaking change: is this design viable and my use of 'import' OK?by choroba (Cardinal) |
| on Oct 04, 2024 at 18:38 UTC ( [id://11162064]=note: print w/replies, xml ) | Need Help?? |
|
For object oriented modules, your approach is fragile and non standard. Usually, when you need to instantiate objects, but the objects could be of several different classes based on what the user needs, you can use the Builder pattern. When building the builder object, you pass it all the arguments common to all the constructors of the different classes it can instantiate, it can then have several builder methods, one for each class, which take the arguments specific for the class's constructor. If some of the methods have the same implementation in multiple classes, create an abstract parent class from which all the classes inherit (Foo::Common below), or use roles to implement the methods (not shown in the example below). OO classes don't usually export anything. To import constants, use a dedicated class. For a small project, this might seem like a Java-level verbosity. For larger projects, one would get mad at handling the different flags and ternaries in method implementations; with the Builder pattern you always know where to look when you need to see the implementation of a particular behaviour - and if it's not in the file, it tells you where to look further (parent or role). I've used this at a $job - 2 with tens of constructor parameters, built on Moose. It worked great.
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||||