View Source smerl (util v1.1.5)
Link to this section Summary
Types
func_form()s.Functions
Equivalent to add_func(MetaMod, Form, true).
Function to MetaMod and return the new meta_mod(). If Export is true, add Function to MetaMod's exports.Equivalent to compile(MetaMod, []).
Form with Args. Here, "currying" involves replacing one or more of the function's leading arguments with predefined values.Module:Function/Arity with the given Args.Module:Function/Aritywith the given Args, renaming it to NewName and return the renamed form.Form curried with Args to MetaMod.Function/Arity curried with Args to MetaMod.MetaMod:Function/Arity and add it to MetaMod as NewName.Module:Function/Arity and add it to MetaMod as NewName.Form in MetaMod with its curried form.Function/Arity in MetaMod with its curried form.embed_args/2 with Values to all forms in MetaMod. exports for functions whose arities change are preserved.Form, where the argument's Name matches an element from Vals with the corresponding Value.Equivalent to embed_args(MetaMod, Name, Arity, Values, Name).
embed_args/2 to MetaMod:Function/Arity and add the resulting function to MetMod, after renaming it to NewName.See also: rename/2.
Parent's functions missing from Child to Child. The new functions in Child are shallow, i.e. they have the name and arity of the corresponding functions in Parent, but instead of implementing their logic they call the Parent functions.extend/2, with the addition of ArityDiff, which indicates the difference in arities Smerl should use when figuring out which functions to generate based on the modules' exports. This is sometimes useful when calling extend/3 followed by embed_all/2.Equivalent to for_file(SrcFilePath, []).
Equivalent to for_module(ModuleName, []).
Create a meta_mod tuple for an existing module. If ModuleName is a string, it is interpreted as a file name (this is the same as calling for_file/3). If ModuleName is an atom, Smerl attempts to find its abstract represtation either from its source file or from its .beam file directly (if it has been compiled with debug_info). If the abstract representation can't be found, this function returns an error.
MetaMod's Key attribute.export_all value for MetaMod.MetaMod has a function Function/Arity.{Function, Arity} from the list of exports in MetaMod.Function from MetaMod. If the function exists, return the new meta_mod(). Otherwise, return MetaMod.Form to NewName.Function to MetaMod. This is tantamount to calling remove_func/3 followed by add_func/2.export_all value for MetaMod.MetaMod's export list to Exports.MetaMod.Link to this section Types
-type args() :: term() | [term()].
-type error_t(Error) :: ok | {error, Error}.
-type export() :: {Function :: atom(), Arity :: arity()}.
-type exports() :: [export()].
export()s.
-type func_form() :: erl_parse:abstract_form().
-type func_forms() :: [func_form()].
func_form()s.
-type meta_mod() :: #meta_mod{}.
-type ok_t(Value) :: {ok, Value} | error.
-type result(Value) :: result(Value, term()).
-type result(Value, Error) :: {ok, Value} | {error, Error}.
Link to this section Functions
-spec add_func(MetaMod, Form) -> result(meta_mod(), parse_error) when MetaMod :: meta_mod(), Form :: func_form() | string().
Equivalent to add_func(MetaMod, Form, true).
Add a new exported function toMetaMod.
-spec add_func(MetaMod, Func, Export) -> result(meta_mod(), parse_error) when MetaMod :: meta_mod(), Func :: func_form() | string(), Export :: boolean().
Function to MetaMod and return the new meta_mod(). If Export is true, add Function to MetaMod's exports.
Equivalent to compile(MetaMod, []).
CompileMetaMod and load the resulting BEAM into the emulator.
-spec compile(MetaMod, Options) -> error_t(term()) when MetaMod :: meta_mod(), Options :: [proplists:property()].
Equivalent to compile(MetaMod, [report_errprs, report_warnings, return_errors]).
CompileMetaMod and load the resulting BEAM into the emulator. Options is a list of options as described in the compile module in the Erlang documentation. If an outdir is provided, write the .beam file to it.
Form with Args. Here, "currying" involves replacing one or more of the function's leading arguments with predefined values.
-spec curry(Module, Function, Arity, Args) -> result(func_form()) when Module :: module() | meta_mod(), Function :: atom(), Arity :: arity(), Args :: args().
Module:Function/Arity with the given Args.
-spec curry(Module, Function, Arity, Args, NewName) -> result(func_form()) when Module :: module() | meta_mod(), Function :: atom(), Arity :: arity(), Args :: args(), NewName :: atom().
Module:Function/Aritywith the given Args, renaming it to NewName and return the renamed form.
-spec curry_add(MetaMod, Form, Args) -> result(meta_mod()) when MetaMod :: meta_mod(), Form :: func_form(), Args :: args().
Form curried with Args to MetaMod.
-spec curry_add(MetaMod, Function, Arity, Args) -> result(meta_mod()) when MetaMod :: meta_mod(), Function :: atom(), Arity :: arity(), Args :: args().
Function/Arity curried with Args to MetaMod.
-spec curry_add(MetaMod, Function, Arity, Args, NewName) -> Result when MetaMod :: meta_mod(), Function :: atom(), Arity :: arity(), Args :: args(), NewName :: atom(), Result :: result(meta_mod(), parse_error).
MetaMod:Function/Arity and add it to MetaMod as NewName.
-spec curry_add(MetaMod, Module, Function, Arity, Args, NewName) -> Result when MetaMod :: meta_mod(), Module :: module() | meta_mod(), Function :: atom(), Arity :: arity(), Args :: args(), NewName :: atom(), Result :: result(meta_mod()).
Module:Function/Arity and add it to MetaMod as NewName.
-spec curry_replace(MetaMod, Form, Args) -> result(meta_mod()) when MetaMod :: meta_mod(), Form :: func_form(), Args :: args().
Form in MetaMod with its curried form.
-spec curry_replace(MetaMod, Function, Arity, Args) -> result(meta_mod()) when MetaMod :: meta_mod(), Function :: atom(), Arity :: arity(), Args :: args().
Function/Arity in MetaMod with its curried form.
-spec embed_all(MetaMod, Values) -> NewMod when MetaMod :: meta_mod(), Values :: [{Name :: atom(), Value :: term()}], NewMod :: meta_mod().
embed_args/2 with Values to all forms in MetaMod. exports for functions whose arities change are preserved.
-spec embed_args(Form, Vals) -> NewForm when Form :: func_form(), Vals :: [{Name :: atom(), Value :: term()}], NewForm :: func_form().
Form, where the argument's Name matches an element from Vals with the corresponding Value.
-spec embed_args(MetaMod, Function, Arity, Values) -> result(meta_mod()) when MetaMod :: meta_mod(), Function :: atom(), Arity :: arity(), Values :: proplists:proplist().
Equivalent to embed_args(MetaMod, Name, Arity, Values, Name).
-spec embed_args(MetaMod, Function, Arity, Values, NewName) -> Result when MetaMod :: meta_mod(), Function :: atom(), Arity :: arity(), Values :: proplists:proplist(), NewName :: atom(), Result :: result(meta_mod()).
embed_args/2 to MetaMod:Function/Arity and add the resulting function to MetMod, after renaming it to NewName.See also: rename/2.
-spec extend(Parent, Child) -> NewChildMod when Parent :: module() | meta_mod(), Child :: module() | meta_mod(), NewChildMod :: meta_mod().
Parent's functions missing from Child to Child. The new functions in Child are shallow, i.e. they have the name and arity of the corresponding functions in Parent, but instead of implementing their logic they call the Parent functions.
-spec extend(Parent, Child, ArityDiff) -> NewChildMod when Parent :: module() | meta_mod(), Child :: module() | meta_mod(), ArityDiff :: non_neg_integer(), NewChildMod :: meta_mod().
extend/2, with the addition of ArityDiff, which indicates the difference in arities Smerl should use when figuring out which functions to generate based on the modules' exports. This is sometimes useful when calling extend/3 followed by embed_all/2.
-spec extend(Parent, Child, ArityDiff, Options) -> NewChildMod when Parent :: module() | meta_mod(), Child :: module() | meta_mod(), ArityDiff :: non_neg_integer(), Options :: [proplists:property()], NewChildMod :: meta_mod().
Equivalent to for_file(SrcFilePath, []).
Equivalent to for_file(SrcFilePath, IncludePaths, []).
-spec for_file(SrcFilePath, IncludePaths, Macros) -> Result when SrcFilePath :: file:filename(), IncludePaths :: [file:filename()], Macros :: [{module(), atom()}], Result :: result(meta_mod(), invalid_module).
Equivalent to for_module(ModuleName, []).
Equivalent to for_module(ModuleName, IncludePaths, []).
-spec for_module(ModuleName, IncludePaths, Macros) -> result(meta_mod) when ModuleName :: atom() | string(), IncludePaths :: [string()], Macros :: [{atom(), term()}].
Create a meta_mod tuple for an existing module. If ModuleName is a string, it is interpreted as a file name (this is the same as calling for_file/3). If ModuleName is an atom, Smerl attempts to find its abstract represtation either from its source file or from its .beam file directly (if it has been compiled with debug_info). If the abstract representation can't be found, this function returns an error.
IncludePaths argument is used when ModuleName is a file name.
MetaMod's Key attribute.
-spec get_export_all(MetaMod :: meta_mod()) -> boolean().
export_all value for MetaMod.
-spec get_forms(MetaMod :: meta_mod()) -> func_forms().
-spec get_func(MetaMod, Function, Arity) -> result(func_form()) when MetaMod :: meta_mod() | module(), Function :: atom(), Arity :: arity().
func_form() for MetaMod:Function/Arity.
-spec get_module(MetaMod :: meta_mod()) -> module().
-spec has_func(MetaMod, Function, Arity) -> boolean() when MetaMod :: meta_mod(), Function :: atom(), Arity :: arity().
MetaMod has a function Function/Arity.
-spec new(Module :: module()) -> meta_mod().
-spec remove_export(MetaMod, Function, Arity) -> NewMod when MetaMod :: meta_mod(), Function :: atom(), Arity :: arity(), NewMod :: meta_mod().
{Function, Arity} from the list of exports in MetaMod.
-spec remove_func(MetaMod, Function, Arity) -> NewMod when MetaMod :: meta_mod(), Function :: atom(), Arity :: arity(), NewMod :: meta_mod().
Function from MetaMod. If the function exists, return the new meta_mod(). Otherwise, return MetaMod.
Form to NewName.
-spec replace_func(MetaMod, Function) -> result(meta_mod()) when MetaMod :: meta_mod(), Function :: string() | func_form().
Function to MetaMod. This is tantamount to calling remove_func/3 followed by add_func/2.
-spec set_export_all(MetaMod, Value) -> NewMod when MetaMod :: meta_mod(), Value :: boolean(), NewMod :: meta_mod().
export_all value for MetaMod.
-spec set_exports(MetaMod, Exports) -> NewMod when MetaMod :: meta_mod(), Exports :: exports(), NewMod :: meta_mod().
MetaMod's export list to Exports.
-spec set_forms(MetaMod, Forms) -> NewMod when MetaMod :: meta_mod(), Forms :: func_forms(), NewMod :: meta_mod().
-spec to_src(MetaMod :: meta_mod()) -> Source :: string().
MetaMod.
-spec to_src(MetaMod, Filename) -> error_t(term()) when MetaMod :: meta_mod(), Filename :: file:filename().
Equivalent to file:write_file(Filename, to_src(MetaMod)).