I have this class which is basically a wrapper for a Str attribute:
use Vimwiki::File::TextProcessingClasses;
unit class Vimwiki::File::ContentStr;
has Str $!content;
submethod BUILD( :$content ) {
$!content = $content;
}
method gist {
return $!content;
}
method capitalize-headers() {
$!content = Vimwiki::File::TextProcessingClasses::HeadlineCapitalizer.new.capitalize-headers($!content);
}
Seems like it would be more efficient to subclass the core Str class with something like this, similar to a trick I learned for subclassing IO::Path:
class Blah is Str {
method !SET-SELF() {
self;
}
method new(Str:D $string) {
self.Str::new($string)!SET-SELF();
}
}
my $blah = Blah.new('hello');
say $blah;
However, this throws an error: Default constructor for 'Blah' only takes named arguments