forked from mbbx6spp/rebar-templates
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ztmod.erl
82 lines (67 loc) · 1.88 KB
/
ztmod.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
%%%' HEADER
%%% @author {{author_name}} <{{author_email}}>
%%% @copyright {{copyright_year}} {{author_name}}
%%% @doc gen_server-based Zotonic module:
%%% {{description}}
%%% @end
-module(mod_{{name}}).
-author('{{author_name}} <{{author_email}}>').
-behaviour(gen_server).
-mod_title("{{module_title}}").
-mod_description("{{description}}").
-mod_prio({{module_priority}}).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
-export([start_link/1]).
-include_lib("zotonic.hrl").
-record(state, {context}).
%%%.
%%%' PUBLIC API
%% @doc starts gen_server implementation and caller links to the process too.
%% @spec start_link() -> {ok, Pid} | ignore | {error, Error}
%% where
%% Pid = pid(),
%% Error = {already_started, Pid} | term()
start_link(Args) when is_list(Args) ->
gen_server:start_link(?MODULE, Args, []).
%% @doc stops gen_server implementation process
%% @spec stop() -> ok
stop() ->
gen_server:cast(?MODULE, stop).
% TODO: define public API here.
%%%.
%%%' CALLBACKS
%% @private
init(Args) ->
process_flag(trap_exit, true),
{context, Context} = proplists:lookup(context, Args),
{ok, #state{context=z_context:new(Context)}}.
%% @private
handle_call(Req, _From, State) ->
%{reply, State}.
{stop, {unknown_call, Req}, State}.
%% @private
handle_cast(stop, State) ->
{stop, normal, State};
handle_cast(Req, State) ->
%{noreply, State}.
{stop, {unknown_call, Req}, State}.
%% @private
handle_info(_Info, State) ->
{noreply, State}.
%% @private
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
%% @private
terminate(normal, _State) ->
ok;
terminate(shutdown, _State) ->
ok;
terminate({shutdown, _Reason}, _State) ->
ok;
terminate(Reason, _State) ->
ok.
%%%.
%%%' PRIVATE FUNCTIONS
% TODO: Add private helper functions here.
%%%.
%%% vim: set filetype=erlang tabstop=2 foldmarker=%%%',%%%. foldmethod=marker: