lib/IRC/Bot/Hangman/Command.pm

filter: Statementstmt 51.2% 21 / 41 Branchbran 75.0% 6 / 8 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 4 / 8 Podpod 100% 3 / 3 totaltotal 51.5% 34 / 66 CC 5 SCAR 19.0
CC
5
Cov
51%
_do_process
12.0
run
12.0
pre_process
2.0
CRAP 6.7
« lib/IRC/Bot/Hangman.pm ↑ Summary lib/IRC/Bot/Hangman/WordList.pm »
1 =head1 NAME
2  
3 IRC::Bot::Hangman::Command - Hangman commands' plugin engine
4  
5 =head1 SYNOPSIS
6  
7 See IRC::Bot::Hangman
8  
9 use IRC::Bot::Hangman::Command;
10 IRC::Bot::Hangman::Command->run( 'play' );
11  
12 =head1 DESCRIPTION
13  
14 This module execute the commands
15 by calling the right plugin
16  
17 =cut
18  
19 package IRC::Bot::Hangman::Command;
20 1 ▶use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Carp qw( carp croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Module::Find qw( useall );
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 1 our @PLUGINS = useall( 'IRC::Bot::Hangman::Command' );
26 1 ▶our %COMMANDS = map { %{ $_->can('commands') ? $_->commands : {} } } @PLUGINS;
Branch: 1 branch
BranchTrueFalseTotal
$_->can('commands') ? : 1 2 3
27 1 ▶our @PRE_PROCESS = map { $_->can('pre_process') ? $_ : () } @PLUGINS;
Branch: 1 branch
BranchTrueFalseTotal
$_->can('pre_process') ? : 1 2 3
28 1 ▶our @POST_PROCESS = map { $_->can('post_process') ? $_ : () } @PLUGINS;
Branch: 1 branch
BranchTrueFalseTotal
$_->can('post_process') ? : 1 2 3
29  
30  
31  
32 =head2 pre_process( robot )
33  
34 Call pre_process on all plugins
35 which have implemented pre_process()
36  
37 =cut
38  
39 0 ▶sub pre_process {
Subroutine pre_process: not called CC=1 SCAR=6.9
Pod documented
40 0 my $class = shift;
41 0 my $robot = shift;
42 0 $class->_do_process( $robot, 'pre_process', \@PRE_PROCESS );
43 }
44  
45 =head2 post_process( robot )
46  
47 Call post_process on all plugins
48 which have implemented pre_process()
49  
50 =cut
51  
52 0 ▶sub post_process {
Subroutine post_process: not called CC=1 SCAR=6.9
Pod documented
53 0 my $class = shift;
54 0 my $robot = shift;
55 0 $class->_do_process( $robot, 'post_process', \@POST_PROCESS );
56 }
57  
58  
59 0 ▶sub _do_process {
Subroutine _do_process: not called CC=3 SCAR=24.8
60 0 my $class = shift;
61 0 my $robot = shift;
62 0 my $cmd = shift;
63 0 ▶ my $classes = shift || [];
Condition0%0/2
shift() || []
l!l
00
MC/DC0%0/1
shift() || []
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
64 0 foreach my $pclass ( @$classes ) {
65 0 $pclass->$cmd( $robot );
66 }
67 }
68  
69  
70 =head2 run( robot )
71  
72 Execute a command if registered in a IRC::Bot::Hangman::Command plugin
73  
74 =cut
75  
76 0 ▶sub run {
Subroutine run: not called CC=3 SCAR=24.8
Pod documented
77 0 my $class = shift;
78 0 my $robot = shift;
79  
80 0 $class->pre_process( $robot );
81  
82 0 ▶ my (@args) = split /[\s,.;]+/, ( $robot->input || '');
Condition0%0/2
$robot->input || ''
l!l
00
MC/DC0%0/1
$robot->input || ''
$robot->input
Truth table0%0/2
A
A= $robot->input
Aresult
11
00
83 0 my $cmd = lc shift @args;
84 0 ▶ if ( my $cmd_ref = $COMMANDS{$cmd} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cmd_ref = $IRC::Bot::Hangman::Command::COMMANDS{$cmd}) 0 0 0
85 0 $cmd_ref->( $robot, @args );
86 }
87  
88 0 $class->post_process( $robot );
89 }
90  
91  
92 1 1;
93  
94  
95 =head1 AUTHOR
96  
97 Pierre Denis <pierre@itrelease.net>
98  
99 http://www.itrelease.net/
100  
101 =head1 COPYRIGHT
102  
103 Copyright 2005 IT Release Ltd - All Rights Reserved.
104  
105 This module is released under the same license as Perl itself.
106  
107 =cut
« lib/IRC/Bot/Hangman.pm ↑ Summary lib/IRC/Bot/Hangman/WordList.pm »