Getting a list of all Elixir modules

1,127 views
Skip to first unread message

Dave Thomas

unread,
Mar 14, 2014, 1:20:58 AM3/14/14
to elixir-l...@googlegroups.com

I’m trying to create a table showing the relationship between various Elixir modules. As a starting place, I wanted to create a list of all these modules.

I tried

modules = for {name,_} <- :code.all_loaded, 
              Regex.match?(~r/^[A-Z]/, atom_to_binary(name)), 
          do: name

but (no surprise) it only lists modules that have been loaded.

Is there a decent programatic way of doing this?

Dave

Saša Jurić

unread,
Mar 14, 2014, 4:15:56 AM3/14/14
to elixir-l...@googlegroups.com, da...@pragprog.com
Maybe go through all load paths (:code.get_path), and find all beam files in there?
This will get you Erlang modules as well, so you probably want to do some filtering.

Eric Meadows-Jönsson

unread,
Mar 14, 2014, 6:14:01 AM3/14/14
to elixir-l...@googlegroups.com

Hi Dave,

:erl_prim_loader can be used to load all modules. Take a look at how Mix loads all modules to find all mix tasks:

https://github.com/elixir-lang/elixir/blob/0bacbaeff7d75c2725cd3ce5e7f780e13e1c7f21/lib/mix/lib/mix/task.ex#L52



--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Eric Meadows-Jönsson
Reply all
Reply to author
Forward
0 new messages