Created
July 20, 2019 08:07
-
-
Save antoniogamiz/3b9fa8fa4a284ab84518480b0506a307 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A { | |
has $.verbose; | |
submethod BUILD ( | |
:$verbose | |
) { | |
} | |
} | |
class B is A { | |
has $.attr; | |
submethod BUILD( | |
:$attr | |
) { | |
} | |
} | |
my $b = B.new(verbose => "dd", attr => "dddd"); | |
say $b; # B.new(attr => Any, verbose => Any) |
Oooohh I see! Thanks a lot for taking the time with this! I really appreciate it :D.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Remember that if you want it to populate the attributes, you need:
BUILD
submethod's body:For the class A's
BUILD
, you could do:verbose($!verbose)
right in theBUILD
's signature. The same forB
. But isn't:verbose($!verbose)
too verbose? You can use:$!verbose
instead. I guess that's probably what you meant but missed the elusive!
in the named parameter and that's why you gotB.new(attr => Any, verbose => Any)
.Per the docs,
I think the use of the
BUILD
submethod is also discouraged. Instead, you might want to use theTWEAK
submethod.