I have been having some trouble figuring out the proper way in 4.7 to break my huge module up into submodules. I have a module that defines multiple node types, so I pulled each node type out into a seperate .inc file. Back in the 4.6 days, I just included them directly into the main module
<?php
$module_path = drupal_get_path('module', 'main');
if (file_exists("$module_path/main.module")) {
require_once "$module_path/sub1.inc";
}
?>In 4.7 this breaks when the site is cached, because drupal_get_path is not defined by the abbreviated bootstrap that loads the cached pages. I also came across a drupal guideline that say not to put any code directly into your module (everything should be inside a function). hook_init seemed like the obvious place, but it's doc page says no (http://api.drupal.org/api/4.7/function/hook_init). The instructions there are to put code that should not be run for cached pages into hook_menu, in the (!may_cache) block. Unfortunately, this does not work for my .inc files. They are getting includes, but not soon enough for the hook system to find it.
So I ended up using the solution I found in cck: use hook_init, but wrap my includes inside
<?php
if (function_exists('drupal_get_path')) {
?>Feels kinda kludgy, but it works.
Still main module
I do the same sort of split-up in nodereview, which has 4.7 and 5 versions. You can still use the "top level" of your module, as long as you remember that it's not the global namespace. Although you're probably better off with module_exists() (which was called module_exist() in 4.7).