Drupal::Admin::ModuleState - screen scraping Perl API to Drupal module state
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 $@;
Screen scraping Perl API to Drupal module state. Intended to be called from Drupal::Admin. The module can log through Log::Log4perl.
Though the term module is used, what is really meant is checkbox.
Maximum times to retry a commit. Multiple commits are sometimes necessary to overcome dependencies. Default is 4.
Constructor takes two required parameters; mech, an object of type WWW::Mechanize, and baseurl, the base URL of the drupal installation.
Return a list of the current module state in human readable form.
Return a list of module groups.
Return a list of module types (these are actually checkbox types, i.e. status and throttle).
status
throttle
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().
setstate()
commit()
Parameters:
Required boolean; 1 is enabled (checked), 0 is disabled (unchecked).
1
0
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.
Core - required
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.
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.
name
Database logging
status[dblog]
dblog
Disable all modules not in the Core - required group.
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.
warn()
The object's module list is then set to the current state from the modules page.
To install Drupal::Admin, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Drupal::Admin
CPAN shell
perl -MCPAN -e shell install Drupal::Admin
For more information on module installation, please visit the detailed CPAN module installation guide.