sub add-numbers(&log, $x, $y) {
log("Adding $x and $y");
$x + $y;
}
sub multiply-numbers(&log, $x, $y) {
log("Multiplying $x and $y");
$x * $y;
}
sub my-program(&log, $x, $y) {
say add-numbers(&log, $x, $y);
say multiply-numbers(&log, $x, $y);
}
sub MAIN() {
my &*log;
say "\n", 'No logging at all.';
my-program(-> $msg { }, 1, 2);
say "\n", 'Log only additions (filtering).';
my-program({ .say if m/Adding/ }, 1, 2);
say "\n", 'Log in all caps.';
my-program({ .uc.say }, 1, 2);
say "\n", 'Log all messages.';
my-program(&say, 1, 2);
}