develooper Front page | perl.perl6.users | Postings from April 2018

inheritance and default attributes

Thread Next
Theo van den Heuvel
April 30, 2018 08:55
inheritance and default attributes
Message ID:
Hi all,

trying to make sense of the following excerpt from the documentation on 
object construction:

  Due to the default behavior of BUILDALL and BUILD submethods, named 
arguments to the constructor new derived from Mu
  can correspond directly to public attributes of any of the classes in 
the method resolution order, or to any named
  parameter of any BUILD submethod.

I would like to build a class A and subclasses AB and more such that AB 
and friends differ in the default attribute values. On the basis of the 
docs I expected this to work:

class A {
   has Int $.a;
   method sayit() { say $!a }

class AB is A {
   submethod BUILD(:$!a = 17){}

my $ab =;

however. I get "Attribute $!a not declared in class AB", which makes 
How should I write this instead?


Theo van den Heuvel
Van den Heuvel HLT Consultancy

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About