| 1 | =head1 NAME | ||||||||||
| 2 | |||||||||||
| 3 | IRC::Bot::Hangman::Response - Hangman responses' plugin engine | ||||||||||
| 4 | |||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||
| 6 | |||||||||||
| 7 | use IRC::Bot::Hangman::Response; | ||||||||||
| 8 | print IRC::Bot::Hangman::Response->get_a_msg( 'help' ); | ||||||||||
| 9 | |||||||||||
| 10 | =head1 DESCRIPTION | ||||||||||
| 11 | |||||||||||
| 12 | This module loads the responses plugins | ||||||||||
| 13 | and provide a message based on its name | ||||||||||
| 14 | |||||||||||
| 15 | =cut | ||||||||||
| 16 | |||||||||||
| 17 | package IRC::Bot::Hangman::Response; | ||||||||||
| 18 | 1 | ▶ | use warnings::register; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 1 | ▶ | use Carp qw( carp croak ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 1 | ▶ | use Module::Find qw( useall ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | 1 | our %RESPONSES; | |||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | 1 | foreach my $module ( useall( __PACKAGE__ ) ) { | |||||||||
| 27 | 2 | my $responses = $module->responses; | |||||||||
| 28 | 2 | foreach my $res_key ( keys %$responses ) { | |||||||||
| 29 | 12 | push @{$RESPONSES{$res_key}}, @{$responses->{$res_key}}; | |||||||||
| 30 | } | ||||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | |||||||||||
| 34 | |||||||||||
| 35 | =head2 get_a_msg( type ) | ||||||||||
| 36 | |||||||||||
| 37 | Returns all messages of a given type | ||||||||||
| 38 | |||||||||||
| 39 | =cut | ||||||||||
| 40 | |||||||||||
| 41 | 0 | ▶ | sub get_a_msg { | ||||||||
|
Subroutine
get_a_msg: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 42 | 0 | my $self = shift; | |||||||||
| 43 | 0 | my $type = shift; | |||||||||
| 44 | 0 | ▶ | my $msgs = $self->get_msgs($type) or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 0 | $msgs->[rand(@$msgs)]; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | |||||||||||
| 49 | =head2 get_msgs( type ) | ||||||||||
| 50 | |||||||||||
| 51 | Returns all messages of a given type | ||||||||||
| 52 | |||||||||||
| 53 | =cut | ||||||||||
| 54 | |||||||||||
| 55 | 0 | ▶ | sub get_msgs { | ||||||||
|
Subroutine
get_msgs: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 56 | 0 | my $class = shift; | |||||||||
| 57 | 0 | my $res_name = shift; | |||||||||
| 58 | 0 | ▶ | my $responses = $RESPONSES{$res_name} or carp "$res_name is not a registered response"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 0 | return $responses; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | |||||||||||
| 63 | |||||||||||
| 64 | 1 | 1; | |||||||||
| 65 | |||||||||||
| 66 | |||||||||||
| 67 | =head1 AUTHOR | ||||||||||
| 68 | |||||||||||
| 69 | Pierre Denis <pierre@itrelease.net> | ||||||||||
| 70 | |||||||||||
| 71 | http://www.itrelease.net/ | ||||||||||
| 72 | |||||||||||
| 73 | =head1 COPYRIGHT | ||||||||||
| 74 | |||||||||||
| 75 | Copyright 2005 IT Release Ltd - All Rights Reserved. | ||||||||||
| 76 | |||||||||||
| 77 | This module is released under the same license as Perl itself. | ||||||||||
| 78 | |||||||||||
| 79 | =cut | ||||||||||