The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Bot::Cobalt::Core - Bot::Cobalt core and event syndicator

DESCRIPTION

This module is the core of Bot::Cobalt, tying an event syndicator (via POE::Component::Syndicator and Object::Pluggable) into a logger instance, configuration manager, and other useful tools.

Core is a singleton; within a running Cobalt instance, you can always retrieve the Core via the instance method:

require Bot::Cobalt::Core;
my $core = Bot::Cobalt::Core->instance;

You can also query to find out if Core has been properly instanced:

if ( Bot::Cobalt::Core->has_instance ) {

}

If you 'use Bot::Cobalt;' you can also access the Core singleton instance via the core() exported sugar:

use Bot::Cobalt;
core->log->info("I'm here now!")

See Bot::Cobalt::Core::Sugar for details.

Public methods are documented in "Core methods" in Bot::Cobalt::Manual::Plugins and the classes & roles listed below.

See also:

Custom frontends

It's trivially possible to write custom frontends to spawn a Cobalt instance; Bot::Cobalt::Core just needs to be initialized with a valid configuration object and spawned via POE::Kernel's run() method.

A configuration object is an instanced Bot::Cobalt::Conf:

my $conf_obj = Bot::Cobalt::Conf->new(
  etc => $path_to_etc_dir,
);

. . . then passed to Bot::Cobalt::Core before the POE kernel is started:

## Instance a Bot::Cobalt::Core singleton
## Further instance() calls will return the singleton
Bot::Cobalt::Core->instance(
  cfg => $conf_obj,
  var => $path_to_var_dir,

  ## See perldoc Bot::Cobalt::Logger regarding log levels:
  loglevel => $loglevel,

  ## Debug levels:
  debug => $debug,

  ## Indicate whether or not we're a daemon
  ## (Changes behavior of logging and signals)
  detached => $detached,
)->init;

Frontends have to worry about daemonization on their own.

AUTHOR

Jon Portnoy <avenj@cobaltirc.org>