|P is for Practical|
Factory Pattern in Perl6by hardburn (Abbot)
|on May 13, 2016 at 22:39 UTC||Need Help??|
hardburn has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to write a Factory pattern in Perl6, and I need to pass the same arguments to the constructor of each class. All the examples of Perl6 Factories out there right now seem to have neglected trying to pass arguments.
In Perl5, I would probably set a variable to hold the classname, and then pass the args after we figure out where we want to go.
Alternatively, you can wrap up the arguments and rely on list flattening to take care of it:
My first attempt in Perl6 followed the first method above:
But this resulted in an object from Any, not the class I wanted.
I also took a stab at the second method, attempting to use the | list flattening operator:
Along with a few variations, most of which failed with Default constructor for 'ClassA' only takes named arguments.
Help for either option would be enlightening.
"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.