This is a followup to another question I asked abou creating your own hooks.
In the answer and comments, two functions were mentioned
module_invoke_all(...)
drupal_alter(...)
The function module_invoke_all
appears to be used to invoke a hook for any module that implements it.
The function drupal_alter
appears to invoke a hook for any module that implements it and passes around a persistant data structure between all the hook functions.
Digging through the code, I also found
module_invoke(...)
which appears to let you invoke a specific hook in a specific module.
So, my question is really two questions. First, is my understanding of the above items correct. Second, are there any other core Drupal functions that can be used to invoke hooks implemented in a module?
My end goal is a better understanding of how the pieces of Drupal's architecture come together to form Drupal, the application, as most people use it. I'm starting with trying to understand the module system in isolation. Any corrections to glaring misconceptions are appreciated
First question: Yes.
Second question: Apart from using these functions, you can also call module_implements() directly and call them manually. Example use case is when you want to pass arguments by reference but don't want an hook_something_alter() naming scheme that drupal_alter() forces you into.
module_implements() returns an array of modules that implemented the given hook. In Drupal 6 this is simply a loop over all modules and then checking if the function $module . '_' . $hook exists.
In Drupal 7, it is for example possible to define that your hook_yourmodule_something can be in a anothermodule.yourmodule.inc and Drupal will then automatically look for that file and include it when necessary. See hook_hook_info. Additionally, it is also possible to alter the list of modules that implement a hook, which is rather crazy and should be used with care. See hook_module_implements_alter.
Because these features make the discovery quite a bit slower than in D6, a cache was added to that. This basically means that whenever you add a hook implementation in D7, you need to clear the cache.
Example manual implementation:
If you look at the code of the functions you linked in your question, you can see that they are basically just helper function for the same procedure, so this should also help to improve the general understanding of hook calling.