Move all module.* methods into a separate constructor function

This makes the code more portable and easier to test. Key changes are:

* Creation of the `ModuleRegistry` constructor, this handles dom events and creation and registration of modules.
* Moving broadcast and inheritance methods onto a `utils` object.
* `m.module()` still exists but is now just a wrapper around `ModuleRegistry`.