Is there a way to make module in anon workspace & then ingest it into a package?

The idea is you create a module – Foo – in some anonymous workspace.

// i.e. in order to not have to overwrite the module if it fails

module _anon_uuid

    module Foo

       if rand() < 0.5
          bar() = "Hello, World."
       else
          error("Explode")
       end

    end

end

Is there a way to then inject this encapsulated module into some other Module?

in psuedocode:

module Fizz

  cur_module = parse(<string_representation_of_module>)

  cur_sub_module = nothing

  for cur_attempt in 1:10
    try
      cur_sub_module = @make_encapsulated_module cur_module
    catch
      include("hot_fix_$(cur_attempt).jl")
      continue
    end

    break
  end

  ( cur_sub_module == nothing ) && error("nothing worked!")

  @ingest_module cur_sub_module

end

There is a lot of code here that is not definend e.g. @make_encapsulated_module or @ingest_module, so I don’t fully understand your question or what you intend to do.

I presume that @ingest_module gives you the module _anon_uuid?

What about simply doing a import _anon_uuid: Foo?