In Control flow§
See primary documentation in context for once.
A block or statement prefixed with once
will be executed exactly once, even if placed inside a loop or a recursive routine.
my $guard; loop { once $guard = 3; last if $guard-- <= 0; once { put 'once' }; print 'many' } # OUTPUT: «oncemanymanymany»
This works per "clone" of the containing code object, so:
({ once 42.say } xx 3).map: {$_(), $_()}; # says 42 thrice
Note that this is not a thread-safe construct when the same clone of the same block is run by multiple threads. Also remember that methods only have one clone per class, not per object.