I can select multi based on some value other than the argument, but I must have at least one argument so that I can where :
our $*DEBUG = 1; debug( 'This should print', 'Phrase 2' ); $*DEBUG = 0; debug( 'This should not print' ); multi debug ( *@a where ? $*DEBUG ) { put @a } multi debug ( *@a where ! $*DEBUG ) { True }
It seems that I recall some kind of trick that someone used to send to multis, which did not take exactly any parameters. For example, I have a show-env routine that I would like to sprinkle, and that only does anything if I set some debugging conditions. I could achieve this, as I have shown, but it is not very satisfactory, and this is not what I think I saw elsewhere:
our $*DEBUG = 1; debug( 'This should print', 'Phrase 2' ); show-env(); $*DEBUG = 0; debug( 'This should not print' ); show-env(); multi debug ( *@a where ? $*DEBUG ) { put @a } multi debug ( *@a where ! $*DEBUG ) { True }
I could do something similar with additional named parameters, but that was even less satisfying.
Of course, I could only do this with this simple example, but this is not fun:
sub show-env () { return True unless $*DEBUG; dd %*ENV; }
source share