This may not be correct -- since module names are typically namespaces, and submodules are possible, the first namespace segment may not be right. As an example, if I had a submodule named "Phly\RestTools", with the class "Phly\RestTools\Module", the actual module name the above line would detect is "Phly", which is incorrect.

I'm thinking you may need to do key/value pairs of module name => module instance to make this work.