74 Function interception
FunctionInterceptor wraps the declared greet call. around calls proceed() once, so the original function still supplies the greeting.
norm
import std.annotation.FunctionInterceptor
import std.annotation.SourceRetention
annotation Trace implements FunctionInterceptor, SourceRetention {
R around<R>(FunctionInvocation<R> invocation) {
printLine("enter")
R result = invocation.proceed()
printLine("leave")
return result
}
}
@Trace()
String greet(String name) { return "Hello, " + name }
main() { printLine(greet(name: "Norm")) }Expected output:
text
enter
leave
Hello, NormTry it: Remove proceed() and inspect how the required return value must be supplied.
Precise rules: Reference.