Why use closures instead of passing module name as an argument? IMHO that would be much clearer and much faster than the closures approach.
This is basically how Mox works under the hood.
It seems like your goals here are more exploratory than practical. Please correct me if I’m wrong.
On the practical side: in the last year or two, I’d been searching for a more practical way to allow occasional dependency injection for testing purposes. I didn’t like using Mock or Mox much at all. Then a teammate introduced me to Mimic, and mocking no longer bothers me at all. Great tool. https://github.com/edgurgel/mimic
Oh, mimic creates an alias to the module with an overloaded name. that kinda gives me the heebie jeebies, can’t quite put my finger on why though.