1.7.3 Module anvl_hook

API for managing the hooks.

Plugins can declare hook points and inject code into other plugin’s hook points.

1.7.3.1 Types

hookpoint()
-type hookpoint() :: term().

1.7.3.2 Functions

first_match(HookPoint, Val)
-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.

foreach(HookPoint, Arg)
-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.

fold(HookPoint, Acc0)
-spec fold(hookpoint(), Acc) -> Acc.

If F1, F2, ..., FN are hooks registered at HookPoint, return FN(...(F2(F1(Acc0))).

traverse(Fun, Acc, HookPoint)
-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.

add(HookPoint, Priority, Fun)
-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.

add(HookPoint, Fun)
-spec add(hookpoint(), fun()) -> ok.

Add a hook Fun to the HookPoint with default priority (0).


JavaScript license information