What is it for?

This module allows you to write modules in pure OOP syntax. It becomes handy when you need some kind of "aspects" to inweave into the main functionality of your module. Moopapi does it by Decorator pattern. Currently we have these types of decorators implemented:
- Logger: allows to log every method calling together with all parameters passed. A mighty tool for development and debugging in some circumstances.
Used by: BOTCHA (spam protection without CAPTCHA) - its use case is that while developing Selenium-tests for its JavaScript there is no chance to use usual development tools such as XDebug, because Selenium-tests are intended to be launched via command-line interface. Moopapi logger helps BOTCHA to keep debugged.
- Cacher (planned, see #1870060: Create new decorator: Cacher): The idea is to separate a logic of an application and tricks to make it work faster. It could be done by Cacher "aspect" which includes all speed optimizations while your application contains pure business logic.
- Adapter: Abstraction layer for Drupal major version. The concept is thoroughly described here: #1932290: Forwardport doctrine - a proposed solution for Drupal major version migration problem. See 4.x branches of BOTCHA project (D6 & D7) together with common part x.x-1.x as an implementation of such audacious approach.


How does it work?

The only requirement is that oop syntax module must implement hook_boot() like so:

function hook_boot(){
  module_invoke('moopapi', 'register', '[YOUR CLASS NAME WHICH SHOULD BE THE MODULE NAME]');

This will register your class as module and will then simply work. Just enable it and enjoy.


Which version to choose?

Please use included .make-file as installation instruction.

Demo module to try this out

Create ooptest.module and stick code as follows into it.
Enable both moopapi.module with ooptest.module and then visit either to /oop or /oop-test to see that it works :-D


; $Id$
name = OOPTest
description = The Next Level $417
core = 6.x
version = VERSION



class ooptest {

  public function

menu() {
$items = array();
$items['oop-test'] = array (
'title'            => 'OOP Page Test',
'page callback'    => 'ooptest_fark',
'access arguments' => array('access content'),
'type'             => MENU_NORMAL_ITEM,
$items['oop'] = array (
'title'            => 'OOP FAPI Test',
'page callback'    => 'drupal_get_form',
'page arguments'   => array('ooptest_form'),
'access arguments' => array('access content'),
'type'             => MENU_NORMAL_ITEM,
  public function
boot() {

  public function

form_alter(&$form, $form_state, $form_id) {
    if (
'ooptest_form' == $form_id) {
$form['additional'] = array(
'#type' => 'radios',
'#title' => t('Is this cool or what!?!?!? - (hook_form_alter() item)'),
'#options' => array(
'Super cool!',
'Hell yeah!!!!',
'#default_value' => variable_get('additional', null),
'#weight' => -1,
  public function
form() {
$form = array();
$form['testing'] = array(
'#type'  => 'textfield',
'#title'  => t('This is a test field (form item)'),
'#default_value' => variable_get('testing', '134'),



  public function
fark () {
'hello world 2.0 style';

 * Implementing hook_boot() is a must, to force drupal to load this module as early as possible
 * Druring hook_init phase moopapi_init() will initialize all the oop method wrappers and execute hook oop->boot()
function ooptest_boot(){
module_invoke('moopapi', 'register', 'ooptest');

How much does it cost?

It is absolutely free. But you have the opportunity to contribute to the implementation of new features or speed up the closure of the bug that annoys you, or just to thank the developers.
Support this module to make new features to be implemented faster:

Project resources


PatchRanger - the first crowdfunded Drupal freelancer:
Flattr PatchRanger

Project Information