2222% % Export explicit API but also send compile directive to export all
2323% % because some of these private functions are useful in their own
2424% % right.
25- -export ([add /3 , add /4 ]).
25+ -export ([add /3 , add /4 , clean / 1 ]).
2626-compile (export_all ).
2727
2828-type abstract_code () :: term ().
5454% % functions.
5555% %
5656% % E.g. `[{{update_perform,2}, sleep_update_perform}]'
57- -spec add (module (), module (), mapping ()) -> ok .
57+ -spec add (module (), module (), mapping (), string () ) -> ok .
5858add (Target , Intercept , Mapping , OutDir ) ->
5959 Original = ? ORIGINAL (Target ),
6060 TargetAC = get_abstract_code (Target ),
@@ -66,9 +66,22 @@ add(Target, Intercept, Mapping, OutDir) ->
6666 ok = compile_and_load (Original , OrigAC , OutDir ),
6767 ok = compile_and_load (Target , ProxyAC , OutDir ).
6868
69+ -spec add (module (), module (), mapping ()) -> ok .
6970add (Target , Intercept , Mapping ) ->
7071 add (Target , Intercept , Mapping , undefined ).
7172
73+ % % @doc Cleanup proxy and backuped original module
74+ -spec clean (module ()) -> ok |{error , term ()}.
75+ clean (Target ) ->
76+ _ = code :purge (Target ),
77+ _ = code :purge (? ORIGINAL (Target )),
78+ case code :load_file (Target ) of
79+ {module , Target } ->
80+ ok ;
81+ {error , Reason } ->
82+ {error , Reason }
83+ end .
84+
7285% % @private
7386% %
7487% % @doc Compile the abstract code `AC' and load it into the code server.
0 commit comments