NAME

Bot::Backbone::Service - Useful features for services

VERSION

version 0.161950

SYNOPSIS

package MyBot::Service::Echo;
use v5.14; # because newer Perl is cooler than older Perl
use Bot::Backbone::Service;

with qw(
    Bot::Backbone::Service::Role::Service
    Bot::Backbone::Service::Role::Responder
);

# Instead of Bot::Backbone::Service::Role::Responder, you may prefer to
# apply the Bot::Backbone::Service::Role::ChatConsumer role instead. It
# really depends on if this module will be used across multiple chats or
# needs to be tied to a specific chat.

service_dispatcher as {
    command '!echo' => given_parameters {
        parameter thing => ( match => qr/.+/ );
    } respond_by_method 'echo_back';
};

sub echo_back {
    my ($self, $message) = @_;
    return $message->parameters->{thing};
}

__PACKAGE__->meta->make_immutable; # very good idea

DESCRIPTION

This is a Moose-replacement for bot backbone services. It provides a similar set of features to a service class as are provided to bot classes by Bot::Backbone.

SUBROUTINES

init_meta

Setup the bot package by applying the Bot::Backbone::Service::Role::Service role to the class.

SETUP ROUTINES

with_bot_roles

with_bot_roles ...;

Similar to with provided by Moose, this defines a list of roles that should be applied to the bot that uses this service.

service_dispatcher

service_dispatcher ...;

Setup the default dispatcher for this service. Use of this method will cause the Bot::Backbone::Service::Role::Dispatch role to be applied to the class.

DISPATCHER PREDICATES

This exports all the same dispatcher predicates as Bot::Backbone.

  • redispatch_to

  • command

  • not_command

  • given_parameters (and parameter)

  • to_me

  • not_to_me

  • shouted

  • spoken

  • whispered

  • also

RUN MODE OPERATIONS

This exports all the same run mode operations as Bot::Backbone.

  • as

  • respond. This run mode operation will be passed the service object as the first argument, rather than that bot object.

  • respond_with_method. As stated for respond, the first argument is the service object. The method is also a method defined within the current service package rather than the bot.

  • respond_with_bot_method. This is similar to respond_with_method, but instead of calling a method within the service, it will call a method directly on the bot to which the service has been added.

  • run_this. This run mode operation will be passed the service object as the first argument, rather than that bot object.

  • run_this_method. As stated for respond, the first argument is the service object. The method is also a method defined within the current service package rather than the bot.

  • run_this_bot_method. This is similar to run_this_method, but results in a call to a method on the bot object rather than on the service.

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.