--- patterns.install	2009-03-03 13:35:12.000000000 -0500
+++ patterns_patched.install	2009-05-12 14:09:33.612087400 -0400
@@ -37,3 +37,60 @@ function patterns_schema() {
 function patterns_uninstall() {
   drupal_uninstall_schema('patterns');
 }
+
+/**
+ * Implementation of hook_requirements().
+ *
+ * @param string $phase The phase in which hook_requirements is run (install|runtime)
+ */
+function patterns_requirements($phase) {
+  $requirements = array();
+  // Ensure translations don't break at install time
+  $t = get_t();
+
+  switch ($phase) {
+    case 'install':
+    case 'runtime':
+      $path = drupal_get_path('module', 'patterns') .'/spyc/spyc.php';
+      if (!file_exists($path)) {
+        $requirements['patterns'] = array(
+          'title'       => $t('Patterns - SPYC library'),
+          'description' => $t('Obtain the !spyc package and copy spyc.php to the spyc directory inside module directory.',
+                              array('!spyc' => l('SPYC', 'http://code.google.com/p/spyc/', array('absolute' => TRUE)))),
+          'severity'    => $phase == 'install' ? REQUIREMENT_WARNING : REQUIREMENT_ERROR,
+          'value'       => $t('spyc.php file missing'),
+        );
+      }
+      elseif ($phase == 'runtime') {
+        require_once($path);
+        $requirements['patterns'] = array(
+          'title'       => $t('Patterns - SPYC library'),
+          'severity'    => REQUIREMENT_OK,
+          'value'       => _get_file_phpdoc_version($path),
+        );
+      }
+      break;
+  }
+  return $requirements;
+}
+
+/**
+ * Helper function to get PHPDoc @version tag from a file
+ */
+function _get_file_phpdoc_version($path) {
+  $version = 'unknown';
+  $needle  = '@version ';
+
+  if (file_exists($path)) {
+    $fp = @fopen($path, 'r');
+    if ($fp) {
+      while (!feof($fp)) {
+        $occurence = stristr(fgets($fp), $needle);
+        if ($occurence) { // false if stristr found nothing
+          return rtrim(substr($occurence, strlen($needle)));
+        }
+      }
+    }
+  }
+  return $version;
+}
