🔍 Find a dependency's modules and functions
Notes
At some point, you may want to find out a dependency’s modules or functions. Thankfully, Elixir has good introspection so we can do that at runtime!
Suppose we want to learn more about this obscure dependency called LiveView. 😏
We can first get the list of all modules for one of our dependencies using
Erlang’s :application.get_key/2
.
iex> :application.get_key(:phoenix_live_view, :modules)
# => {:ok, list_of_modules}
We see that Phoenix.LiveView.JS
is one of those modules.
Now, say we want to find out Phoenix.LiveView.JS
’s functions. We can use
Module.__info__/1
:
iex> Phoenix.LiveView.JS.__info__(:functions)`
# => all the functions
Voilà!
Keep that in your back pocket for when you need it. 😉