RD_Basic.pm

filter: Statementstmt 60.6% 20 / 33 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 6 / 9 Podpod 100% 2 / 2 totaltotal 60.8% 28 / 46 CC 2 SCAR 7.9
CC
2
Cov
57%
tell
6.0
help
2.0
say
2.0
CRAP 2.2
« RD.pm ↑ Summary
1 package Bot::BasicBot::Pluggable::Module::RD_Basic;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use base qw(Bot::BasicBot::Pluggable::Module);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Bot::BasicBot::Pluggable::Module::RD;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '0.02';
7  
8 =head1 NAME
9  
10 Bot::BasicBot::Pluggable::Module::RD_Basic - Basic RDBot commands
11  
12 =head1 SYNOPSIS
13  
14 !load RD
15  
16 See the synopsis of L<Bot::BasicBot::Pluggable> for how to load this plugin.
17  
18 =head1 DESCRIPTION
19  
20 This is an example module of how to use the
21 L<Bot::BasicBot::Pluggable::Module::RD> grammar framework, and should be
22 used as the basis of creating new pluggable RDBot modules.
23  
24 Note that the grammar and methods in this module are available once RD has
25 been loaded, but that will not be generally be true. A module that uses RD
26 will need to have RD loaded first.
27  
28 =head2 Grammar
29  
30 The following simple commands are provided:
31  
32 say Hello channel
33 tell ivorw I'm connected
34  
35 There's also a catch all verb "Sorry", useful for dealing with, and disposing
36 of error messages from other bots.
37  
38 =cut
39  
40 2 my $grammar = <<'END';
41 <autotree>
42  
43 command: 'say' /.*/
44 | 'tell' recipient /.*/
45 | 'Sorry'
46  
47 recipient: nick
48 | channel
49  
50 nick: /\w+/
51  
52 channel: /#\w+/
53  
54 END
55  
56 =head2 init
57  
58 This is called by the BasicBot infrastructure. Put anything else here that
59 needs to happen when your module is loaded.
60  
61 =cut
62  
63 3 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod documented
64 3 my $self = shift;
65  
66 3 Bot::BasicBot::Pluggable::Module::RD->extend( $grammar, __PACKAGE__ );
67 }
68  
69 =head2 help
70  
71 You need to provide a help method, which is called when someone says
72  
73 bot: help module
74  
75 See also L<Bot::BasicBot::Pluggable::Module>.
76  
77 =cut
78  
79 0 ▶sub help {
Subroutine help: not called CC=1 SCAR=6.9
Pod documented
80 0 my $self = shift;
81  
82 0 return <<'END';
83 Basic RecDescent bot commands:
84 say <message>
85 tell <recipient> <message>
86 END
87  
88 }
89  
90 =head2 command namespace
91  
92 You provide subs in __PACKAGE__::Command for each command verb which get
93 called. Note that there must be a new method available either here or in
94 its super class.
95  
96 =cut
97  
98 package Bot::BasicBot::Pluggable::Module::RD_Basic::Command;
99 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
100  
101 2 ▶use base qw(Parse::RecDescent::Topiary::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
102  
103 0 ▶sub say {
Subroutine say: not called CC=1 SCAR=6.9
104 0 my ( $self, $bot, $context ) = @_;
105  
106 0 my $msg = $self->{__PATTERN1__};
107 0 $bot->say( %$context, address => '', body => $msg );
108 }
109  
110 0 ▶sub tell {
Subroutine tell: not called CC=2 SCAR=17.9
111 0 my ( $self, $bot, $context ) = @_;
112  
113 0 my $msg = $self->{__PATTERN1__};
114 0 my $recip = $self->{recipient};
115  
116 0 ▶ if ( exists $recip->{nick} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $recip->{'nick'}) { } 0 0 0
117 0 my $nick = $recip->{nick}{__VALUE__};
118 0 $bot->say(
119 %$context,
120 body => $msg,
121 channel => 'msg',
122 who => $nick
123 );
124 }
125 else {
126 0 my $chan = $recip->{channel}{__VALUE__};
127 0 $bot->say(
128 %$context,
129 body => $msg,
130 address => '',
131 channel => $chan
132 );
133 }
134 }
135  
136 =head1 BUGS
137  
138 Please report any bugs to L<http://rt.cpan.org>.
139  
140 =head1 AUTHOR
141  
142 Ivor Williams
143 CPAN ID: IVORW
144
145 ivorw@cpan.org
146
147  
148 =head1 COPYRIGHT
149  
150 This program is free software; you can redistribute
151 it and/or modify it under the same terms as Perl itself.
152  
153 The full text of the license can be found in the
154 LICENSE file included with this module.
155  
156  
157 =head1 SEE ALSO
158  
159 perl(1).
160  
161 =cut
162  
163 2 1;
164  
« RD.pm ↑ Summary