Bot/BasicBot/Pluggable.pm

filter: Statementstmt 17.9% 57 / 317 Branchbran 0.0% 0 / 132 Conditioncond 0.0% 0 / 56 MC/DCmcdc 0.0% 0 / 33 Subroutinesub 25.0% 17 / 68 Podpod 8.5% 3 / 35 totaltotal 12.0% 77 / 641 CC 99 SCAR 41.8
CC
99
Cov
11%
say
272.0
irc_received_state
240.0
dispatch_priorities
90.0
CRAP 65.6
↑ Summary Log/Log4perl.pm »
1 package Irssi::Bot::BasicBot::Pluggable;
2 # ABSTRACT: Run Bot::BasicBot::Pluggable::Module_s in Irssi
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Irssi::Log::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 use Module::Pluggable
9 1 ▶ sub_name => '_available',
Subroutine BEGIN: called CC=1 SCAR=0.0
10 search_path => 'Bot::BasicBot::Pluggable::Module',
11 1 except => 'Bot::BasicBot::Pluggable::Module::Base';
12  
13 1 ▶use Bot::BasicBot::Pluggable::Module;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Bot::BasicBot::Pluggable::Store;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Capture::Tiny 'capture';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Text::Wrap ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 #use Carp::Always;
20  
21 # POE::Session constants
22 0 ▶sub OBJECT () { 0 }
Subroutine OBJECT: not called CC=1 SCAR=6.9
Pod undocumented
23 0 ▶sub ARG0 () { 10 }
Subroutine ARG0: not called CC=1 SCAR=6.9
Pod undocumented
24 0 ▶sub ARG1 () { 11 }
Subroutine ARG1: not called CC=1 SCAR=6.9
Pod undocumented
25 0 ▶sub ARG2 () { 12 }
Subroutine ARG2: not called CC=1 SCAR=6.9
Pod undocumented
26  
27 0 ▶sub new ($cls, @config) {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
28 0 my $self = bless +{ @config } => $cls;
29  
30 0 print "These modules are available for loading: "
31 . join( ", ", $self->available_modules );
32  
33 0 ▶ $self->init or die "init did not return a true value - dying";
Branch: 1 branch
BranchTrueFalseTotal
$self->init or die "init did not return a true value - dying" 0 0 0
34  
35 0 return $self;
36 }
37  
38 0 ▶sub MULTINET { 1 }
Subroutine MULTINET: not called CC=1 SCAR=6.9
Pod undocumented
39  
40 0 ▶sub init_logging { undef }
Subroutine init_logging: not called CC=1 SCAR=6.9
Pod undocumented
41  
42 0 ▶sub init ($self) {
Subroutine init: not called CC=1 SCAR=6.9
Pod undocumented
43 0 $self->init_logging();
44  
45 0 my $logger = Irssi::Log::Log4perl->get_logger( ref $self );
46 0 $logger->info( 'Starting initialization of ' . ref $self );
47  
48 0 return 1;
49 }
50  
51 0 ▶sub log {
Subroutine log: not called CC=2 SCAR=17.9
Pod documented
52 0 my $self = shift;
53 0 my $logger = Irssi::Log::Log4perl->get_logger( ref $self );
54 0 for my $log_entry (@_) {
55 0 chomp $log_entry;
56 0 $logger->warn($log_entry);
57 }
58 0 return;
59 }
60  
61 0 ▶sub available_modules ($self) {
Subroutine available_modules: not called CC=1 SCAR=6.9
Pod undocumented
62 my @modules = sort
63 map {
64 0 my $mod = $_;
65 0 $mod =~ s/^Bot::BasicBot::Pluggable::Module:://;
66 0 $mod;
67 } $self->_available();
68 0 return @modules;
69 }
70  
71 0 ▶sub dispatch ($self, $method, @args) {
Subroutine dispatch: not called CC=7 SCAR=40.3
Pod undocumented
72 0 my $logger = Irssi::Log::Log4perl->get_logger( ref $self );
73  
74 0 ▶ $logger->info("Dispatching $method")
Branch: 1 branch
BranchTrueFalseTotal
unless $method eq "tick" 0 0 0
75 unless $method eq 'tick';
76 0 for my $who ( $self->modules ) {
77 ## Otherwise we would see tick every five seconds
78 0 ▶ if ( $method eq 'tick' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq 'tick') { } 0 0 0
79 0 $logger->trace("Trying to dispatch $method to $who");
80 }
81 else {
82 0 $logger->debug("Trying to dispatch $method to $who");
83 }
84 0 ▶ $logger->trace( "... with " . Dumper(@args) )
Branch: 1 branch
BranchTrueFalseTotal
if $logger->is_trace and @args 0 0 0
Condition0%0/3
$logger->is_trace and @args
!ll&&!rl&&r
000
MC/DC0%0/2
$logger->is_trace and @args
$logger->is_trace @args
Truth table0%0/3
A and B
A= $logger->is_traceB= @args
ABresult
0X0
100
111
85 if $logger->is_trace && @args;
86  
87 0 ▶ next unless $self->module($who)->can($method);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->module($who)->can($method) 0 0 0
88 0 ▶ try {
Subroutine __ANON__: not called CC=2 SCAR=17.9
89 0 ▶ $logger->trace(
Branch: 1 branch
BranchTrueFalseTotal
if $logger->is_trace 0 0 0
90 "Dispatching $method to $who with " . Dumper(@args) )
91 if $logger->is_trace;
92 0 $self->module($who)->$method(@args);
93 }
94 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
95 0 $logger->warn($_);
96 }
97 0 }
98 0 return;
99 }
100  
101 0 ▶sub tick ($self) {
Subroutine tick: not called CC=1 SCAR=6.9
Pod undocumented
102 0 $self->dispatch('tick');
103 0 return 5;
104 }
105  
106 0 ▶sub dispatch_priorities ($self, $event, $mess) {
Subroutine dispatch_priorities: not called CC=9 SCAR=45.0
Pod undocumented
107 0 my $response;
108 my $who;
109  
110 0 my $logger = Irssi::Log::Log4perl->get_logger( ref $self );
111 0 $logger->info("Dispatching $event event");
112  
113 0 for my $priority ( 0 .. 3 ) {
114 0 for my $module ( $self->modules ) {
115 0 my $response;
116 0 $logger->debug(
117 "Trying to dispatch $event to $module on priority $priority");
118 0 ▶ $logger->trace( '... with arguments ' . Dumper($mess) )
Branch: 1 branch
BranchTrueFalseTotal
if $logger->is_trace and $mess 0 0 0
Condition0%0/3
$logger->is_trace and $mess
!ll&&!rl&&r
000
MC/DC0%0/2
$logger->is_trace and $mess
$logger->is_trace $mess
Truth table0%0/3
A and B
A= $logger->is_traceB= $mess
ABresult
0X0
100
111
119 if $logger->is_trace and $mess;
120 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
121 0 $response =
122 $self->module($module)->$event( $mess, $priority );
123 }
124 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
125 0 $logger->warn($_);
126 0 };
127 0 ▶ if ( $priority and $response ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($priority and $response) 0 0 0
Condition0%0/3
$priority and $response
!ll&&!rl&&r
000
MC/DC0%0/2
$priority and $response
$priority $response
Truth table0%0/3
A and B
A= $priorityB= $response
ABresult
0X0
100
111
128 0 $logger->debug("Response by $module on $priority");
129 0 ▶ $logger->trace( 'Response is ' . Dumper($response) )
Branch: 1 branch
BranchTrueFalseTotal
if $logger->is_trace 0 0 0
130 if $logger->is_trace;
131 0 ▶ return if $response eq '1';
Branch: 1 branch
BranchTrueFalseTotal
if $response eq 1 0 0 0
132 0 $self->reply( $mess, $response );
133 0 return;
134 }
135 }
136 }
137 0 return;
138 }
139  
140 0 ▶sub reply ($self, $mess, @other) {
Subroutine reply: not called CC=2 SCAR=17.9
Pod undocumented
141 0 $self->dispatch( 'replied', {%$mess}, @other );
142 0 ▶ if ( $mess->{reply_hook} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mess->{'reply_hook'}) { } 0 0 0
143 0 return $mess->{reply_hook}->( $mess, @other );
144 }
145 else {
146 0 my ($body) = @other;
147 0 my %hash = %$mess;
148 0 $hash{body} = $body;
149 0 return $self->say(%hash);
150 }
151 }
152  
153 0 ▶sub say {
Subroutine say: not called CC=16 SCAR=56.1
Pod undocumented
154 # If we're called without an object ref, then we're handling saying
155 # stuff from inside a forked subroutine, so we'll freeze it, and toss
156 # it out on STDOUT so that POE::Wheel::Run's handler can pick it up.
157 0 ▶ if (!ref $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_[0]) 0 0 0
158 0 print $_[0], "\n";
159 0 return 1;
160 }
161  
162 # Otherwise, this is a standard object method
163  
164 0 my $self = shift;
165 0 my $args;
166 0 ▶ if (ref $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 0 0
167 0 $args = shift;
168 }
169 else {
170 0 my %args = @_;
171 0 $args = \%args;
172 }
173  
174 0 my $body = $args->{body};
175  
176 # add the "Foo: bar" at the start
177 0 ▶ if ($args->{channel} ne "msg" && defined $args->{address}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"channel"} ne "msg" and defined $args->{"address"}) 0 0 0
Condition0%0/3
$args->{"channel"} ne "msg" and defined $args->{"address"}
!ll&&!rl&&r
000
MC/DC0%0/2
$args->{"channel"} ne "msg" and defined $args->{"address"}
$args->{"channel"} ne "msg" defined $args->{"address"}
Truth table0%0/3
A and B
A= $args->{"channel"} ne "msg"B= defined $args->{"address"}
ABresult
0X0
100
111
178 0 $body = "$args->{who}: $body";
179 }
180  
181 # work out who we're going to send the message to
182 0 ▶ my $who = $args->{channel} eq "msg" ? $args->{who} : $args->{channel};
Branch: 1 branch
BranchTrueFalseTotal
$args->{'channel'} eq 'msg' ? : 0 0 0
183  
184 0 ▶ if (!defined $who || !defined $body) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $who and defined $body) 0 0 0
Condition0%0/3
defined $who and defined $body
!ll&&!rl&&r
000
MC/DC0%0/2
defined $who and defined $body
defined $who defined $body
Truth table0%0/3
A and B
A= defined $whoB= defined $body
ABresult
0X0
100
111
185 0 $self->log("Can't send a message without target and body\n"
186 . " called from "
187 . ( [caller]->[0] )
188 . " line "
189 . ( [caller]->[2] ) . "\n"
190 . " who = '$who'\n body = '$body'\n");
191 0 return;
192 }
193  
194 # if we have a long body, split it up..
195 #local $Text::Wrap::columns = 300;
196 0 local $Text::Wrap::columns = 294;
197 0 local $Text::Wrap::unexpand = 0; # no tabs
198 0 my $wrapped = Text::Wrap::wrap('', '..', $body); # =~ m!(.{1,300})!g;
199 # I think the Text::Wrap docs lie - it doesn't do anything special
200 # in list context
201 0 my @bodies = split /\n+/, $wrapped;
202  
203 # Allows to override the default "PRIVMSG". Used by notice()
204 my $irc_command = defined $args->{irc_command}
205 0 ▶ && $args->{irc_command} eq 'notice'
Branch: 1 branch
BranchTrueFalseTotal
defined $args->{'irc_command'} && $args->{'irc_command'} eq 'notice' ? : 0 0 0
Condition0%0/3
defined $args->{"irc_command"} and $args->{"irc_command"} eq "notice"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $args->{"irc_command"} and $args->{"irc_command"} eq "notice"
defined $args->{"irc_command"} $args->{"irc_command"} eq "notice"
Truth table0%0/3
A and B
A= defined $args->{"irc_command"}B= $args->{"irc_command"} eq "notice"
ABresult
0X0
100
111
206 ? 'notice'
207 : 'privmsg';
208  
209 # possibility to set the network
210 local $self->{conn_tag} = $args->{network}
211 0 ▶ if $args->{network};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"network"} 0 0 0
212  
213 # post an event that will send the message
214 0 my $last_color;
215 0 for my $body (@bodies) {
216 0 ▶ if (defined $last_color) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last_color) 0 0 0
217 0 $body = "..\cC$last_color".substr $body, 2;
218 }
219 0 ▶ if ((my $bcol = rindex $body, "\cC") > -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $bcol = rindex($body, "\3")) > -1) 0 0 0
220 0 ▶ $last_color = (substr $body, $bcol + 1) =~ /^(\d{1,2}(?:,\d{1,2})?)/ ? $1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
substr($body, $bcol + 1) =~ /^(\d{1,2}(?:,\d{1,2})?)/ ? : 0 0 0
221 }
222 0 ▶ if ($who eq '@@@ local user @@@') {
Branch: 1 branch
BranchTrueFalseTotal
if ($who eq '@@@ local user @@@') { } 0 0 0
223 0 $self->localresponse({ body => $body });
224 } else {
225 0 $self->{irssi}->$irc_command($self, $who, $body);
226 }
227 }
228  
229 0 return;
230 }
231  
232 0 ▶sub irc_chan_received_state ($self, $received, $nick, $address, $channel) {
Subroutine irc_chan_received_state: not called CC=5 SCAR=34.0
Pod undocumented
233 0 my $return;
234 0 my $mess = {};
235 0 ▶ return unless $nick && $address;
Branch: 1 branch
BranchTrueFalseTotal
unless $nick and $address 0 0 0
Condition0%0/3
$nick and $address
!ll&&!rl&&r
000
MC/DC0%0/2
$nick and $address
$nick $address
Truth table0%0/3
A and B
A= $nickB= $address
ABresult
0X0
100
111
236 0 $mess->{who} = $nick;
237 0 $mess->{raw_nick} = "$nick!$address";
238  
239 0 $mess->{channel} = $channel;
240 0 $mess->{body} = $received; #chanjoin or chanpart
241 0 $mess->{address} = "chan";
242  
243 # okay, call the chanjoin/chanpart method
244 0 $return = $self->$received($mess);
245  
246 ### what did we get back?
247  
248 # nothing? Say nothing then
249 0 ▶ return if !defined $return;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $return 0 0 0
250  
251 # a string? Say it how we were addressed then
252 0 ▶ if (!ref $return) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $return) 0 0 0
253 0 $mess->{body} = $return;
254 0 $self->say($mess);
255 0 return;
256 }
257 }
258  
259 0 ▶sub irc_received_state ($self, $received, $respond, $nick, $address, $target, $body) {
Subroutine irc_received_state: not called CC=15 SCAR=54.8
Pod undocumented
260 0 my $return;
261 0 my $mess = {};
262  
263 # pass the raw body through
264 0 $mess->{raw_body} = $body;
265  
266 # work out who it was from
267 0 ▶ return unless $nick && $address;
Branch: 1 branch
BranchTrueFalseTotal
unless $nick and $address 0 0 0
Condition0%0/3
$nick and $address
!ll&&!rl&&r
000
MC/DC0%0/2
$nick and $address
$nick $address
Truth table0%0/3
A and B
A= $nickB= $address
ABresult
0X0
100
111
268 0 $mess->{who} = $nick;
269 0 $mess->{raw_nick} = "$nick!$address";
270  
271 # right, get the list of places this message was
272 # sent to and work out the first one that we're
273 # either a memeber of is is our nick.
274 # The IRC protocol allows messages to be sent to multiple
275 # targets, which is pretty clever. However, noone actually
276 # /does/ this, so we can get away with this:
277  
278 0 my $channel = $target;
279 0 ▶ if (lc($channel) eq lc($self->nick)) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $channel eq lc $self->nick) { } 0 0 0
280 0 $mess->{channel} = "msg";
281 0 $mess->{address} = "msg";
282 }
283 else {
284 0 $mess->{channel} = $channel;
285 }
286  
287 # okay, work out if we're addressed or not
288  
289 0 $mess->{body} = $body;
290 0 ▶ if ($mess->{channel} ne "msg") {
Branch: 1 branch
BranchTrueFalseTotal
if ($mess->{"channel"} ne "msg") 0 0 0
291 0 my $own_nick = $self->nick;
292  
293 0 ▶ if ($mess->{body} =~ s/^(\Q$own_nick\E)\s*[:,-]?\s*//i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mess->{"body"} =~ s/^(\Q$own_nick\E)\s*[:,-]?\s*//i) 0 0 0
294 0 $mess->{address} = $1;
295 }
296  
297 0 for my $alt_nick ($self->alt_nicks) {
298 0 ▶ last if $mess->{address};
Branch: 1 branch
BranchTrueFalseTotal
if $mess->{"address"} 0 0 0
299 0 ▶ if ($mess->{body} =~ s/^(\Q$alt_nick\E)\s*[:,-]?\s*//i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mess->{"body"} =~ s/^(\Q$alt_nick\E)\s*[:,-]?\s*//i) 0 0 0
300 0 $mess->{address} = $1;
301 }
302 }
303 }
304  
305 # strip off whitespace before and after the message
306 0 $mess->{body} =~ s/^\s+//;
307 0 $mess->{body} =~ s/\s+$//;
308  
309 # check if someone was asking for help
310 0 ▶ if ($mess->{address} && $mess->{body} =~ /^help/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mess->{"address"} and $mess->{"body"} =~ /^help/i) 0 0 0
Condition0%0/3
$mess->{"address"} and $mess->{"body"} =~ /^help/i
!ll&&!rl&&r
000
MC/DC0%0/2
$mess->{"address"} and $mess->{"body"} =~ /^help/i
$mess->{"address"} $mess->{"body"} =~ /^help/i
Truth table0%0/3
A and B
A= $mess->{"address"}B= $mess->{"body"} =~ /^help/i
ABresult
0X0
100
111
311 0 ▶ $mess->{body} = $self->help($mess) or return;
Branch: 1 branch
BranchTrueFalseTotal
$mess->{"body"} = $self->help($mess) or return 0 0 0
312 0 $self->say($mess);
313 0 return;
314 }
315  
316 # okay, call the said/emoted method
317 0 $return = $self->$received($mess);
318  
319 ### what did we get back?
320  
321 # nothing? Say nothing then
322 0 ▶ return if !defined $return;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $return 0 0 0
323  
324 # a string? Say it how we were addressed then
325 0 ▶ if (!ref $return && length $return) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $return and length $return) 0 0 0
Condition0%0/3
not ref $return and length $return
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $return and length $return
not ref $return length $return
Truth table0%0/3
not(A) and B
A= not ref $returnB= length $return
ABresult
0X0
100
111
326 0 $mess->{body} = $return;
327 0 $self->$respond($mess);
328 0 return;
329 }
330 }
331  
332 0 ▶sub localresponse ($self, $mess) {
Subroutine localresponse: not called CC=2 SCAR=17.9
Pod undocumented
333 0 ▶ print "[ => ] " . ($self->{server} ? "[$self->{server}{tag}] " : "") . $mess->{body};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'server'} ? : 0 0 0
334 }
335  
336 0 ▶sub nick ($self, $network = undef) {
Subroutine nick: not called CC=3 SCAR=24.8
Pod undocumented
337 0 ▶ local $self->{conn_tag} = $network
Branch: 1 branch
BranchTrueFalseTotal
if $network 0 0 0
338 if $network;
339 0 $self->{irssi}->own_nick($self)
340 }
341  
342 0 ▶sub alt_nicks ($self, $network = undef) {
Subroutine alt_nicks: not called CC=3 SCAR=24.8
Pod undocumented
343 0 ▶ local $self->{conn_tag} = $network
Branch: 1 branch
BranchTrueFalseTotal
if $network 0 0 0
344 if $network;
345 0 $self->{irssi}->find_alternate_nicks($self)
346 }
347  
348 0 ▶sub forkit {
Subroutine forkit: not called CC=5 SCAR=34.0
Pod undocumented
349 0 my $self = shift;
350 0 my $args;
351  
352 0 ▶ if (ref($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 0 0
353 0 $args = shift;
354 }
355 else {
356 0 my %args = @_;
357 0 $args = \%args;
358 }
359  
360 0 ▶ return if !$args->{run};
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"run"} 0 0 0
361  
362 0 ▶ $args->{handler} = $args->{handler} || "_fork_said";
Condition0%0/2
$args->{'handler'} || '_fork_said'
l!l
00
MC/DC0%0/1
$args->{'handler'} || '_fork_said'
$args->{'handler'}
Truth table0%0/2
A
A= $args->{'handler'}
Aresult
11
00
363 0 ▶ $args->{arguments} = $args->{arguments} || [];
Condition0%0/2
$args->{'arguments'} || []
l!l
00
MC/DC0%0/1
$args->{'arguments'} || []
$args->{'arguments'}
Truth table0%0/2
A
A= $args->{'arguments'}
Aresult
11
00
364  
365 #$poe_kernel->state( $args->{handler}, $args->{callback} || $self );
366  
367 0 my $run;
368 0 ▶ $run = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
369 0 ▶ my ($stdout, $stderr, $result) = capture {
Subroutine __ANON__: not called CC=1 SCAR=6.9
370 0 return scalar $args->{run}->($args->{body}, @{ $args->{arguments} });
371 0 };
372 0 ▶ return $stdout || $result;
Condition0%0/3
$stdout || $result
l!l&&r!l&&!r
000
MC/DC0%0/2
$stdout || $result
$stdout $result
Truth table0%0/3
A || B
A= $stdoutB= $result
ABresult
1X1
011
000
373 0 };
374  
375 0 my $pt = $self->{irssi}->bg_do($run, $args->{handler});
376  
377 # store the wheel object in our bot, so we can retrieve/delete easily
378  
379 $self->{forks}{ $pt } = {
380 args => {
381 conn_tag => $self->{conn_tag},
382 channel => $args->{channel},
383 who => $args->{who},
384 address => $args->{address}
385 }
386 0 };
387 0 return;
388 }
389  
390 0 ▶sub pipe_input_handler ($self, $data, $pipetag, $rhandler) {
Subroutine pipe_input_handler: not called CC=4 SCAR=26.4
Pod undocumented
391 0 ▶ my $func = $rhandler =~ /::/ ? $rhandler : "Bot::BasicBot::Pluggable::$rhandler";
Branch: 1 branch
BranchTrueFalseTotal
$rhandler =~ /::/ ? : 0 0 0
392 0 my $args = $self->{forks}{$pipetag};
393 0 ▶ $args = $args->{args} if $args;
Branch: 1 branch
BranchTrueFalseTotal
if $args 0 0 0
394 0 local $self->{conn_tag} = $args->{conn_tag};
395 local $self->{server} = Irssi::server_find_tag($args->{conn_tag})
396 0 ▶ if $args->{conn_tag};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"conn_tag"} 0 0 0
397  
398 0 my @args;
399 0 $args[OBJECT] = $self;
400 0 $args[ARG0] = $data;
401 0 $args[ARG1] = $pipetag;
402 {
403 0 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.2
404 0 &$func(@args);
405 }
406  
407 0 delete $self->{forks}{$pipetag};
408 }
409  
410 0 ▶sub Bot::BasicBot::Pluggable::_fork_said {
Subroutine _fork_said: not called CC=1 SCAR=6.9
411 0 my ($bot, $body, $wheel_id) = @_[OBJECT, ARG0, ARG1];
412 0 chomp $body; # remove newline necessary to move data;
413  
414 # pick up the default arguments we squirreled away earlier
415 0 my $args = $bot->{forks}{$wheel_id}{args};
416 0 $args->{body} = $body;
417  
418 0 $bot->say($args);
419 0 return;
420 }
421  
422 1 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=11.1
423 1 my @dispatchable_events = (
424 qw/
425 connected chanjoin chanpart userquit nick_change
426 topic kicked raw_in raw_out
427 /
428 );
429 1 my @priority_events = (qw/ said emoted /);
430 {
431 ## no critic qw(ProhibitNoStrict)
432 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
433 1 for my $event (@dispatchable_events) {
434 0 ▶ *$event = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
435 0 shift->dispatch( $event, @_ );
436 9 };
437 }
438 1 for my $event (@priority_events) {
439 0 ▶ *$event = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
440 0 shift->dispatch_priorities( $event, @_ );
441 2 };
442 }
443 }
444 }
445  
446 0 ▶sub help ($self, $mess) {
Subroutine help: not called CC=3 SCAR=24.8
Pod undocumented
447 0 $mess->{body} =~ s/^help\s*//i;
448 0 my $logger = Irssi::Log::Log4perl->get_logger( ref $self );
449  
450 0 ▶ unless ( $mess->{body} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mess->{'body'}) { } 0 0 0
451 return
452 0 "Ask me for help about: "
453 . join( ", ", $self->modules() )
454 . " (say 'help <modulename>').";
455 }
456 else {
457 0 ▶ if ( my $module = $self->module( $mess->{body} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $module = $self->module($mess->{'body'})) { } 0 0 0
458 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
459 0 return $module->help($mess);
460 }
461 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
462 0 $logger->warn(
463 "Error calling help for module $mess->{body}: $_");
464 }
465 0 }
466 else {
467 0 return "I don't know anything about '$mess->{body}'.";
468 }
469 }
470 }
471  
472 0 ▶sub pocoirc ($self, $network = undef) {
Subroutine pocoirc: not called CC=3 SCAR=24.8
Pod undocumented
473 0 ▶ return bless +{ bot => $self, irssi => $self->{irssi}, conn_tag => ($network // $self->{conn_tag}) }
Condition0%0/3
$network // $self->{"conn_tag"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$network // $self->{"conn_tag"}
$network $self->{"conn_tag"}
Truth table0%0/3
A // B
A= $networkB= $self->{"conn_tag"}
ABresult
1X1
011
000
474 => 'Irssi::Bot::BasicBot::Pluggable::PoCoIrc';
475 }
476  
477 0 ▶sub load ($self, $module) {
Subroutine load: not called CC=7 SCAR=37.9
Pod undocumented
478 0 my $logger = Irssi::Log::Log4perl->get_logger( ref $self );
479  
480 # it's safe to die here, mostly this call is eval'd.
481 0 ▶ $logger->logdie("Cannot load module without a name") unless $module;
Branch: 1 branch
BranchTrueFalseTotal
unless $module 0 0 0
482 0 ▶ $logger->logdie("Module $module already loaded") if $self->module($module);
Branch: 1 branch
BranchTrueFalseTotal
if $self->module($module) 0 0 0
483  
484 # This is possible a leeeetle bit evil.
485 0 $logger->info("Loading module $module");
486 0 my $filename = $module;
487 0 $filename =~ s{::}{/}g;
488 0 my $file = "Bot/BasicBot/Pluggable/Module/$filename.pm";
489 0 ▶ $file = "Irssi/Bot/BasicBot/Pluggable/Module/Auth.pm"
Branch: 1 branch
BranchTrueFalseTotal
if lc $module eq "auth" 0 0 0
490 if lc $module eq 'auth';
491 0 $logger->debug("Loading module $module from file $file");
492  
493 # force a reload of the file (in the event that we've already loaded it).
494 1 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
495 0 delete $INC{$file};
496  
497 0 ▶ try { require $file } catch { die "Can't load $module: $_"; };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
498  
499 # Ok, it's very evil. Don't bother me, I'm working.
500  
501 0 my $m = "Bot::BasicBot::Pluggable::Module::$module"->new(
502 Bot => $self,
503 );
504  
505 0 ▶ $logger->logdie("->new didn't return an object") unless ( $m and ref($m) );
Branch: 1 branch
BranchTrueFalseTotal
unless $m and ref $m 0 0 0
Condition0%0/3
$m and ref $m
!ll&&!rl&&r
000
MC/DC0%0/2
$m and ref $m
$m ref $m
Truth table0%0/3
A and B
A= $mB= ref $m
ABresult
0X0
100
111
506 0 ▶ $logger->logdie( ref($m) . " isn't a $module" )
Branch: 1 branch
BranchTrueFalseTotal
unless ref($m) =~ /\Q$module\E/ 0 0 0
507 unless ref($m) =~ /\Q$module/;
508  
509 0 $self->add_module( $m, $module );
510  
511 0 return $m;
512 }
513  
514 0 ▶sub reload ($self, $module) {
Subroutine reload: not called CC=3 SCAR=24.8
Pod undocumented
515 0 my $logger = Irssi::Log::Log4perl->get_logger( ref $self );
516 0 ▶ $logger->logdie("Cannot reload module without a name") unless $module;
Branch: 1 branch
BranchTrueFalseTotal
unless $module 0 0 0
517 0 ▶ $self->remove_module($module) if $self->module($module);
Branch: 1 branch
BranchTrueFalseTotal
if $self->module($module) 0 0 0
518 0 return $self->load($module);
519 }
520  
521 0 ▶sub unload ($self, $module) {
Subroutine unload: not called CC=3 SCAR=24.8
Pod undocumented
522 0 my $logger = Irssi::Log::Log4perl->get_logger( ref $self );
523 0 ▶ $logger->logdie("Need name") unless $module;
Branch: 1 branch
BranchTrueFalseTotal
unless $module 0 0 0
524 0 ▶ $logger->logdie("Not loaded") unless $self->module($module);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->module($module) 0 0 0
525 0 $logger->info("Unloading module $module");
526 0 $self->remove_module($module);
527 }
528  
529 0 ▶sub store ($self) {
Subroutine store: not called CC=1 SCAR=6.9
Pod undocumented
530 0 return $self->{store};
531 }
532  
533 0 ▶sub module ($self, $name) {
Subroutine module: not called CC=1 SCAR=6.9
Pod documented
534 0 return $self->{modules}{ lc($name) };
535 }
536  
537 0 ▶sub modules ($self) {
Subroutine modules: not called CC=7 SCAR=40.3
Pod documented
538 my @keys = sort {
539 0 my $xa = $self->module($a);
540 0 my $xb = $self->module($b);
541 (
542 0 ▶ ($xb->get('user_priority') || $xb->get('priority') || 0)
Condition0%0/13
($xb->get('user_priority') || $xb->get('priority') || 0) <=> ($xa->get('user_priority') || $xa->get('priority') || 0) || $a cmp $b
l!l&&r!l&&!r
000
$xb->get('user_priority') || $xb->get('priority') || 0
l!l
00
$xb->get("user_priority") or $xb->get("priority")
l!l&&r!l&&!r
000
$xa->get('user_priority') || $xa->get('priority') || 0
l!l
00
$xa->get("user_priority") or $xa->get("priority")
l!l&&r!l&&!r
000
MC/DC0%0/3
($xb->get('user_priority') || $xb->get('priority') || 0) <=> ($xa->get('user_priority') || $xa->get('priority') || 0) || $a cmp $b
$xb->get("user_priority") $xb->get("priority") $a cmp $b
MC/DC0%0/2
$xa->get('user_priority') || $xa->get('priority') || 0
$xa->get("user_priority") $xa->get("priority")
Truth table0%0/4
A or B || C
A= $xb->get("user_priority")B= $xb->get("priority")C= $a cmp $b
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/3
A or B
A= $xa->get("user_priority")B= $xa->get("priority")
ABresult
1X1
011
000
543 <=>
544 ($xa->get('user_priority') || $xa->get('priority') || 0)
545 ) || ($a cmp $b)
546 0 } keys( %{ $self->{modules} } );
547 0 ▶ return @keys if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
548 0 return \@keys;
549 }
550  
551 # deprecated
552 0 ▶sub handlers ($self) { $self->modules }
Subroutine handlers: not called CC=1 SCAR=6.9
Pod undocumented
553  
554 0 ▶sub add_module ($self, $module, $name) {
Subroutine add_module: not called CC=3 SCAR=24.8
Pod undocumented
555 0 my $logger = Irssi::Log::Log4perl->get_logger( ref $self );
556 0 ▶ $logger->logdie("Need a name for adding a module") unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 0 0
557 $logger->logdie("Can't load a module with a duplicate name $name")
558 0 ▶ if $self->{modules}{ lc($name) };
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"modules"}{lc $name} 0 0 0
559 0 $self->{modules}{ lc($name) } = $module;
560 }
561  
562 0 ▶sub remove_module ($self, $name) {
Subroutine remove_module: not called CC=3 SCAR=24.8
Pod undocumented
563 0 my $logger = Irssi::Log::Log4perl->get_logger( ref $self );
564 0 ▶ $logger->logdie("Need a name for removing a module") unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 0 0
565 $logger->logdie("Module $name not defined")
566 0 ▶ unless $self->{modules}{ lc($name) };
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"modules"}{lc $name} 0 0 0
567 0 $self->{modules}{ lc($name) }->stop();
568 0 delete $self->{modules}{ lc($name) };
569 }
570  
571 0 ▶sub stop ($self) {
Subroutine stop: not called CC=2 SCAR=17.9
Pod undocumented
572 0 for my $module (reverse $self->modules) {
573 0 $self->remove_module($module);
574 }
575 0 return;
576 }
577  
578 0 ▶sub DUMMY { 1 }
Subroutine DUMMY: not called CC=1 SCAR=6.9
Pod undocumented
579  
580 1 1;
581  
582 package Irssi::Bot::BasicBot::Pluggable::PoCoIrc;
583 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
584 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
585 1 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
586  
587 0 ▶sub is_channel_member ($self, $channel, $nick) {
Subroutine is_channel_member: not called CC=5 SCAR=34.0
588 0 ▶ return 0 unless $self->{conn_tag};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"conn_tag"} 0 0 0
589 my $server = Irssi::server_find_tag($self->{conn_tag})
590 0 ▶ or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $server = Irssi::server_find_tag($self->{"conn_tag"}) or return 0 0 0 0
591 0 ▶ my $ch = $server->channel_find($channel)
Branch: 1 branch
BranchTrueFalseTotal
my $ch = $server->channel_find($channel) or return 0 0 0 0
592 or return 0;
593 0 ▶ my $n = $ch->nick_find($nick)
Branch: 1 branch
BranchTrueFalseTotal
my $n = $ch->nick_find($nick) or return 0 0 0 0
594 or return 0;
595 0 return 1;
596 }
597  
598 0 ▶sub channel_list ($self, $channel) {
Subroutine channel_list: not called CC=4 SCAR=30.0
599 warn "connection lost: $channel",
600 0 ▶ return () unless $self->{conn_tag};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"conn_tag"} 0 0 0
601 my $server = Irssi::server_find_tag($self->{conn_tag})
602 0 ▶ or warn "connection lost: $self->{conn_tag}", return ();
Branch: 1 branch
BranchTrueFalseTotal
my $server = Irssi::server_find_tag($self->{"conn_tag"}) or warn qq[connection lost: $self->{"conn_tag"}], (return ()) 0 0 0
603 0 ▶ my $ch = $server->channel_find($channel)
Branch: 1 branch
BranchTrueFalseTotal
my $ch = $server->channel_find($channel) or return () 0 0 0
604 or return ();
605 0 return map { $_->{nick} } $ch->nicks;
606 }
607  
608 0 ▶sub DUMMY { 1 }
Subroutine DUMMY: not called CC=1 SCAR=6.9
609  
610 1 1;
↑ Summary Log/Log4perl.pm »