lib/IRC/Bot/Hangman/Response.pm

filter: Statementstmt 71.4% 20 / 28 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 4 / 6 Podpod 100% 2 / 2 totaltotal 65.0% 26 / 40 CC 3 SCAR 12.5
CC
3
Cov
62%
get_a_msg
6.0
get_msgs
6.0
BEGIN
1.0
CRAP 3.5
« lib/IRC/Bot/Hangman/Command/Default.pm ↑ Summary lib/IRC/Bot/Hangman/Command/Profanity.pm »
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
BranchTrueFalseTotal
my $msgs = $self->get_msgs($type) or return 0 0 0
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
BranchTrueFalseTotal
my $responses = $IRC::Bot::Hangman::Response::RESPONSES{$res_name} or carp("$res_name is not a registered response") 0 0 0
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
« lib/IRC/Bot/Hangman/Command/Default.pm ↑ Summary lib/IRC/Bot/Hangman/Command/Profanity.pm »