Index: includes/registry.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/registry.inc,v
retrieving revision 1.14
diff -u -r1.14 registry.inc
--- includes/registry.inc	7 May 2009 18:04:16 -0000	1.14
+++ includes/registry.inc	7 May 2009 20:50:10 -0000
@@ -45,11 +45,19 @@
   system_get_files_database($modules, 'module');
   // Get the list of files we are going to parse.
   $files = array();
-  foreach ($modules as $module) {
+  $module_cache = module_rebuild_cache();
+  foreach ($module_cache as $module) {
+    $dir = dirname($module->filepath);
+
+    // Store the module directory for use in hook_registry_files_alter().
+    $module_cache[$module->name]->dir = $dir;
+
+    // Parse .info file only for all modules. The list of files can then be
+    // used in hook_registry_files_alter() implementations.
+    $module->info = drupal_parse_info_file(dirname($module->filepath) . '/' . $module->name . '.info');
+
     if ($module->status) {
-      // Parse .info file only for enabled modules.
-      $module->info = drupal_parse_info_file(dirname($module->filepath) . '/' . $module->name . '.info');
-      $dir = dirname($module->filepath);
+      // Add enabled modules files to registry.
       foreach ($module->info['files'] as $file) {
         $files["$dir/$file"] = array('module' => $module->name, 'weight' => $module->weight);
       }
@@ -59,6 +67,13 @@
     $files["$filename"] = array('module' => '', 'weight' => 0);
   }
 
+  // Allow modules to manually modify the list of files before the registry
+  // parses them. The $module_cache provides the .info file information, which
+  // includes the list of files registered to the module. Any files in the list
+  // can then be added to the list of files that the registry will parse, or
+  // modify attributes of a file.
+  drupal_alter('registry_files', $files, $module_cache);
+
   foreach (registry_get_parsed_files() as $filename => $file) {
     // Add the md5 to those files we've already parsed.
     if (isset($files[$filename])) {
Index: modules/system/system.api.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.api.php,v
retrieving revision 1.32
diff -u -r1.32 system.api.php
--- modules/system/system.api.php	6 May 2009 11:30:19 -0000	1.32
+++ modules/system/system.api.php	7 May 2009 20:50:11 -0000
@@ -1694,5 +1694,51 @@
 }
 
 /**
+ * Perform necessary alterations to the list of files parsed by the registry.
+ *
+ * Modules can manually modify the list of files before the registry parses
+ * them. The $module_cache provides the .info file information, which includes
+ * the list of files registered to the module. Any files in the list can then
+ * be added to the list of files that the registry will parse, or modify
+ * attributes of a file.
+ *
+ * Implementing hooks on behalf of another module can be done by implementing
+ * the hook in a file and changing the module related to the file before the
+ * registry parses the file. In the example bellow, hook_token() is implemented
+ * by the token module on behalf of the node module. The associated module for
+ * the file containing node_token() is changed to the node module, even though
+ * the file is located withing the token module's directory.
+ *
+ * File prvoded by disabled modules can also be forced into the list of files
+ * the registry parses.
+ *
+ * @param $files
+ *   List of files to be parsed by the registry. The list will contain a file
+ *   found in each enabled module's info file and the includes directory. The
+ *   array is keyed by the file path and contains an array of the related module
+ *   name and weight.
+ *
+ *   For example:
+ *   @code
+ *     $files["modules/system/system.module"] = array(
+ *       'module' => 'system',
+ *       'weight' => 0,
+ *     );
+ *   @endcode
+ * @param $module_cache
+ *   List of all the files provided by modules in the system, as returned by
+ *   module_rebuild_cache(). The module object contains an property, 'dir',
+ *   added by _registry_rebuild(). The example shows how to take advantage of
+ *   the property.
+ *
+ * @see _registry_rebuild()
+ * @see module_rebuild_cache().
+ */
+function hook_registry_files_alter($files, $module_cache) {
+  $dir = $module_cache['token']->dir;
+  $files["$dir/token.node.inc"]['module'] = 'node';
+}
+
+/**
  * @} End of "addtogroup hooks".
  */
