[erlang-questions] Replacing a module with another module

Dmitry Demeshchuk demeshchuk@REDACTED
Thu Apr 21 07:15:02 CEST 2011

Actually, this task is very similar to how meck, effigy and similar stuff work.

So, there's a module named foo that is working. And there's a module
foo_mock, we want to mock a lot of stuff from the module foo here. Of
course, we could just use 'start_mocking' function where we declare
standard meck rules, like

meck:expect(foo, bar, 0, fun() -> stuff end).
meck:expect(foo, bar2, 0, fun() -> stuff2 end).

But this is obviously ugly.

So, the more general way of solving this is to get abstract code of
the module foo using beam_lib, map through it, replacing the module
atoms, and compiling it back again.

My questions are:
1. Is there an easier way? (Besides loading a module with the same
name from another path, the circumstances don't allow me that)
2. Hasn't anyone already done that? Maybe I'm trying to re-invent
something obvious here.

Best regards,
Dmitry Demeshchuk

More information about the erlang-questions mailing list