__before_compile__ 的这个参数在 Phoenix.Endpoint 中设置在哪里?

Where does this argument to __before_compile__ get set in Phoenix.Endpoint?

以下源码来自https://github.com/phoenixframework/phoenix/blob/v1.5/lib/phoenix/endpoint.ex#L602

defmacro __before_compile__(%{module: module}) do

似乎正在将 map 参数传递给 before_compile 。但是 documentation for @before_compile 说“将在编译模块之前调用的挂钩。接受模块或 {module, function_or_macro_name} 元组。请参阅下面的“编译回调”部分。”。

  1. 传递给 __before_compile__ 的参数 %{module: module} 中确定的 module 的键值在哪里?
  2. 为什么将地图传递给 before_compile 与文档直接矛盾?

当您使用 @before_compile 作为编译挂钩时,它看起来像这样(来自文档):

defmodule B do
  @before_compile A
end

调用的是目标中的 __before_compile__ 宏, 接收一个参数,即一个映射,例如

defmodule A do
  defmacro __before_compile__(%{module: module}) do
     # Do pre-compile stuff
  end
end

您引用的源代码 defmacro __before_compile__(%{module: module}) do 正在使用模式匹配来提取调用它的 module(例如上面示例中的模块 B),因为它需要知道模块对其进行操作的名称。