IRC::Bot::Hangman::WordList - Word list plugin engine


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

Index


Code Index:

NAME

Top

IRC::Bot::Hangman::WordList - Word list plugin engine

SYNOPSIS

Top

  use IRC::Bot::Hangman::WordList;
  $words = IRC::Bot::Hangman::WordList->load( 'too_easy' );
  print $words->[3];

DESCRIPTION

Top

This module loads the word list plugins and provide a list based on a name

load( plugin name )

Returns a word list loaded from a specific plugin

word_list

Loads the word list

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::WordList;
use warnings::register;
use strict;
use Carp qw( carp croak );
use Module::Find qw( useall );

our %WORDLISTS = map { $_->name => $_ } useall( __PACKAGE__ );



sub load {
  my $class  = shift;
  my $name   = shift;
  my $module = $WORDLISTS{$name};
  unless ($module) {
    carp "$name is not a registered word list, try " . join(' or ', keys %WORDLISTS);
    return;
  }

  $class->word_list( $module );
}


sub word_list {
  my $self   = shift;
  my $module = shift;
  my $fh = "${module}::DATA";
  my @words;
  while (<$fh>) {
    chomp;
    push @words, $_ if $_;
  }
  \@words;
}


1;