blib/lib/Test/Bot/BasicBot/Pluggable.pm

filter: Statementstmt 92.5% 25 / 27 Branchbran 100% 4 / 4 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 81.8% 9 / 11 Podpod 100% 6 / 6 totaltotal 85.7% 48 / 56 CC 5 SCAR 8.8
CC
5
Cov
89%
tell
5.0
connect
2.0
BEGIN
1.0
CRAP 2.4
« blib/lib/Bot/BasicBot/Pluggable/Store/Storable.pm ↑ Summary blib/lib/Bot/BasicBot/Pluggable/Store/Deep.pm »
1 package Test::Bot::BasicBot::Pluggable;
2 5 $Test::Bot::BasicBot::Pluggable::VERSION = '1.11';
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use base qw( Bot::BasicBot::Pluggable );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 sub new {
8 5 ▶ my ( $class, %args ) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
9 5 my $bot = $class->SUPER::new(
10 store => 'Memory',
11 nick => 'test_bot',
12 %args
13 );
14 5 return bless $bot, $class;
15 }
16  
17 sub tell_private {
18 22 ▶ return shift->tell( shift, 1, 1 );
Subroutine tell_private: called CC=1 SCAR=0.0
Pod documented
19 } # tell the module something privately
20  
21 61 ▶sub tell_direct { return shift->tell( shift, 0, 1 ) }
Subroutine tell_direct: called CC=1 SCAR=0.0
Pod documented
22  
23 sub tell_indirect {
24 148 ▶ return shift->tell( shift, 0, 0 );
Subroutine tell_indirect: called CC=1 SCAR=0.0
Pod documented
25 } # the module has seen something
26  
27 sub tell {
28 231 ▶ my ( $bot, $body, $private, $addressed, $who ) = @_;
Subroutine tell: called CC=5 SCAR=16.2
Pod documented
29 231 my @reply;
30 my $message = {
31 body => $body,
32 who => $who || 'test_user',
33 channel => $private ? 'msg' : '#test',
34 address => $addressed,
35 214 ▶ reply_hook => sub { push @reply, $_[1]; }, # $_[1] is the reply text
Subroutine __ANON__: called CC=1 SCAR=0.0
36 231 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$private ? : 22 209 231
Condition50%1/2
$who || 'test_user'
l!l
0231
MC/DC0%0/1
$who || 'test_user'
$who
Truth table50%1/2
A
A= $who
Aresult
11
00
37 231 ▶ if ( $body =~ /^help/ and $addressed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($body =~ /^help/ and $addressed) { } 1 230 231
Condition66%2/3
$body =~ /^help/ and $addressed
!ll&&!rl&&r
23001
MC/DC50%1/2
$body =~ /^help/ and $addressed
$body =~ /^help/ $addressed
Truth table66%2/3
A and B
A= $body =~ /^help/B= $addressed
ABresult
0X0
100
111
38 1 push @reply, $bot->help($message);
39 }
40 else {
41 230 $bot->said($message);
42 }
43 231 return join "\n", @reply;
44 }
45  
46 sub connect {
47 0 ▶ my $self = shift;
Subroutine connect: not called CC=1 SCAR=6.9
Pod documented
48 0 $self->dispatch('connected');
49 }
50  
51 # otherwise AUTOLOAD in Bot::BasicBot will be called
52 ▶sub DESTROY { }
Subroutine DESTROY: not called CC=1 SCAR=0.0
53  
54 5 1;
55  
56 __END__
57  
58 =head1 NAME
59  
60 Test::Bot::BasicBot::Pluggable - utilities to aid in testing of Bot::BasicBot::Pluggable modules
61  
62 =head1 VERSION
63  
64 version 1.11
65  
66 =head1 SYNOPSIS
67  
68 use Test::More;
69 use Test::Bot::BasicBot::Pluggable;
70  
71 my $bot = Test::Bot::BasicBot->new();
72 $bot->load('MyModule');
73  
74 is ( $bot->tell_direct('foo'), 'bar');
75 is ( $bot->tell_indirect('foo'), 'bar');
76 is ( $bot->tell_private('foo'), 'bar');
77  
78 =head1 DESCRIPTION
79  
80 Test::Bot::BasicBot::Pluggable was written to provide a
81 minimalistic testing bot in order to write cleaner unit tests for
82 Bot::BasicBot::Pluggable modules.
83  
84 =head1 SUBROUTINES/METHODS
85  
86 =head2 new
87  
88 Creates a new Test::Bot::BasicBot::Pluggable object, which is
89 basically just a subclass of Bot::BasicBot::Pluggable with a few
90 special methods. The default nickname is 'test_bot' and it contains
91 a in-memory store instead of sqlite. It takes the same arguments as
92 Bot::BasicBot::Pluggable.
93  
94 =head1 INSTANCE METHODS
95  
96 =head2 tell_direct
97  
98 Sends the provided string to the bot like it was send directly to the bot in a public channel. The channel is called '#test' and the sending user 'test_user'.
99  
100 test_user@#test> test_bot: foo
101  
102 =head2 tell_indirect
103  
104 Sends the provided string to the bot like it was send to a public channel without addressing. The channel is called '#test' and the sending user 'test_user'.
105  
106 test_user@#test> foo
107  
108 =head2 tell_private
109  
110 Sends the provided string to the bot like it was send in a private channel. The sending user 'test_user'.
111  
112 test_user@test_bot> foo
113  
114 =head2 tell
115  
116 This is the working horse of Test::Bot::BasicBot::Pluggable. It
117 basically builds a message hash as argument to the bots said()
118 function. You should never have to call it directly.
119  
120 =head2 connect
121  
122 Dispatch the connected event to all loaded modules without actually
123 connecting to anything.
124  
125 =head2 DESTROY
126  
127 The special subroutine is explicitly overridden with an empty
128 subroutine as otherwise AUTOLOAD in Bot::BasicBot will be called
129 for it.
130  
131 =head1 BUGS AND LIMITATIONS
132  
133 There are no methods to test join, part and emote.
134  
135 =head1 AUTHOR
136  
137 Mario Domgoergen <mdom@cpan.org>
138  
139 =head1 LICENSE AND COPYRIGHT
140  
141 Copyright 2009 Mario Domgoergen, all rights reserved.
142  
143 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
« blib/lib/Bot/BasicBot/Pluggable/Store/Storable.pm ↑ Summary blib/lib/Bot/BasicBot/Pluggable/Store/Deep.pm »