[erlang-questions] Switching between http/non-http depending of first byte
Ngoc Dao
ngocdaothanh@REDACTED
Fri Oct 2 08:33:57 CEST 2009
Smerl in ErlyWeb:
http://code.google.com/p/erlyweb/source/browse/trunk/src/smerl/smerl.erl
allows you to manipulate existing modules and functions just like in Ruby.
You can use Smerl to monkeypatch Yaw's yaws_server module's aloop function.
Example:
a.erl
------
-module(a).
-compile(export_all).
f() -> 1.
b.erl
------
-module(b).
-compile(export_all).
f_with_feature() -> a:f_without_feature() + 1.
t.erl
-----
-module(t).
-compile(export_all).
t() ->
% Take out metamods of the 2 modules
{ok, MA1} = smerl:for_module(a),
{ok, MB1} = smerl:for_module(b),
% Take out forms of the 2 functions
{ok, FA1} = smerl:get_func(MA1, f, 0),
{ok, FB1} = smerl:get_func(MB1, f_with_feature, 0),
% Rename functions in the 2 forms
FA2 = smerl:rename(FA1, f_without_feature),
FB2 = smerl:rename(FB1, f),
% Remove and add functions to module a
MA2 = smerl:remove_func(MA1, f, 0),
{ok, MA3} = smerl:add_func(MA2, FA2),
{ok, MA4} = smerl:add_func(MA3, FB2),
smerl:compile(MA4),
io:format("~p~n", [a:f()]).
Ngoc
On Fri, Oct 2, 2009 at 1:44 PM, Max Lapshin <max.lapshin@REDACTED> wrote:
> As I've already told, I refused from original idea, but in any case,
> such thing may be useful.
> There are some features in erlang, that are undocumented, but required
> for normal work,
> such as prim_inet:async_accept.
More information about the erlang-questions
mailing list