IRC::Bot::Hangman::Response - Hangman responses' plugin engine


IRC-Bot-Hangman documentation Contained in the IRC-Bot-Hangman distribution.

Index


Code Index:

NAME

Top

IRC::Bot::Hangman::Response - Hangman responses' plugin engine

SYNOPSIS

Top

  use IRC::Bot::Hangman::Response;
  print IRC::Bot::Hangman::Response->get_a_msg( 'help' );

DESCRIPTION

Top

This module loads the responses plugins and provide a message based on its name

get_a_msg( type )

Returns all messages of a given type

get_msgs( type )

Returns all messages of a given type

AUTHOR

Top

Pierre Denis <pierre@itrelease.net>

http://www.itrelease.net/

COPYRIGHT

Top


IRC-Bot-Hangman documentation Contained in the IRC-Bot-Hangman distribution.
package IRC::Bot::Hangman::Response;
use warnings::register;
use strict;
use Carp qw( carp croak );
use Module::Find qw( useall );

our %RESPONSES;


foreach my $module ( useall( __PACKAGE__ ) ) {
  my $responses = $module->responses;
  foreach my $res_key ( keys %$responses ) {
    push @{$RESPONSES{$res_key}}, @{$responses->{$res_key}};
  }
}



sub get_a_msg {
  my $self  = shift;
  my $type  = shift;
  my $msgs  = $self->get_msgs($type) or return;
  $msgs->[rand(@$msgs)];
}


sub get_msgs {
  my $class    = shift;
  my $res_name = shift;
  my $responses = $RESPONSES{$res_name} or carp "$res_name is not a registered response";
  return $responses;
}



1;