Dear perl 6 users,
I am trying to pass a Nil value to a method new of a class that expects a Str.
The method new will assign this Nil value to a Str member variable. Then, this
value will change during runtime.
At the moment I am getting this error: Type check failed in binding $value;
expected Str but got Nil
Here is an simplified example of what I'm doing:
class MyClass {
has Str $.value is rw;
method new (Str $value) {
return self.bless(:$value);
}
submethod BUILD (Str :$!value) {
}
}
$myObject = MyClass.new(Nil); # << this triggers the error
I expect $.value to hold Strings, but I want to be able to instantiate MyClass
whether I have a value already or not, and I also want to be able to tell if
$.value has a real String or not. Is this possible?
If anyone knows a way to do it or has any clue to solve this case, I would be
glad to hear about it.
Thanks to all in advance,
Emiliano