Transformations in Erlang syntax allowing cache decorator directives above functions to cache them using erl-cache.
This is a fork of spilgames/erl-decorator-pt for Alert Logic.
This application implements a set of transformations in the erlang syntax tree allowing the following:
-
The decorator directive on top of functions in order to add extra functionality to them
-
The ?FUNCTION and ?ARITY macros, returning an atom with the function name corresponding to the current scope and the amount of arguments that function was invoked with. These macros can be used in your decorators.
There are many ways to include these macros in your projects. Just remember macros and macro debugging in particular are not the simplest tools in the world. A great power comes with a great responsibility.
The most common way of using this application is:
-
Make it available to your application via rebar
-
Create an .hrl file loading hooking the decorator_pt_core in the compilation process and defining a macro with a representative name for your decorator. i.e. my_decorator.hrl
-compile([{parse_transform, decorator_pt_core}]).
-define(MY_DECORATOR(Options), -decorate({MyCbModule, MyCbFun, {?MODULE, ?FUNCTION, Options}})).
- Define the callback function in the callback module to your liking. Keep in mind what the signature of your callback should be:
my_cb_fun(OriginalFun::function(), Args::[tern()],
{OriginalModule::atom(), OriginalFunctionName::atom(), Opts::[term()]) ->
FunReturningResult::fun(() -> term()).
- When using your decorator, include my_decorator.hrl and decorator_pt.hrl in that order.
-include_lib("my_app/include/my_decorator.hrl").
-include_lib("decorator_pt/include/decorator_pt.hrl").
[...]
?MY_DECORATOR([{opt1, val}]).
my_decorated_fun() ->
ok.