Not quite sure what you're asking. Are you looking for a way to change the default for an attribute in a subclass?

package ClassB; use Moose; extends 'ClassA'; has '+param2' => (default => 'PARAM2-CLASSB'); around FOREIGNBUILDARGS => sub { my $orig = shift; my $class = shift; return $class->$orig(param1=>'PARAM1-CLASSB',@_); };

Or better yet, use builders instead of defaults:

package ClassA; use Moose; use MooseX::NonMoose; extends 'aNonMooseClass'; has 'param2' => ( isa=>'Str', builder => '_build_param2'); sub FOREIGNBUILDARGS { my $class = shift; my %args = @_; my $param1 = exists $args{param1} ? $args{param1} : $class->_build +_param1; return ( $param1 ); } sub _build_param1 { return 'Default param1 in class A'; } sub _build_param2 { return 'Default param2 in class A'; } package ClassB; use Moose; extends 'ClassA'; sub _build_param1 { return 'PARAM1-CLASSB'; } sub _build_param2 { return 'PARAM2-CLASSB'; }
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

In reply to Re: NonMoose and (clean) inheritance by tobyink
in thread 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.