#332733: implement drupal_require() that allows to lazy load functions *and* make sure they exists.

From: Damien Tournoud <damien@tournoud.net>


---
 bootstrap.inc |   17 +++++++++++++++++
 form.inc      |    2 +-
 module.inc    |   11 +++++------
 3 files changed, 23 insertions(+), 7 deletions(-)

diff --git includes/bootstrap.inc includes/bootstrap.inc
index c73cf42..ae713e7 100644
--- includes/bootstrap.inc
+++ includes/bootstrap.inc
@@ -1694,6 +1694,23 @@ function drupal_function_exists($function) {
 }
 
 /**
+ * Require that some functions exists.
+ *
+ * That function lazy-load the specified functions and throw an exception if 
+ * one of them is not available.
+ *
+ * @param $functions
+ *   An array of functions.
+ */
+function drupal_require(Array $functions) {
+  foreach ($functions as $function) {
+    if (!drupal_function_exists($function)) {
+      throw new Exception("Required function '" . $function . "' is not available");
+    }
+  }
+}
+
+/**
  * Confirm that an interface is available.
  *
  * This function parallels drupal_function_exists(), but is rarely
diff --git includes/form.inc includes/form.inc
index 0e235ea..4624005 100644
--- includes/form.inc
+++ includes/form.inc
@@ -438,7 +438,7 @@ function drupal_retrieve_form($form_id, &$form_state) {
     }
     if (isset($form_definition['callback'])) {
       $callback = $form_definition['callback'];
-      drupal_function_exists($callback);
+      drupal_require(array($callback));
     }
   }
 
diff --git includes/module.inc includes/module.inc
index d3e3059..df4a4a4 100644
--- includes/module.inc
+++ includes/module.inc
@@ -211,16 +211,15 @@ function module_load_install($module) {
  *   Optionally, specify the file name. If not set, the module's name is used.
  */
 function module_load_include($type, $module, $name = NULL) {
+  drupal_require(array('drupal_get_path'));
   if (empty($name)) {
     $name = $module;
   }
 
-  if (drupal_function_exists('drupal_get_path')) {
-    $file = DRUPAL_ROOT . '/' . drupal_get_path('module', $module) . "/$name.$type";
-    if (is_file($file)) {
-      require_once $file;
-      return $file;
-    }
+  $file = DRUPAL_ROOT . '/' . drupal_get_path('module', $module) . "/$name.$type";
+  if (is_file($file)) {
+    require_once $file;
+    return $file;
   }
   return FALSE;
 }
