Hello,
I have a class A which inherits from a NonMoose class. Therefor I use FOREIGNBUILDARGS to set the default for the nonMoose class constructor argument:
package ClassA; use Moose; use MooseX::NonMoose; extends 'aNonMooseClass'; has 'param2' => ( isa=>'Str', default=>'Default param2 in class A' ); sub FOREIGNBUILDARGS { my $class = shift; my %args = @_; my $param1 = exists $args{param1} ? $args{param1} : 'Default param +1 in class A'; return ( $param1 ); }
Now I have a regular Moose class B which inherits from class A.
param1 is to be fixed to 'PARAM1-CLASSB' and param2 is to be fixed to 'PARAM2-CLASSB' for all instances. So, I figured this declaration:
package ClassB; use Moose; extends 'ClassA'; around FOREIGNBUILDARGS => sub { my $orig = shift; my $class = shift; return $class->$orig(param1=>'PARAM1-CLASSB',@_); }; around BUILDARGS => sub { my $orig = shift; my $class = shift; return $class->$orig(param2=>'PARAM2-CLASSB', @_); };
As ClassB is based on ClassA I'd prefer to have a uniform way of setting param1 and param2 in ClassB. I don't bother in making ClassA more complex, but I want ClassB to be as user-friendly as possible. Can this be achieved ?
Thanks!
In reply to NonMoose and (clean) inheritance by eco
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |