anvl_hook ¶API for managing the hooks.
Plugins can declare hook points and inject code into other plugin’s hook points.
-spec first_match(hookpoint(), _Input) -> {value,
_Return} |
false.
Pass Val to functions registered at HookPoint.
Stop iteration and return {value, Ret} when hook returns {true, Ret}.
Otherwise return false.
-spec foreach(hookpoint(), term()) -> boolean().
Pass Arg to all functions registered at HookPoint.
The hook type must be (Arg) -> boolean().
The return value is a boolean, calculated similar to lists:any/2.
-spec fold(hookpoint(), Acc) -> Acc.
If F1, F2, ..., FN are hooks registered at HookPoint,
return FN(...(F2(F1(Acc0))).
-spec traverse(fun((fun(), Acc) -> {boolean(), Acc}),
Acc, hookpoint()) -> Acc.
A generic function that traverses through hooks registered at HookPoint and passes them as an argument to Fun together with the accumulator value.
Fun should return a tuple where the first element is a boolean and the second is new value of the accumulator.
If it returns {true, Acc2} and the next hook exists,
Fun will be called again the next next hook and the new value of
the accumulator as arguments. Otherwise iteration stops and
accumulator is returned.
-spec add(hookpoint(), integer(), fun()) -> ok.
Add a hook Fun to the HookPoint with the given priority.
Hooks with a higher priority are executed earlier.
-spec add(hookpoint(), fun()) -> ok.
Add a hook Fun to the HookPoint with default priority (0).