I have this class which subclasses Str:
use Vimwiki::File::TextProcessingClasses;
unit class Vimwiki::File::ContentStr is Str;
method new(Str:D $string) {
self.Str::new(value => $string);
}
# this method fails
method capitalize-headers() {
self = Vimwiki::File::TextProcessingClasses::HeadlineCapitalizer.new.capitalize-headers(self);
}
The problem is the capitalize-headers method fails with the Cannot modify an immutable error because it's a string. One way I could avoid this problem is to simply not subclass Str and write wrappers for the Str methods I want to use like this:
unit class Vimwiki::File::ContentStr;
has Str $!content;
method uc() {
$!content = $!content.uc;
}
But that got me wondering if instead of writing these wrapper method, there might be something like AUTOLOAD in Raku so that if a method does not exist, the non-existent method could default to being called on the $!content attribute.
Is this possible? Or is there a cleaner way around the immutable object problem?