Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

getting starting in erlang

  • Loading branch information...
commit 1cbebfc52f8f941c72ce64636483771aa2d0aa81 1 parent 43e3f30
Blake Mizerany bmizerany authored
1  .gitignore
View
@@ -0,0 +1 @@
+ebin/*.beam
7 Rakefile
View
@@ -0,0 +1,7 @@
+task :default do
+ sh "erlc +debug_info -W2 -o ebin #{Dir["src/*.erl"].join(" ")}"
+end
+
+task :c => [:default] do
+ sh "erl -boot start_sasl -pa ./ebin -pa ./ebin/*/ebin"
+end
8 ebin/subsucka.app
View
@@ -0,0 +1,8 @@
+{application, subsucka,
+ [{description, "Moving you from SVN even faster!"},
+ {vsn, "0.1.0"},
+ {modules, [subsucka, subsucka_app, subsucka_server]},
+ {registered, [subsucka_server]},
+ {applications, [kernel, stdlib]},
+ {mod, {subsucka_app, []}}
+]}.
9 src/subsucka.erl
View
@@ -0,0 +1,9 @@
+-module (subsucka).
+-export ([start/0, stop/0]).
+
+start() ->
+ application:load(subsucka),
+ application:start(subsucka).
+
+stop() ->
+ application:stop(subsucka).
9 src/subsucka_app.erl
View
@@ -0,0 +1,9 @@
+-module(subsucka_app).
+-behaviour(application).
+-export([start/2, stop/1]).
+
+start(_Type, _StartArgs) ->
+ subsucka_server:start_link().
+
+stop(_State) ->
+ subsucka_server:stop().
90 src/subsucka_server.erl
View
@@ -0,0 +1,90 @@
+-module(subsucka_server).
+
+-behaviour(gen_server).
+
+%% API
+-export([start_link/0]).
+
+%% gen_server callbacks
+% -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
+% terminate/2, code_change/3]).
+-compile([export_all]).
+
+-define(SERVER, subsuka_server).
+
+%%====================================================================
+%% API
+%%====================================================================
+%%--------------------------------------------------------------------
+%% Function: start_link() -> {ok,Pid} | ignore | {error,Error}
+%% Description: Starts the server
+%%--------------------------------------------------------------------
+start_link() ->
+ gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
+
+%%====================================================================
+%% gen_server callbacks
+%%====================================================================
+
+%%--------------------------------------------------------------------
+%% Function: init(Args) -> {ok, State} |
+%% {ok, State, Timeout} |
+%% ignore |
+%% {stop, Reason}
+%% Description: Initiates the server
+%%--------------------------------------------------------------------
+init([]) ->
+ {ok, []}.
+
+%%--------------------------------------------------------------------
+%% Function: %% handle_call(Request, From, State) -> {reply, Reply, State} |
+%% {reply, Reply, State, Timeout} |
+%% {noreply, State} |
+%% {noreply, State, Timeout} |
+%% {stop, Reason, Reply, State} |
+%% {stop, Reason, State}
+%% Description: Handling call messages
+%%--------------------------------------------------------------------
+handle_call({import, Uri}, _From, State) ->
+ Reply = ok,
+ io:format("~p~n", [Uri]),
+ {reply, Reply, State}.
+
+%%--------------------------------------------------------------------
+%% Function: handle_cast(Msg, State) -> {noreply, State} |
+%% {noreply, State, Timeout} |
+%% {stop, Reason, State}
+%% Description: Handling cast messages
+%%--------------------------------------------------------------------
+handle_cast(_Msg, State) ->
+ {noreply, State}.
+
+%%--------------------------------------------------------------------
+%% Function: handle_info(Info, State) -> {noreply, State} |
+%% {noreply, State, Timeout} |
+%% {stop, Reason, State}
+%% Description: Handling all non call/cast messages
+%%--------------------------------------------------------------------
+handle_info(_Info, State) ->
+ {noreply, State}.
+
+%%--------------------------------------------------------------------
+%% Function: terminate(Reason, State) -> void()
+%% Description: This function is called by a gen_server when it is about to
+%% terminate. It should be the opposite of Module:init/1 and do any necessary
+%% cleaning up. When it returns, the gen_server terminates with Reason.
+%% The return value is ignored.
+%%--------------------------------------------------------------------
+terminate(_Reason, _State) ->
+ ok.
+
+%%--------------------------------------------------------------------
+%% Func: code_change(OldVsn, State, Extra) -> {ok, NewState}
+%% Description: Convert process state when code is changed
+%%--------------------------------------------------------------------
+code_change(_OldVsn, State, _Extra) ->
+ {ok, State}.
+
+%%--------------------------------------------------------------------
+%%% Internal functions
+%%--------------------------------------------------------------------
Please sign in to comment.
Something went wrong with that request. Please try again.