You're halfway there. You must make the right two changes to your code:
class File {
has $.filename;
}
class XmlFile is File {
submethod BUILD(:$filename) { }
}
dd my XmlFile $XF = XmlFile.new(filename => "test.xml");
Replacing $!filenamewith $.filenamein a class Filegenerates a public access method ( .filename) in that class.
( : , .. , . " " " ", .)
! BUILD XmlFile , XmlFile .
Per :
- BUILDALL BUILD new, Mu, .
(, " " . " ".)