perlmoose

In Moose, how to specify constructor arguments for the superclass in a subclass?


I have a Moose class with some properties (x,y,z). I subclass it, and for the subclass, x is always 3. How can I specify this in subclass?


Solution

  • One could use BUILDARGS.

    around BUILDARGS => sub {
        my $orig  = shift;
        my $class = shift;
     
        return $class->$orig(@_, x => 3 );
    };