This is an automated email from the ASF dual-hosted git repository. willholley pushed a commit to branch upstream-2.20.0 in repository https://gitbox.apache.org/repos/asf/couchdb-mochiweb.git
commit 83fdebc7b0cbfdbafbfac1a246dacac26276c5b0 Author: Bob Ippolito <[email protected]> AuthorDate: Sat Mar 9 20:28:47 2019 +0000 Remove compile(tuple_calls) from mochifmt --- src/mochifmt.erl | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/mochifmt.erl b/src/mochifmt.erl index 5a5ed45..1aa01c3 100644 --- a/src/mochifmt.erl +++ b/src/mochifmt.erl @@ -25,8 +25,6 @@ -module(mochifmt). -author('[email protected]'). --compile(tuple_calls). - -export([format/2, format_field/2, convert_field/2, get_value/2, get_field/2]). -export([tokenize/1, format/3, get_field/3, format_field/3]). -export([bformat/2, bformat/3]). @@ -76,8 +74,7 @@ get_field(Key, Args) -> %% is used to implement formats such as {0.0}. get_field(Key, Args, Module) -> {Name, Next} = lists:splitwith(fun (C) -> C =/= $. end, Key), - Res = try Module:get_value(Name, Args) - catch error:undef -> get_value(Name, Args) end, + Res = mod_get_value(Name, Args, Module), case Next of "" -> Res; @@ -85,6 +82,16 @@ get_field(Key, Args, Module) -> get_field(S1, Res, Module) end. +mod_get_value(Name, Args, Module) -> + try tuple_apply(Module, get_value, [Name, Args]) + catch error:undef -> get_value(Name, Args) + end. + +tuple_apply(Module, F, Args) when is_atom(Module) -> + erlang:apply(Module, F, Args); +tuple_apply(Module, F, Args) when is_tuple(Module), is_atom(element(1, Module)) -> + erlang:apply(element(1, Module), F, Args ++ [Module]). + %% @spec format(Format::string(), Args) -> iolist() %% @doc Format Args with Format. format(Format, Args) -> @@ -204,11 +211,11 @@ format2([{format, {Key, Convert, Format0}} | Rest], Args, Module, Acc) -> V1 = convert_field(V0, Convert), format_field(V1, Format); _ -> - V0 = try Module:get_field(Key, Args) + V0 = try tuple_apply(Module, get_field, [Key, Args]) catch error:undef -> get_field(Key, Args, Module) end, - V1 = try Module:convert_field(V0, Convert) + V1 = try tuple_apply(Module, convert_field, [V0, Convert]) catch error:undef -> convert_field(V0, Convert) end, - try Module:format_field(V1, Format) + try tuple_apply(Module, format_field, [V1, Format]) catch error:undef -> format_field(V1, Format, Module) end end, format2(Rest, Args, Module, [V | Acc]). @@ -436,9 +443,9 @@ std_test() -> records_test() -> M = mochifmt_records:new([{conversion, record_info(fields, conversion)}]), R = #conversion{length=long, precision=hard, sign=peace}, - long = M:get_value("length", R), - hard = M:get_value("precision", R), - peace = M:get_value("sign", R), + long = mochifmt_records:get_value("length", R, M), + hard = mochifmt_records:get_value("precision", R, M), + peace = mochifmt_records:get_value("sign", R, M), <<"long hard">> = bformat("{length} {precision}", R, M), <<"long hard">> = bformat("{0.length} {0.precision}", [R], M), ok.
