{"id":13836770,"url":"https://github.com/egobrain/erlang_decorators","last_synced_at":"2025-10-21T17:38:31.753Z","repository":{"id":3670657,"uuid":"4739783","full_name":"egobrain/erlang_decorators","owner":"egobrain","description":"This code implenets decorators for erlang.","archived":false,"fork":false,"pushed_at":"2018-05-10T10:17:45.000Z","size":19,"stargazers_count":29,"open_issues_count":0,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-09T01:48:34.367Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/egobrain.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-06-21T13:57:14.000Z","updated_at":"2024-07-26T09:12:09.000Z","dependencies_parsed_at":"2022-08-28T20:01:49.237Z","dependency_job_id":null,"html_url":"https://github.com/egobrain/erlang_decorators","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egobrain%2Ferlang_decorators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egobrain%2Ferlang_decorators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egobrain%2Ferlang_decorators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egobrain%2Ferlang_decorators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/egobrain","download_url":"https://codeload.github.com/egobrain/erlang_decorators/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225647787,"owners_count":17502130,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T15:00:54.166Z","updated_at":"2025-10-21T17:38:31.676Z","avatar_url":"https://github.com/egobrain.png","language":"Erlang","funding_links":[],"categories":["Erlang"],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/egobrain/decimal.png?branch=master)](https://travis-ci.org/egobrain/erlang_decorators.png?branch=master)\n[![GitHub tag](https://img.shields.io/github/tag/egobrain/erlang_decorators.svg)](https://github.com/egobrain/erlang_decorators)\n[![Hex.pm](https://img.shields.io/hexpm/v/erlang_decorators.svg)](https://hex.pm/packages/erlang_decorators)\n\nerlang_decorators\n=================\n\nThis code implenets decorators for erlang.\n\nUsage\n=====\n\nInternal\n------\n\nFirst of all you need set `{parser_transform, decorators}` compile option.\n\n```Erlang\n-compile([{parse_transform, decorators}]).\n```\nand then specify `decorate` attribute before funcion definition.\n\n```Erlang\n-decorate(DecoratorSpec).\nmy_function(...) -\u003e ... .\n```\n\nDecoratorSpec:\n   - `{Module :: module(), Fun :: atom()}` - will call `Module:Fun(F, Args)`, where\n`F` is function with arity 1, which takes a list as argumets and apply this list to original function,\nand `Args` is a decorated function arguments list.\n   - `{Module :: module(), Fun :: atom(), Args :: [any()]}` - same as previous, but you can\nspecify aditional decorator function arguments. `Module:Fun(F, Args, Arg1, Arg2, ...) will be called.\n   - `{Module :: module(), Fun :: atom(), Args :: [any()], verbose}` - if you specify `verbose` option,\nthe third decorator function argument will be an a tuple of original function name and code line:\n`{FuncName :: atom(), Line :: non_neg_integer()}`. `Module:Fun(F, Args, {FunName, Line}, Arg1, Arg2, ...) will be called.\n\nExternal\n--------\n\nYou can also specify decorators from outside of module at compile time.\n\nFirst of all you must tell compiler to use *decorators* parse_transform globaly.\nAnd then specify compile `decorate` option, which describes how to decorate modules functions.\nSyntax:\n```Erlang\n{decorate,\n    [\n     {Module :: module(),\n     [\n      {{Fun :: atom(), Arity :: non_neg_integer() | '*'} | '*',\n       [DecoratorSpec, ...]},\n      ...\n     ],\n     ...\n    ]}\n```\n\nExamples\n========\n\nInternal\n--------\n\n```Erlang\n\n-module(my_module).\n\n-compile([{parse_transform, decorators}]).\n\n%% decorator\n-export([\n         log_result/2\n        ]).\n\n%% Decorated function\n-export([\n         foo/1\n        ]).\n\nlog_result(Fun, Args) -\u003e\n    Result = Fun(Args),\n    io:format(\"Result is: ~p\", [Result]),\n    Result.\n\n-decorate({?MODULE, log_result}).\nfoo(Bar) -\u003e\n    Bar*100.\n\n```\n\n\nExternal\n--------\n\n*rebar.config*\n\n```Erlang\n{erl_opts,\n [\n  {parse_transform, decorators},\n  {decorate,\n   [\n    {my_module1,\n     [\n      {{fun1, 0}, [{my_decorators, decorator1}]},\n      {{fun2, 0}, [\n                   {my_decorators, decorator1},\n                   {my_decorators, decorator2}\n                  ]},\n     ]},\n    {my_module2,\n     [\n      {{fun2, 0}, [\n                   {my_decorators, decorator3, [tag]},\n                   {my_decorators, decorator4, [tag], verbose}\n                  ]}\n     ]}\n   ]},\n   ...\n ]}.\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegobrain%2Ferlang_decorators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fegobrain%2Ferlang_decorators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegobrain%2Ferlang_decorators/lists"}