The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Bot::Backbone::Bot - Provides backbone services to your bot

VERSION

version 0.161950

SYNOPSIS

  my $bot = My::Bot->new;
  $bot->run;

DESCRIPTION

When you use Bot::Backbone in your code, you get a bot implementing this role. It provides tools for constructing, executing, and shutting down services.

ATTRIBUTES

event_loop

Bots do all their work using an event loop. Usually, this is either POE or AnyEvent. Fortunately, these event loops tend to work well together in case you need both. Just in case you need specialized startup for your bot's event loop, though, this is attribute is provided to allow the event loop startup to be customized.

This is an object or class on which you may call a run with no arguments. It will be called to start the event loop. By default, this is just "POE::Kernel". It is expected that this method will block until the bot is shutdown.

services

This is a hash of constructed services used by this bot. There should be a key in this hash matching every key in the same attribute in Bot::Backbone::Meta::Class, once "run" has been called.

initialized_services

This is a set containing the names of all the services that have been constructed and initialized.

METHODS

bot

Returns itself.

construct_services

  $bot->construct_services;

This method iterates through the service configurations of the meta class and constructs each service from that configuration.

You may run this prior to "run" to construct your services prior to running. Normally, though, this method is called within "run".

initialize_services

  $bot->initialize_services;

If more services are added to the bot later, this method may be called to initialize services after the new services have been constructed.

run

  $bot->run;

This starts your bot running. It constructs the services if they have not yet been constructed. Then, it initializes each service. Finally, it starts the POE event loop. This last part really isn't it's business and might go away in the future.

This method will not return until the event loop terminates. The usual way to do this is to call "shutdown".

shutdown

  $bot->shutdown;

You may call this at any time while your bot is running to shutdown all the services. This notifies each service that it should shutdown (i.e., finish or terminate any pending jobs in the event loop). It then clears the "services" hash, which should cause all services to be destroyed.

CAVEATS

This thing sort of kind of needs POE to be any kind of useful. However, POE seems to have weird drawbacks. I have some planned work-arounds for this being an explicit and required dependency, but it's there for now.

Second, if you use the Jabber chat service, you need AnyEvent. Mostly, AnyEvent and POE seem to get along, but it's slow and I've found that timers, in particular, just plain don't work quite right.

AUTHOR

Andrew Sterling Hanenkamp <hanenkamp@cpan.org>

COPYRIGHT AND LICENSE

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.