|
|
@@ -68,7 +68,7 @@
|
|
|
format/1,
|
|
|
format/2,
|
|
|
format_mfal/2,
|
|
|
- call_first_defined/1,
|
|
|
+ call_first_defined/3,
|
|
|
ntoa/1,
|
|
|
foldl_while/3,
|
|
|
is_restricted_str/1
|
|
|
@@ -599,21 +599,18 @@ format_mfal(Data, #{with_mfa := true}) ->
|
|
|
format_mfal(_, _) ->
|
|
|
undefined.
|
|
|
|
|
|
--spec call_first_defined(list({module(), atom(), list()})) -> term() | no_return().
|
|
|
-call_first_defined([{Module, Function, Args} | Rest]) ->
|
|
|
- try
|
|
|
- apply(Module, Function, Args)
|
|
|
- catch
|
|
|
- error:undef:Stacktrace ->
|
|
|
- case Stacktrace of
|
|
|
- [{Module, Function, _, _} | _] ->
|
|
|
- call_first_defined(Rest);
|
|
|
- _ ->
|
|
|
- erlang:raise(error, undef, Stacktrace)
|
|
|
- end
|
|
|
- end;
|
|
|
-call_first_defined([]) ->
|
|
|
- error(none_fun_is_defined).
|
|
|
+-spec call_first_defined(module(), atom(), list()) -> term() | no_return().
|
|
|
+call_first_defined(Module, Function, []) ->
|
|
|
+ error({not_exported, Module, Function});
|
|
|
+call_first_defined(Module, Function, [Args | Rest]) ->
|
|
|
+ %% ensure module is loaded
|
|
|
+ _ = apply(Module, module_info, []),
|
|
|
+ case erlang:function_exported(Module, Function, length(Args)) of
|
|
|
+ true ->
|
|
|
+ apply(Module, Function, Args);
|
|
|
+ false ->
|
|
|
+ call_first_defined(Module, Function, Rest)
|
|
|
+ end.
|
|
|
|
|
|
%%------------------------------------------------------------------------------
|
|
|
%% Internal Functions
|