From 4ad4a3bf246e1ed045f7f55c29ce388ca149c334 Mon Sep 17 00:00:00 2001 From: Badlop Date: Tue, 20 Dec 2022 16:13:27 +0100 Subject: [PATCH] Support to get module status from Elixir modules --- src/ext_mod.erl | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/src/ext_mod.erl b/src/ext_mod.erl index eeb310207..1d8cb685e 100644 --- a/src/ext_mod.erl +++ b/src/ext_mod.erl @@ -936,12 +936,7 @@ get_installed_module_el({ModAtom, Attrs}, Lang) -> [] end, TitleEl = make_title_el(CommitDate, CommitMessage, CommitAuthorName), - Status = case lists:member({mod_status, 0}, ModAtom:module_info(exports)) of - true -> - [?C(<<" ">>), - ?C(ModAtom:mod_status())]; - false -> [] - end, + Status = get_module_status_el(ModAtom), HomeTitleEl = make_home_title_el(Summary, Author), ?XE(<<"tr">>, [?XE(<<"td">>, [?AXC(Home, [HomeTitleEl], Mod)]), @@ -954,6 +949,46 @@ get_installed_module_el({ModAtom, Attrs}, Lang) -> ++ Status) | UpgradeEls]). +get_module_status_el(ModAtom) -> + case {get_module_status(ModAtom), + get_module_status(elixir_module_name(ModAtom))} of + {Str, unknown} when is_list(Str) -> + [?C(<<" ">>), ?C(Str)]; + {unknown, Str} when is_list(Str) -> + [?C(<<" ">>), ?C(Str)]; + {unknown, unknown} -> + [] + end. + +get_module_status(Module) -> + try Module:mod_status() of + Str when is_list(Str) -> + Str + catch + _:_ -> + unknown + end. + +%% Converts mod_some_thing to Elixir.ModSomeThing +elixir_module_name(ModAtom) -> + list_to_atom("Elixir." ++ elixir_module_name("_" ++ atom_to_list(ModAtom), [])). + +elixir_module_name([], Res) -> + lists:reverse(Res); +elixir_module_name([$_, Char | Remaining], Res) -> + [Upper] = uppercase([Char]), + elixir_module_name(Remaining, [Upper | Res]); +elixir_module_name([Char | Remaining], Res) -> + elixir_module_name(Remaining, [Char | Res]). + +-ifdef(HAVE_URI_STRING). +uppercase(String) -> + string:uppercase(String). % OTP 20 or higher +-else. +uppercase(String) -> + string:to_upper(String). % OTP older than 20 +-endif. + get_available_module_el({ModAtom, Attrs}) -> Installed = installed(), Mod = misc:atom_to_binary(ModAtom),