Bot::Backbone::Service::Role::Dispatch - Role for services that can perform dispatch


version 0.161950


Any service that can use a dispatcher employ this role to make that happen.



  dispatcher default => as {

  service some_service => (
      service    => '=My::Service',
      dispatcher => 'default',

During construction, this is named dispatcher. This is the name of the dispatcher to load from the bot during initialization.


  my $dispatcher = $service->dispatcher;

Do not set this attribute. It will be loaded using the "dispatcher_name" automatically. It returns a Bot::Bakcbone::Dispatcher object to use for dispatch.

A dispatch_message method is also delegated to the dispatcher.


This is an optional setting for any dispatched service. Sometimes it is nice to use the same service more than once in a given context, but that does not work well when the service uses a fixed set of commands. This allows the commands to be remapped. It may also be that a user simply doesn't like the names originally chosen and this lets them change the names of any command.

This attribute takes a reference to a hash of strings which are used to remap the commands. The keys are the new commands to use and the values are the commands that should be replaced. A given command can only be renamed once.

For example,

  service roll => (
      service  => 'OFun::Roll',
      commands => {
          '!rolldice' => '!roll',
          '!flipcoin' => '!flip',

Using the Bot::Backbone::Service::OFun::Roll service, This would rename the !roll command to !rolldice and !flip to !flipcoin. In this case, using !roll in a chat with the bot would no longer have any effect on the service named "roll", but !rolldice would report the outcome of a dice roll.

If this does not provide enough flexibility, you can always go the route of completely replacing a service dispatcher with a new one (and you may want to check out "respond_by_service_method" in Bot::Backbone and "run_this_service_method" in Bot::Backbone for help doing that from the bot configuration). You can also define custom code to use "predicate_iterator" in Bot::Backbone::Dispatcher that walks the entire dispatcher tree and makes changes as needed, which is how this is implemented internally.



Rewrites the dispatcher according to the commands renamed in "commands".



If the service has a dispatcher configured, this will call the "dispatch_message" in Bot::Backbone::Dispatcher method on the dispatcher.


Make sure the dispatcher is initialized by initialization.


Andrew Sterling Hanenkamp <>


This software is copyright (c) 2016 by Qubling Software LLC.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.