thank you very much for your answer. ++ And, yes, it does work and solve the issue.
And although I said that the get method was not seeing $!z, yes, I also suspected that it could also possibly be the constructor not setting it, but had not real way to tell the difference.
There may probably be some good reasons for that behavior, but I find it is sort of a pity that the default new constructor can't deal with private attributes, thus forcing the user to use a lower-lever BUILD submethod, especially in view of the fact that the documentation says again and again that attributes are defaulted to private. Also this seems to lead to the fact that if I have another class inheriting from Dot (which I do have in my real case), then that subclass will also presumably need the BUILD submethod, since submethods are not inherited to the child methods, which is less practical. Well, this is just said from the tip of my mind, I have to do further testing to fully understand the implications.
The example I gave in my original post was just a much simplified version of the code I was working on, which had quite a few other methods: this simplified code was just trying to investigate and show the problem with the smallest possible program, in accordance with the usual PM guidelines. The only reason I had public x and y and private z in this example here was not that there was anything special about z, but was to show clearly the difference between the two situations. My real aim (in my real program) was to try to build strong encapsulation for all attributes. I can see that this is quite possible, but less naturally that I was hoping it to be.
As for your update about smarter ways to print the object's content, yes, I know and I tried them in various ways (both inside and outside the class), but, in the sample code here, I just wanted to display the list of values returned by the get method to show my problem with the private $!z attribute.
Well, anyway, again, thanks a lot for your very useful explanations.
In reply to Re^2: Private attributes in Perl 6 objects
by Anonymous Monk
in thread Private attributes in Perl 6 objects
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |