Rene Schickbauer
and 1 contributors


Maplat::Worker - the Maplat Worker


The worker module is the one responsible for loading all actual working modules, dispatches calls and callbacks/hooks.

  my $config = XMLin($configfile,
                      ForceArray => [ 'module', 'directory' ],);
  $APPNAME = $config->{appname};
  print "Changing application name to '$APPNAME'\n\n";
  # set required values to default if they don't exist
  if(!defined($config->{mincycletime})) {
      $config->{mincycletime} = 10;
  my @modlist = @{$config->{module}};
  foreach my $module (@modlist) {
      $worker->configure($module->{modname}, $module->{pm}, %{$module->{options}});
  # main loop
  $cycleStartTime = time;
  while(1) {
      my $workCount = $worker->run();
      my $tmptime = time;
      my $workTime = $tmptime - $cycleStartTime;
      my $sleeptime = $config->{mincycletime} - $workTime;
      if($sleeptime > 0) {
          print "** Fast cycle ($workTime sec), sleeping for $sleeptime sec **\n";
          print "** Wake-up call **\n";
      } else {
          print "** Cycle time $workTime sec **\n";
      $cycleStartTime = time;


This worker is "the root of all evil". It loads and configures the working modules and dispatches callbacks/hooks.

Configuration and Startup

Configuration is done in stages from the main application, after new(), the first thing to call is startconfig() to prepare the worker for module configuration.

After that, for each module to load, configure() is called, during which the module is loaded and configured.

Next thing is to call endconfig(), which notifies the worker that all required modules are loaded (the worker then automatically calls reload() to load all cached data).

Running is done in a while loop or similar calling run(). As most workers dont have to react in the millisecond range, it's a good idea to have some code in place to try to do cyclic calls in a configurable cycle time. See also the synopsis and the example included in the tarball.


Create a new instance of Maplat::Worker.


Prepare the worker instance for module configuration.


Configure a worker module.


Finish up configuration and prepare for run().


Add a worker callback. Called by the various worker modules.


Add a worker cleanup callback. This is mostly used by the database modules to make sure there are no active transactions at the end of a run.


Do a single run of all registered worker callbacks.


Maplat::Web Maplat::Worker::BaseModule

Please also take a look in the example provided in the tarball available on CPAN.


Rene Schickbauer, <>


Copyright (C) 2008-2011 by Rene Schickbauer

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.