Can I choose between Perl 6 multis that have no parameters?
You could destructure the |
with ()
.
my $*DEBUG = 1;
show-env();
$*DEBUG = 0;
show-env();
# use an unnamed capture | but insist it has 0 arguments by destructuring
multi show-env ( | () where ? $*DEBUG ) { dd %*ENV }
multi show-env ( | () where ! $*DEBUG ) { True }
show-env(42); # Cannot resolve caller show-env(42); …
Or you could have a proto
declaration
proto show-env (){*}
multi show-env ( | where ? $*DEBUG ) { dd %*ENV }
multi show-env ( | where ! $*DEBUG ) { True }
show-env(42); # Calling show-env(Int) will never work with proto signature () …
A more elegant way to insist that the capture is empty is to specify it with an empty sub-signature:
multi show-env ( | () where ? $*DEBUG ) { dd %*ENV }
multi show-env ( | () where ! $*DEBUG ) { True }