[ewgi commit] r75 - branches/RB-0.2/lib/ewgi/src

1 view
Skip to first unread message

codesite...@google.com

unread,
Oct 19, 2008, 8:45:49 AM10/19/08
to ewgi...@googlegroups.com
Author: huntermorris
Date: Sun Oct 19 05:45:45 2008
New Revision: 75

Modified:
branches/RB-0.2/lib/ewgi/src/ewgi_application.erl

Log:
Simplified 'callable' definition

Added useful middleware applications


Modified: branches/RB-0.2/lib/ewgi/src/ewgi_application.erl
==============================================================================
--- branches/RB-0.2/lib/ewgi/src/ewgi_application.erl (original)
+++ branches/RB-0.2/lib/ewgi/src/ewgi_application.erl Sun Oct 19 05:45:45
2008
@@ -28,6 +28,9 @@
%% Public API
-export([run/2]).

+%% Useful middleware
+-export([module_mw/1, rpc_mw/3, mfa_mw/2]).
+
%% Behaviour callback information
-export([behaviour_info/1]).

@@ -37,6 +40,31 @@
undefined.

run(Application, Context) when is_function(Application, 1) ->
- Application(Context);
-run(Application, Context) ->
- Application:handle(Context).
+ Application(Context).
+
+%% @spec module_mw(Module::term()) -> function()
+%% @doc Produces a middleware application which calls the handle/1
function exported by Module.
+-spec(module_mw/1 :: (any()) -> fun(({tuple(), tuple()}) -> {tuple(),
tuple()})).
+module_mw(Module) ->
+ F = fun(Context) ->
+ Module:handle(Context)
+ end,
+ F.
+
+%% @spec rpc_mw(Node::atom(), Module::atom(), Fun::atom()) -> function()
+%% @doc Produces a middleware application which calls the remote function
Module:Fun on Node.
+-spec(rpc_mw/3 :: (atom(), atom(), atom()) -> fun(({tuple(), tuple()}) ->
{tuple(), tuple()})).
+rpc_mw(Node, Module, Fun) ->
+ F = fun(Context) ->
+ rpc:call(Node, Module, Fun, [Context])
+ end,
+ F.
+
+%% @spec mfa_mw(Module::atom(), Fun::atom()) -> function()
+%% @doc Produces a middleware application which calls the function
Module:Fun(Args)
+-spec(mfa_mw/2 :: (atom(), atom()) -> fun(({tuple(), tuple()}) ->
{tuple(), tuple()})).
+mfa_mw(Module, Fun) when is_atom(Module), is_atom(Fun) ->
+ F = fun(Context) ->
+ apply(Module, Fun, [Context])
+ end,
+ F.

Reply all
Reply to author
Forward
0 new messages