Drupal::Admin::ModuleState(3p)

NAME
Drupal::Admin::ModuleState - screen scraping Perl API to Drupal module state

SYNOPSIS
  use Drupal::ModuleState;

  $Drupal::ModuleState::COMMITMAXRETRIES = 7;

  my $state = new Drupal::ModuleState(
                                      mech => $obj,
                                      baseurl => $url
                                     );
  my @list = $state->list;
  my @groups = $state->groups;
  my @types = $state->types;

  $state->setstate(
                   state => 1,
                   group => 'Core - optional',
                   type => 'status',
                   modules => ['aggregator', 'blog', 'color']
                  );

  eval{ $state->commit };
  warn($@) if $@;

  $state->core_required_disable;

  eval{ $state->commit };
  warn($@) if $@;

DESCRIPTION
Screen scraping Perl API to Drupal module state. Intended to be called from Drupal::Admin. The module can log through Log::Log4perl.

NOTES
Though the term module is used, what is really meant is checkbox.

CONSTANTS

$Drupal::ModuleState::COMMITMAXRETRIES
    Maximum times to retry a commit. Multiple commits are sometimes necessary to overcome dependencies. Default is 4.

METHODS

new Constructor takes two required parameters; mech, an object of type WWW::Mechanize, and baseurl, the base URL of the drupal installation.

list
    Return a list of the current module state in human readable form.

groups
    Return a list of module groups.

types
    Return a list of module types (these are actually checkbox types, i.e. "status" and "throttle").

setstate
    Sets the state of one or more modules.

    Note: setstate() will not create a new entry in the module array; thus, if a module doesn't exist in the list at the time it is set (e.g. a throttle checkbox) it will be silently ignored. The solution to this is to call setstate() in the right order and call commit() between calls to setstate().

    Parameters:

    state
        Required boolean; 1 is enabled (checked), 0 is disabled (unchecked).

    group
        Required; the name of the group to which the module (checkbox) belongs. This is identical to the user visible group (the fieldset) on the modules page. Note that "Core - required" is always ignored.

    type
        Optional; the checkbox type. To enable or disable the module itself, the type is "status". Another possibility is "throttle".

        Note that if state is set to 1 and type is not given and throttling is enabled, "status" and "throttle" (and any other additional heretofore unseen checkbox types) will be enabled; probably not what you want.

    modules
        Optional; list of module names to be operated upon. These are not the user visible module names, but rather the value of the "name" attribute without the type information. This is usually just a lowercase version of the user visible label, but not always; e.g. the "Database logging" module has the name attribute "status[dblog]", so in the module list it would be "dblog".

core_required_disable
    Disable all modules not in the "Core - required" group.

commit
    Attempt to commit the current module state. If one or more modules can't be set, calls warn() with an error message including list of modules that failed. Note that any modules on the current page that don't appear in the object's module list are ignored.

    The object's module list is then set to the current state from the modules page.