[erlang-questions] How to call a module's local function from within an external fun
Fri Nov 25 19:29:08 CET 2011
I'm trying to write a test tool that can be used to send and expect
messages over a custom protocol. I would like the tests themselves to
be supplied as funs from outside the module so that:
test_module:run_test(TestModulePid, fun() -> send(...), expect(...) end).
would end up calling send() and expect() from test_module, as if the
fun was executed in the "context" of the module (i.e. as if it were
defined directly within run_test() and not supplied to it). The
resulting "API" would look like some kind of DSL specialized to define
In my case I need multiple test_modules to run in parallel, so I can't
use a single "test_module" registered name. It would be simple to have
test_module export both send() and expect() so that the following
test_module:run_test(TestModulePid, fun(TestModulePid) ->
test_module:expect(TestModulePid, ...) end).
but I don't like the extra verboseness of having to write
test_module:... all the time.
I _think_ that I might be able to use parse transforms to achieve what
I want but I wanted to know if there would be an easier way.
More information about the erlang-questions