Passing parameters to parent constructor using Perl’s new class syntax
This question concerns Perl’s class
syntax (new as of Perl 5.38.0). I have two classes, Rectangle
and Square
, with Square
inheriting from Rectangle
. They have different constructor arguments; Rectangle
expects length
& height
while Square
expects just side
. My hope was that Square
would be able to inject the length
and height
arguments into the constructor for Square
‘s parent Rectangle
object, based on side
‘s value. Something akin to this, though the BUILD
syntax from Object::Pad
doesn’t work: