Accessing Plug Router init options in macros (get, post, etc.)

When I pry into macro (get, post, match, etc.) I see conn and opts, which is always an empty list for me. In def call(conn, state) I see all options, given in child_spec, but I this case macros are not called.

Is it possible to somehow access Plug.Router state/init options in macros?

What kind of state do you need?

I may be counter-intuitive that options fed into the call callback function, which is executed at run time, come from init/1 which is executed at compile time.

As you can read here: Metaprogramming · Elixir School macros “special functions designed to return a quoted expression that will be inserted into our application code” , that’s why so hard to debug it with pry. I would recommend in this scenario a more conservative approach with IO.inspect or something like that.

When you pry into a macro you get AST, not values. If you confuse these you won’t make any progress with macros. Macros are not passed values, they are passed “code structures” that describe the shape of the code in the macro value.

1 Like