In this particular case you don't even need a custom accessor. You can create extra constraints on your base type constraint with a where
clause:
class Wizzard {
has Int $.mana is rw where * > 0;
}
But if you did want to create a custom accessor you simply have to define a method with the same name and add the is rw
trait.
method mana is rw {
say "running out of mana" if $!mana < 20;
$!mana;
}
You will still be able to use equals assignment syntax like $wizard.mana = 50
but you will not be able to capture the value before it is assigned. If you want something even more fine grained explain Proxy