Interpolate a function in an Expr (macro) in called module scope

Here is some (heavily simplified) code:

module M
function foobar end
macro define_foobar_method()
  :($foobar() = 1)
end
end # module M

Note that the function foobar is not exported by the module M; I would like the macro to expand to a definition of a new method for that function (hence requiring the use of the fully-qualified function name in the method definition). However, the above code fails with

syntax: invalid function name "M.define_foobar_method"

By inspecting the returned expression with @macroexpand I find that indeed the function definition expression contains

1: Expr
  head: symbol call
  args: Array{Any}((1,))
    1: define_foobar_method (function of type typeof(M.define_foobar_method))

In other words, the correct function is interpolated into the Expr, but then “re-parsing” the function name when evaluating the Expr fails. (I would qualify this as a bug: the Function member in the Expr is well defined; thus there exists one and only one reasonable way of evaluating such an Expr, which is using whichever name refers to that function in the current evaluation scope.)

Something that seems to work however is to interpolate the module itself:

:($(@__MODULE__).foobar() = 1) # @__MODULE__ evaluated as `M` here

Is this a correct solution? Does there exist a simpler one? In particular, the “real case” for such an expression would be parametrized by the function itself, and needing to separate the module from the function name means that the code now needs to determine which module the function belongs to (whereas the failed attempt above had the advantage of making this transparent).

You don’t need to interpolate the function nor use @__MODULE__:

julia> module M
           function foobar end

           macro define_foobar_method()
               :(foobar() = 1)
           end
       end
Main.M

julia> M.foobar()
ERROR: MethodError: no method matching foobar()
Stacktrace:
 [1] top-level scope
   @ REPL[2]:1

julia> M.@define_foobar_method
foobar (generic function with 1 method)

julia> M.foobar()
1