Copyright © (c) WhatsApp Inc. and its affiliates. All rights reserved.
Authors: Maxim Fedorov (maximfca@gmail.com).
Allows to inject proxy functions into existing modules, compiled with debug into. Added proxy functions are just redirecting calls to another module.
This could be useful for environments where both shell_default and user_default are already used, and it's not possible to replace any of these.eject/2 | Verifies that current WhereFrom has injected functions from Mod, and purges/deletes WhereFrom code from memory. |
inject/2 | Extracts abstract code from WhereTo module, adds all exports from the module Mod into WhereTo, compiles result and loads it, replacing current WhereTo. |
eject(WhereFrom::module(), Mod::module()) -> ok | {error, not_loaded}
WhereFrom: original module name, e.g. shell_default
Mod: module that has been injected
Verifies that current WhereFrom has injected functions from Mod, and purges/deletes WhereFrom code from memory. Next time shell does ensure_loaded() for WhereFrom, an unmodified version is loaded from disk.
inject(WhereTo::module(), Mod::module()) -> ok | {error, already_loaded} | {error, no_abstract_code} | {error, {badmatch, module()}} | {error, {beam_lib, beam_lib:chnk_rsn()}}
WhereTo: Module name to add proxy methods to
Mod: Module name to proxy calls to
Extracts abstract code from WhereTo module, adds all exports from the module Mod into WhereTo, compiles result and loads it, replacing current WhereTo. This sequence injects proxies for all functions exported from Mod into WhereTo (ignoring compiler-generated module_info/0 and module_info/1). For example, if Mod exports eval/3, after calling power_shell_default:inject(Mod) resulting WhereTo contains following code:
-export([eval/3]). eval(Arg1, Arg2, Arg3) -> Mod:eval(Arg1, Arg2, Arg3).If there is no WhereTo module loaded, proxy just creates one from scratch.
Generated by EDoc