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!

-- ecocode

In reply to NonMoose and (clean) inheritance by eco

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.