Bot-BasicBot-CommandBot

 view release on metacpan or  search on metacpan

lib/Bot/BasicBot/CommandBot.pm  view on Meta::CPAN


use Exporter 'import';
use base qw/Bot::BasicBot/;

our @EXPORT_OK = qw(command autocommand);

my %command;
my %autocommand;

sub command {
    (caller)[0]->declare_command(@_);
}

sub autocommand {
    (caller)[0]->declare_autocommand(@_);
}

sub declare_autocommand {
    my ($package, $sub) = @_;
    $autocommand{$package} = $sub;
}

sub declare_command {
    my $package = shift;
    my $sub = pop;

lib/Bot/BasicBot/CommandBot.pm  view on Meta::CPAN


This function is called by C<command>. It is a package method. It takes the
same arguments as C<command>, but it is called on a package:

    __PACKAGE__->declare_command(qr/^./, sub { ... });

This can be helpful if you don't want to put all your commands in the same
module - you can declare them all on the same package.

    sub import {
        my $caller = (caller)[0];
        $caller->declare_command(...);
    }

=head2 autocommand

An autocommand will be processed regardless of whether the message was
interpreted as a command or not.

    autocommand => sub {
        my $self = shift;



( run in 0.244 second using v1.01-cache-2.11-cpan-a3c8064c92c )