Here is a commented example of a custom service module that uses hook_service() to become a service.
Drupal 6
Under drupal 6.x, one needs to implement hook_disable() and hook_enable() like this:
<?php
/*
* Implementation of hook_disable()
* Perform necessary actions before module is disabled. (like clear the services:methods cache)
*/
function yourModuleName_disable() {
cache_clear_all('services:methods', 'cache');
}
/*
* Implementation of hook_enable()
* Perform necessary actions after module is enabled. (like clear the services:methods cache)
*/
function yourModuleName_enable() {
cache_clear_all('services:methods', 'cache');
}
?>
otherwise any changes during development are unrecognised because they get cached.
Drupal 5 + 6
<?php
/*
* Implementation of hook_service()
* Required by all server modules
* Returns array defining all the methods available in the service
*/
function recipe_service_service() {
return array(
/**
* recipe.all
* We define methods in hashed arrays
*/
array(
/**
* #method - defines the namespace and method name
* the namespace is everything before the last period, so you can do
* methods like 'recipe.lunch.all' where 'recipe.lunch' is the namespace,
* or service, and 'all' is the method