Improve module name resolution

In path_to_module() check that all intermediate directories between
specified module and source root are proper packages.