Component/IRC/State.pm

filter: Statementstmt 76.5% 618 / 807 Branchbran 59.0% 177 / 300 Conditioncond 50.0% 70 / 140 MC/DCmcdc 26.4% 23 / 87 Subroutinesub 80.2% 57 / 71 Podpod 49.1% 29 / 59 totaltotal 66.5% 974 / 1464 CC 214 SCAR 26.2
CC
214
Cov
69%
S_mode
47.7
channel_modes
30.0
S_352
20.9
CRAP 13.7
« Component/IRC/Plugin/Console.pm ↑ Summary Component/IRC/Plugin/Proxy.pm »
1 package POE::Component::IRC::State;
2 21 $POE::Component::IRC::State::VERSION = '6.95';
3 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 21 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 21 ▶use IRC::Utils qw(uc_irc parse_mode_line normalize_mask);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 21 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 21 ▶use POE::Component::IRC::Plugin qw(PCI_EAT_NONE);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 21 ▶use base qw(POE::Component::IRC);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # Event handlers for tracking the STATE. $self->{STATE} is used as our
11 # namespace. uc_irc() is used to create unique keys.
12  
13 # RPL_WELCOME
14 # Make sure we have a clean STATE when we first join the network and if we
15 # inadvertently get disconnected.
16 28 ▶sub S_001 {
Subroutine S_001: called CC=1 SCAR=0.0
Pod undocumented
17 28 my $self = shift;
18 28 $self->SUPER::S_001(@_);
19 28 shift @_;
20  
21 28 delete $self->{STATE};
22 28 delete $self->{NETSPLIT};
23 28 $self->{STATE}{usermode} = '';
24 28 $self->yield(mode => $self->nick_name());
25 28 return PCI_EAT_NONE;
26 }
27  
28 28 ▶sub S_disconnected {
Subroutine S_disconnected: called CC=2 SCAR=6.9
Pod undocumented
29 28 my $self = shift;
30 28 $self->SUPER::S_disconnected(@_);
31 28 shift @_;
32  
33 28 my $nickinfo = $self->nick_info($self->nick_name());
34 28 ▶ $nickinfo = {} if !defined $nickinfo;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $nickinfo 4 24 28
35 28 my $channels = $self->channels();
36 28 push @{ $_[-1] }, $nickinfo, $channels;
37 28 return PCI_EAT_NONE;
38 }
39  
40 26 ▶sub S_error {
Subroutine S_error: called CC=2 SCAR=6.9
Pod undocumented
41 26 my $self = shift;
42 26 $self->SUPER::S_error(@_);
43 26 shift @_;
44  
45 26 my $nickinfo = $self->nick_info($self->nick_name());
46 26 ▶ $nickinfo = {} if !defined $nickinfo;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $nickinfo 4 22 26
47 26 my $channels = $self->channels();
48 26 push @{ $_[-1] }, $nickinfo, $channels;
49 26 return PCI_EAT_NONE;
50 }
51  
52 0 ▶sub S_socketerr {
Subroutine S_socketerr: not called CC=2 SCAR=17.9
Pod undocumented
53 0 my ($self, undef) = splice @_, 0, 2;
54 0 my $nickinfo = $self->nick_info($self->nick_name());
55 0 ▶ $nickinfo = {} if !defined $nickinfo;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $nickinfo 0 0 0
56 0 my $channels = $self->channels();
57 0 push @{ $_[-1] }, $nickinfo, $channels;
58 0 return PCI_EAT_NONE;
59 }
60  
61 53 ▶sub S_join {
Subroutine S_join: called CC=10 SCAR=23.5
Pod undocumented
62 53 my ($self, undef) = splice @_, 0, 2;
63 53 my ($nick, $user, $host) = split /[!@]/, ${ $_[0] };
64 53 my $map = $self->isupport('CASEMAPPING');
65 53 my $chan = ${ $_[1] };
66 53 my $uchan = uc_irc($chan, $map);
67 53 my $unick = uc_irc($nick, $map);
68  
69 53 ▶ if ($unick eq uc_irc($self->nick_name(), $map)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unick eq uc_irc($self->nick_name, $map)) { } 34 19 53
70 34 delete $self->{STATE}{Chans}{ $uchan };
71 34 $self->{CHANNEL_SYNCH}{ $uchan } = {
72 MODE => 0,
73 WHO => 0,
74 BAN => 0,
75 _time => time(),
76 };
77 34 $self->{STATE}{Chans}{ $uchan } = {
78 Name => $chan,
79 Mode => ''
80 };
81  
82 # fake a WHO sync if we're only interested in people's user@host
83 # and the server provides those in the NAMES reply
84 34 ▶ if (exists $self->{whojoiners} && !$self->{whojoiners}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'whojoiners'} and not $self->{'whojoiners'} and $self->isupport('UHNAMES')) { } 0 34 34
Condition33%2/6
exists $self->{"whojoiners"} and not $self->{"whojoiners"} and $self->isupport("UHNAMES")
!ll&&!rl&&r
3400
exists $self->{"whojoiners"} and not $self->{"whojoiners"}
!ll&&!rl&&r
3400
MC/DC0%0/3
exists $self->{"whojoiners"} and not $self->{"whojoiners"} and $self->isupport("UHNAMES")
exists $self->{"whojoiners"} not $self->{"whojoiners"} $self->isupport("UHNAMES")
Truth table25%1/4
A and not(B) and C
A= exists $self->{"whojoiners"}B= not $self->{"whojoiners"}C= $self->isupport("UHNAMES")
ABCresult
0XX0
10X0
1100
1111
85 && $self->isupport('UHNAMES')) {
86 0 $self->_channel_sync($chan, 'WHO');
87 }
88 else {
89 34 $self->yield(who => $chan);
90 }
91 34 $self->yield(mode => $chan);
92 34 $self->yield(mode => $chan => 'b');
93 }
94 else {
95 SWITCH: {
96 19 my $netsplit = "$unick!$user\@$host";
97 19 ▶ if ( exists $self->{NETSPLIT}{Users}{ $netsplit } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"NETSPLIT"}{"Users"}{$netsplit}) 1 18 19
98 # restore state from NETSPLIT if it hasn't expired.
99 1 my $nuser = delete $self->{NETSPLIT}{Users}{ $netsplit };
100 1 ▶ if ( ( time - $nuser->{stamp} ) < ( 60 * 60 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (time - $nuser->{"stamp"} < 3600) 1 0 1
101 1 $self->{STATE}{Nicks}{ $unick } = $nuser->{meta};
102 1 $self->send_event_next(irc_nick_sync => $nick, $chan);
103 1 last SWITCH;
104 }
105 }
106 18 ▶ if ( (!exists $self->{whojoiners} || $self->{whojoiners})
Branch: 1 branch
BranchTrueFalseTotal
if (!exists $self->{'whojoiners'} || $self->{'whojoiners'} and not exists $self->{'STATE'}{'Nicks'}{$unick}{'Real'}) { } 15 3 18
Condition50%3/6
!exists $self->{"whojoiners"} || $self->{"whojoiners"} and not exists $self->{"STATE"}{"Nicks"}{$unick}{"Real"}
!ll&&!rl&&r
0315
not exists $self->{"whojoiners"} or $self->{"whojoiners"}
l!l&&r!l&&!r
1800
MC/DC33%1/3
!exists $self->{"whojoiners"} || $self->{"whojoiners"} and not exists $self->{"STATE"}{"Nicks"}{$unick}{"Real"}
not exists $self->{"whojoiners"} $self->{"whojoiners"} not exists $self->{"STATE"}{"Nicks"}{$unick}{"Real"}
Truth table40%2/5
not(A) or B and not(C)
A= not exists $self->{"whojoiners"}B= $self->{"whojoiners"}C= not exists $self->{"STATE"}{"Nicks"}{$unick}{"Real"}
ABCresult
00X0
1X00
0100
1X11
0111
107 && !exists $self->{STATE}{Nicks}{ $unick }{Real}) {
108 15 $self->yield(who => $nick);
109 15 push @{ $self->{NICK_SYNCH}{ $unick } }, $chan;
110 }
111 else {
112 # Fake 'irc_nick_sync'
113 3 $self->send_event_next(irc_nick_sync => $nick, $chan);
114 }
115 }
116 }
117  
118 53 $self->{STATE}{Nicks}{ $unick }{Nick} = $nick;
119 53 $self->{STATE}{Nicks}{ $unick }{User} = $user;
120 53 $self->{STATE}{Nicks}{ $unick }{Host} = $host;
121 53 $self->{STATE}{Nicks}{ $unick }{CHANS}{ $uchan } = '';
122 53 $self->{STATE}{Chans}{ $uchan }{Nicks}{ $unick } = '';
123  
124 53 return PCI_EAT_NONE;
125 }
126  
127 33 ▶sub S_chan_sync {
Subroutine S_chan_sync: called CC=2 SCAR=6.9
Pod undocumented
128 33 my ($self, undef) = splice @_, 0, 2;
129 33 my $chan = ${ $_[0] };
130  
131 33 ▶ if ($self->{awaypoll}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"awaypoll"}) 2 31 33
132 2 $poe_kernel->state(_away_sync => $self);
133 2 $poe_kernel->delay_add(_away_sync => $self->{awaypoll} => $chan);
134 }
135  
136 33 return PCI_EAT_NONE;
137 }
138  
139 5 ▶sub S_part {
Subroutine S_part: called CC=5 SCAR=16.1
Pod undocumented
140 5 my ($self, undef) = splice @_, 0, 2;
141 5 my $map = $self->isupport('CASEMAPPING');
142 5 my $nick = uc_irc((split /!/, ${ $_[0] } )[0], $map);
143 5 my $uchan = uc_irc(${ $_[1] }, $map);
144  
145 5 ▶ if ($nick eq uc_irc($self->nick_name(), $map)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nick eq uc_irc($self->nick_name, $map)) { } 3 2 5
146 3 delete $self->{STATE}{Nicks}{ $nick }{CHANS}{ $uchan };
147 3 delete $self->{STATE}{Chans}{ $uchan }{Nicks}{ $nick };
148  
149 3 for my $member ( keys %{ $self->{STATE}{Chans}{ $uchan }{Nicks} } ) {
150 2 delete $self->{STATE}{Nicks}{ $member }{CHANS}{ $uchan };
151 2 ▶ if ( keys %{ $self->{STATE}{Nicks}{ $member }{CHANS} } <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$$self{"STATE"}{"Nicks"}{$member}{"CHANS"};} <= 0) 2 0 2
152 2 delete $self->{STATE}{Nicks}{ $member };
153 }
154 }
155  
156 3 delete $self->{STATE}{Chans}{ $uchan };
157 }
158 else {
159 2 delete $self->{STATE}{Nicks}{ $nick }{CHANS}{ $uchan };
160 2 delete $self->{STATE}{Chans}{ $uchan }{Nicks}{ $nick };
161 2 ▶ if ( !keys %{ $self->{STATE}{Nicks}{ $nick }{CHANS} } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (keys %{$$self{"STATE"}{"Nicks"}{$nick}{"CHANS"};}) 2 0 2
162 2 delete $self->{STATE}{Nicks}{ $nick };
163 }
164 }
165  
166 5 return PCI_EAT_NONE;
167 }
168  
169 5 ▶sub S_quit {
Subroutine S_quit: called CC=5 SCAR=16.1
Pod undocumented
170 5 my ($self, undef) = splice @_, 0, 2;
171 5 my $map = $self->isupport('CASEMAPPING');
172 5 my $nick = (split /!/, ${ $_[0] })[0];
173 5 my $msg = ${ $_[1] };
174 5 my $unick = uc_irc($nick, $map);
175 5 my $netsplit = 0;
176  
177 5 push @{ $_[-1] }, [ $self->nick_channels( $nick ) ];
178  
179 # Check if it is a netsplit
180 5 ▶ $netsplit = 1 if _is_netsplit( $msg );
Branch: 1 branch
BranchTrueFalseTotal
if _is_netsplit($msg) 1 4 5
181  
182 5 ▶ if ($unick ne uc_irc($self->nick_name(), $map)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unick ne uc_irc($self->nick_name, $map)) 5 0 5
183 5 for my $uchan ( keys %{ $self->{STATE}{Nicks}{ $unick }{CHANS} } ) {
184 6 delete $self->{STATE}{Chans}{ $uchan }{Nicks}{ $unick };
185 # No don't stash the channel state.
186 #$self->{NETSPLIT}{Chans}{ $uchan }{NICKS}{ $unick } = $chanstate
187 # if $netsplit;
188 }
189  
190 5 my $nickstate = delete $self->{STATE}{Nicks}{ $unick };
191 5 ▶ if ( $netsplit ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($netsplit) 1 4 5
192 1 delete $nickstate->{CHANS};
193 1 $self->{NETSPLIT}{Users}{ "$unick!" . join '@', @{$nickstate}{qw(User Host)} } =
194 { meta => $nickstate, stamp => time };
195 }
196 }
197  
198 5 return PCI_EAT_NONE;
199 }
200  
201 5 ▶sub _is_netsplit {
Subroutine _is_netsplit: called CC=3 SCAR=11.1
202 5 ▶ my $msg = shift || return;
Condition50%1/2
shift() || (return)
l!l
50
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
203 5 ▶ return 1 if $msg =~ /^\s*\S+\.[a-z]{2,} \S+\.[a-z]{2,}$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $msg =~ /^\s*\S+\.[a-z]{2,} \S+\.[a-z]{2,}$/i 1 4 5
204 4 return 0;
205 }
206  
207 8 ▶sub S_kick {
Subroutine S_kick: called CC=5 SCAR=16.1
Pod undocumented
208 8 my ($self, undef) = splice @_, 0, 2;
209 8 my $chan = ${ $_[1] };
210 8 my $nick = ${ $_[2] };
211 8 my $map = $self->isupport('CASEMAPPING');
212 8 my $unick = uc_irc($nick, $map);
213 8 my $uchan = uc_irc($chan, $map);
214  
215 8 push @{ $_[-1] }, $self->nick_long_form( $nick );
216  
217 8 ▶ if ( $unick eq uc_irc($self->nick_name(), $map)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unick eq uc_irc($self->nick_name, $map)) { } 4 4 8
218 4 delete $self->{STATE}{Nicks}{ $unick }{CHANS}{ $uchan };
219 4 delete $self->{STATE}{Chans}{ $uchan }{Nicks}{ $unick };
220  
221 4 for my $member ( keys %{ $self->{STATE}{Chans}{ $uchan }{Nicks} } ) {
222 4 delete $self->{STATE}{Nicks}{ $member }{CHANS}{ $uchan };
223 4 ▶ if ( keys %{ $self->{STATE}{Nicks}{ $member }{CHANS} } <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$$self{"STATE"}{"Nicks"}{$member}{"CHANS"};} <= 0) 3 1 4
224 3 delete $self->{STATE}{Nicks}{ $member };
225 }
226 }
227  
228 4 delete $self->{STATE}{Chans}{ $uchan };
229 }
230 else {
231 4 delete $self->{STATE}{Nicks}{ $unick }{CHANS}{ $uchan };
232 4 delete $self->{STATE}{Chans}{ $uchan }{Nicks}{ $unick };
233 4 ▶ if ( keys %{ $self->{STATE}{Nicks}{ $unick }{CHANS} } <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$$self{"STATE"}{"Nicks"}{$unick}{"CHANS"};} <= 0) 3 1 4
234 3 delete $self->{STATE}{Nicks}{ $unick };
235 }
236 }
237  
238 8 return PCI_EAT_NONE;
239 }
240  
241 2 ▶sub S_nick {
Subroutine S_nick: called CC=3 SCAR=11.0
Pod undocumented
242 2 my $self = shift;
243 2 $self->SUPER::S_nick(@_);
244 2 shift @_;
245  
246 2 my $nick = (split /!/, ${ $_[0] })[0];
247 2 my $new = ${ $_[1] };
248 2 my $map = $self->isupport('CASEMAPPING');
249 2 my $unick = uc_irc($nick, $map);
250 2 my $unew = uc_irc($new, $map);
251  
252 2 push @{ $_[-1] }, [ $self->nick_channels( $nick ) ];
253  
254 2 ▶ if ($unick eq $unew) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unick eq $unew) { } 0 2 2
255 # Case Change
256 0 $self->{STATE}{Nicks}{ $unick }{Nick} = $new;
257 }
258 else {
259 2 my $user = delete $self->{STATE}{Nicks}{ $unick };
260 2 $user->{Nick} = $new;
261  
262 2 for my $channel ( keys %{ $user->{CHANS} } ) {
263 2 $self->{STATE}{Chans}{ $channel }{Nicks}{ $unew } = $user->{CHANS}{ $channel };
264 2 delete $self->{STATE}{Chans}{ $channel }{Nicks}{ $unick };
265 }
266  
267 2 $self->{STATE}{Nicks}{ $unew } = $user;
268 }
269  
270 2 return PCI_EAT_NONE;
271 }
272  
273 64 ▶sub S_chan_mode {
Subroutine S_chan_mode: called CC=6 SCAR=17.9
Pod undocumented
274 64 my ($self, undef) = splice @_, 0, 2;
275 64 pop @_;
276 64 my $who = ${ $_[0] };
277 64 my $chan = ${ $_[1] };
278 64 my $mode = ${ $_[2] };
279 64 ▶ my $arg = defined $_[3] ? ${ $_[3] } : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $_[3] ? : 26 38 64
280 64 my $map = $self->isupport('CASEMAPPING');
281 64 my $me = uc_irc($self->nick_name(), $map);
282  
283 64 ▶ return PCI_EAT_NONE if $mode !~ /\+[qoah]/ || $me ne uc_irc($arg, $map);
Branch: 1 branch
BranchTrueFalseTotal
if not $mode =~ /\+[qoah]/ or $me ne uc_irc($arg, $map) 63 1 64
Condition100%3/3
not $mode =~ /\+[qoah]/ or $me ne uc_irc($arg, $map)
l!l&&r!l&&!r
6121
MC/DC100%2/2
not $mode =~ /\+[qoah]/ or $me ne uc_irc($arg, $map)
not $mode =~ /\+[qoah]/ $me ne uc_irc($arg, $map)
Truth table100%3/3
not(A) or B
A= not $mode =~ /\+[qoah]/B= $me ne uc_irc($arg, $map)
ABresult
1X1
011
000
284  
285 1 my $excepts = $self->isupport('EXCEPTS');
286 1 my $invex = $self->isupport('INVEX');
287 1 ▶ $self->yield(mode => $chan, $excepts ) if $excepts;
Branch: 1 branch
BranchTrueFalseTotal
if $excepts 1 0 1
288 1 ▶ $self->yield(mode => $chan, $invex ) if $invex;
Branch: 1 branch
BranchTrueFalseTotal
if $invex 1 0 1
289  
290 1 return PCI_EAT_NONE;
291 }
292  
293 # RPL_UMODEIS
294 29 ▶sub S_221 {
Subroutine S_221: called CC=1 SCAR=0.0
Pod undocumented
295 29 my ($self, undef) = splice @_, 0, 2;
296 29 my $mode = ${ $_[1] };
297 29 $mode =~ s/^\+//;
298 29 $self->{STATE}->{usermode} = $mode;
299 29 return PCI_EAT_NONE;
300 }
301  
302 # RPL_CHANNEL_URL
303 0 ▶sub S_328 {
Subroutine S_328: not called CC=2 SCAR=17.9
Pod undocumented
304 0 my ($self, undef) = splice @_, 0, 2;
305 0 my ($chan, $url) = @{ ${ $_[2] } };
306 0 my $map = $self->isupport('CASEMAPPING');
307 0 my $uchan = uc_irc($chan, $map);
308  
309 0 ▶ return PCI_EAT_NONE if !$self->_channel_exists($chan);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_channel_exists($chan) 0 0 0
310 0 $self->{STATE}{Chans}{ $uchan }{Url} = $url;
311 0 return PCI_EAT_NONE;
312 }
313  
314 # RPL_UNAWAY
315 3 ▶sub S_305 {
Subroutine S_305: called CC=1 SCAR=0.0
Pod undocumented
316 3 my ($self, undef) = splice @_, 0, 2;
317 3 $self->{STATE}->{away} = 0;
318 3 return PCI_EAT_NONE;
319 }
320  
321 # RPL_NOWAWAY
322 3 ▶sub S_306 {
Subroutine S_306: called CC=1 SCAR=0.0
Pod undocumented
323 3 my ($self, undef) = splice @_, 0, 2;
324 3 $self->{STATE}->{away} = 1;
325 3 return PCI_EAT_NONE;
326 }
327  
328 # this code needs refactoring
329 ## no critic (Subroutines::ProhibitExcessComplexity ControlStructures::ProhibitCascadingIfElse)
330 77 ▶sub S_mode {
Subroutine S_mode: called CC=33 SCAR=38.6
Pod undocumented
331 77 my ($self, undef) = splice @_, 0, 2;
332 77 my $map = $self->isupport('CASEMAPPING');
333 77 my $who = ${ $_[0] };
334 77 my $chan = ${ $_[1] };
335 77 my $uchan = uc_irc($chan, $map);
336 77 pop @_;
337 77 my @modes = map { ${ $_ } } @_[2 .. $#_];
338  
339 # CHANMODES is [$list_mode, $always_arg, $arg_when_set, $no_arg]
340 # A $list_mode always has an argument
341 77 ▶ my $prefix = $self->isupport('PREFIX') || { o => '@', v => '+' };
Condition50%1/2
$self->isupport('PREFIX') || {'o', '@', 'v', '+'}
l!l
770
MC/DC0%0/1
$self->isupport('PREFIX') || {'o', '@', 'v', '+'}
$self->isupport('PREFIX')
Truth table50%1/2
A
A= $self->isupport('PREFIX')
Aresult
11
00
342 77 my $statmodes = join '', keys %{ $prefix };
343 77 ▶ my $chanmodes = $self->isupport('CHANMODES') || [ qw(beI k l imnpstaqr) ];
Condition50%1/2
$self->isupport('CHANMODES') || ['beI', 'k', 'l', 'imnpstaqr']
l!l
770
MC/DC0%0/1
$self->isupport('CHANMODES') || ['beI', 'k', 'l', 'imnpstaqr']
$self->isupport('CHANMODES')
Truth table50%1/2
A
A= $self->isupport('CHANMODES')
Aresult
11
00
344 77 my $alwaysarg = join '', $statmodes, @{ $chanmodes }[0 .. 1];
345  
346 # Do nothing if it is UMODE
347 77 ▶ if ($uchan ne uc_irc($self->nick_name(), $map)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uchan ne uc_irc($self->nick_name, $map)) { } 49 28 77
348 49 my $parsed_mode = parse_mode_line( $prefix, $chanmodes, @modes );
349 49 for my $mode (@{ $parsed_mode->{modes} }) {
350 64 my $orig_arg;
351 64 ▶ if (length $chanmodes->[2] && length $alwaysarg && $mode =~ /^(.[$alwaysarg]|\+[$chanmodes->[2]])/) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $chanmodes->[2] and length $alwaysarg and $mode =~ /^(.[$alwaysarg]|\+[$chanmodes->[2]])/) 26 38 64
Condition50%3/6
length $chanmodes->[2] and length $alwaysarg and $mode =~ /^(.[$alwaysarg]|\+[$chanmodes->[2]])/
!ll&&!rl&&r
03826
length $chanmodes->[2] and length $alwaysarg
!ll&&!rl&&r
0064
MC/DC33%1/3
length $chanmodes->[2] and length $alwaysarg and $mode =~ /^(.[$alwaysarg]|\+[$chanmodes->[2]])/
length $chanmodes->[2] length $alwaysarg $mode =~ /^(.[$alwaysarg]|\+[$chanmodes->[2]])/
Truth table50%2/4
A and B and C
A= length $chanmodes->[2]B= length $alwaysargC= $mode =~ /^(.[$alwaysarg]|\+[$chanmodes->[2]])/
ABCresult
0XX0
10X0
1100
1111
352 26 $orig_arg = shift @{ $parsed_mode->{args} };
353 }
354  
355 64 my $flag;
356 64 my $arg = $orig_arg;
357  
358 64 ▶ if (length $statmodes && (($flag) = $mode =~ /\+([$statmodes])/)) {
Branch: 8 branches
BranchTrueFalseTotal
if (length $statmodes and ($flag) = $mode =~ /\+([$statmodes])/) { } 3 61 64
elsif (length $statmodes and ($flag) = $mode =~ /-([$statmodes])/) { } 0 61 61
elsif (length $chanmodes->[0] and ($flag) = $mode =~ /\+([$chanmodes->[0]])/) { } 5 56 61
elsif (length $chanmodes->[0] and ($flag) = $mode =~ /-([$chanmodes->[0]])/) { } 4 52 56
elsif (length $chanmodes->[3] and ($flag) = $mode =~ /\+([^$chanmodes->[3]])/) { } 12 40 52
elsif (length $chanmodes->[3] and ($flag) = $mode =~ /-([^$chanmodes->[3]])/) { } 4 36 40
elsif (($flag) = $mode =~ /^\+(.)/) { } 34 2 36
elsif (($flag) = $mode =~ /^-(.)/) { } 2 0 2
Condition66%2/3
length $statmodes and ($flag) = $mode =~ /\+([$statmodes])/
!ll&&!rl&&r
0613
MC/DC50%1/2
length $statmodes and ($flag) = $mode =~ /\+([$statmodes])/
length $statmodes ($flag) = $mode =~ /\+([$statmodes])/
Truth table66%2/3
A and B
A= length $statmodesB= ($flag) = $mode =~ /\+([$statmodes])/
ABresult
0X0
100
111
359 3 $arg = uc_irc($arg, $map);
360 3 ▶ if (!$self->{STATE}{Nicks}{ $arg }{CHANS}{ $uchan } || $self->{STATE}{Nicks}{ $arg }{CHANS}{ $uchan } !~ /$flag/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"STATE"}{"Nicks"}{$arg}{"CHANS"}{$uchan} and $self->{"STATE"}{"Nicks"}{$arg}{"CHANS"}{$uchan} =~ /$flag/) 3 0 3
Condition33%1/3
$self->{"STATE"}{"Nicks"}{$arg}{"CHANS"}{$uchan} and $self->{"STATE"}{"Nicks"}{$arg}{"CHANS"}{$uchan} =~ /$flag/
!ll&&!rl&&r
300
MC/DC0%0/2
$self->{"STATE"}{"Nicks"}{$arg}{"CHANS"}{$uchan} and $self->{"STATE"}{"Nicks"}{$arg}{"CHANS"}{$uchan} =~ /$flag/
$self->{"STATE"}{"Nicks"}{$arg}{"CHANS"}{$uchan} $self->{"STATE"}{"Nicks"}{$arg}{"CHANS"}{$uchan} =~ /$flag/
Truth table33%1/3
A and B
A= $self->{"STATE"}{"Nicks"}{$arg}{"CHANS"}{$uchan}B= $self->{"STATE"}{"Nicks"}{$arg}{"CHANS"}{$uchan} =~ /$flag/
ABresult
0X0
100
111
361 3 $self->{STATE}{Nicks}{ $arg }{CHANS}{ $uchan } .= $flag;
362 3 $self->{STATE}{Chans}{ $uchan }{Nicks}{ $arg } = $self->{STATE}{Nicks}{ $arg }{CHANS}{ $uchan };
363 }
364 }
365 ▶ elsif (length $statmodes && (($flag) = $mode =~ /-([$statmodes])/)) {
Condition33%1/3
length $statmodes and ($flag) = $mode =~ /-([$statmodes])/
!ll&&!rl&&r
0610
MC/DC0%0/2
length $statmodes and ($flag) = $mode =~ /-([$statmodes])/
length $statmodes ($flag) = $mode =~ /-([$statmodes])/
Truth table33%1/3
A and B
A= length $statmodesB= ($flag) = $mode =~ /-([$statmodes])/
ABresult
0X0
100
111
366 0 $arg = uc_irc($arg, $map);
367 0 ▶ if ($self->{STATE}{Nicks}{ $arg }{CHANS}{ $uchan } =~ /$flag/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"STATE"}{"Nicks"}{$arg}{"CHANS"}{$uchan} =~ /$flag/) 0 0 0
368 0 $self->{STATE}{Nicks}{ $arg }{CHANS}{ $uchan } =~ s/$flag//;
369 0 $self->{STATE}{Chans}{ $uchan }{Nicks}{ $arg } = $self->{STATE}{Nicks}{ $arg }{CHANS}{ $uchan };
370 }
371 }
372 ▶ elsif (length $chanmodes->[0] && (($flag) = $mode =~ /\+([$chanmodes->[0]])/)) {
Condition66%2/3
length $chanmodes->[0] and ($flag) = $mode =~ /\+([$chanmodes->[0]])/
!ll&&!rl&&r
0565
MC/DC50%1/2
length $chanmodes->[0] and ($flag) = $mode =~ /\+([$chanmodes->[0]])/
length $chanmodes->[0] ($flag) = $mode =~ /\+([$chanmodes->[0]])/
Truth table66%2/3
A and B
A= length $chanmodes->[0]B= ($flag) = $mode =~ /\+([$chanmodes->[0]])/
ABresult
0X0
100
111
373 5 $self->{STATE}{Chans}{ $uchan }{Lists}{ $flag }{ $arg } = {
374 SetBy => $who,
375 SetAt => time(),
376 };
377 }
378 ▶ elsif (length $chanmodes->[0] && (($flag) = $mode =~ /-([$chanmodes->[0]])/)) {
Condition66%2/3
length $chanmodes->[0] and ($flag) = $mode =~ /-([$chanmodes->[0]])/
!ll&&!rl&&r
0524
MC/DC50%1/2
length $chanmodes->[0] and ($flag) = $mode =~ /-([$chanmodes->[0]])/
length $chanmodes->[0] ($flag) = $mode =~ /-([$chanmodes->[0]])/
Truth table66%2/3
A and B
A= length $chanmodes->[0]B= ($flag) = $mode =~ /-([$chanmodes->[0]])/
ABresult
0X0
100
111
379 4 delete $self->{STATE}{Chans}{ $uchan }{Lists}{ $flag }{ $arg };
380 }
381  
382 # All unhandled modes with arguments
383 ▶ elsif (length $chanmodes->[3] && (($flag) = $mode =~ /\+([^$chanmodes->[3]])/)) {
Condition66%2/3
length $chanmodes->[3] and ($flag) = $mode =~ /\+([^$chanmodes->[3]])/
!ll&&!rl&&r
04012
MC/DC50%1/2
length $chanmodes->[3] and ($flag) = $mode =~ /\+([^$chanmodes->[3]])/
length $chanmodes->[3] ($flag) = $mode =~ /\+([^$chanmodes->[3]])/
Truth table66%2/3
A and B
A= length $chanmodes->[3]B= ($flag) = $mode =~ /\+([^$chanmodes->[3]])/
ABresult
0X0
100
111
384 12 ▶ $self->{STATE}{Chans}{ $uchan }{Mode} .= $flag if $self->{STATE}{Chans}{ $uchan }{Mode} !~ /$flag/;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"STATE"}{"Chans"}{$uchan}{"Mode"} =~ /$flag/ 10 2 12
385 12 $self->{STATE}{Chans}{ $uchan }{ModeArgs}{ $flag } = $arg;
386 }
387 ▶ elsif (length $chanmodes->[3] && (($flag) = $mode =~ /-([^$chanmodes->[3]])/)) {
Condition66%2/3
length $chanmodes->[3] and ($flag) = $mode =~ /-([^$chanmodes->[3]])/
!ll&&!rl&&r
0364
MC/DC50%1/2
length $chanmodes->[3] and ($flag) = $mode =~ /-([^$chanmodes->[3]])/
length $chanmodes->[3] ($flag) = $mode =~ /-([^$chanmodes->[3]])/
Truth table66%2/3
A and B
A= length $chanmodes->[3]B= ($flag) = $mode =~ /-([^$chanmodes->[3]])/
ABresult
0X0
100
111
388 4 $self->{STATE}{Chans}{ $uchan }{Mode} =~ s/$flag//;
389 4 delete $self->{STATE}{Chans}{ $uchan }{ModeArgs}{ $flag };
390 }
391  
392 # Anything else doesn't have arguments so just adjust {Mode} as necessary.
393 elsif (($flag) = $mode =~ /^\+(.)/ ) {
394 34 ▶ $self->{STATE}{Chans}{ $uchan }{Mode} .= $flag if $self->{STATE}{Chans}{ $uchan }{Mode} !~ /$flag/;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"STATE"}{"Chans"}{$uchan}{"Mode"} =~ /$flag/ 34 0 34
395 }
396 elsif (($flag) = $mode =~ /^-(.)/ ) {
397 2 $self->{STATE}{Chans}{ $uchan }{Mode} =~ s/$flag//;
398 }
399 64 ▶ $self->send_event_next(irc_chan_mode => $who, $chan, $mode, (defined $orig_arg ? $orig_arg : ()));
Branch: 1 branch
BranchTrueFalseTotal
defined $orig_arg ? : 26 38 64
400 }
401  
402 # Lets make the channel mode nice
403 49 ▶ if ( $self->{STATE}{Chans}{ $uchan }{Mode} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"STATE"}{"Chans"}{$uchan}{"Mode"}) 49 0 49
404 49 $self->{STATE}{Chans}{ $uchan }{Mode} = join('', sort {uc $a cmp uc $b} ( split( //, $self->{STATE}{Chans}{ $uchan }{Mode} ) ) );
405 }
406 }
407 else {
408 28 my $parsed_mode = parse_mode_line( @modes );
409 28 for my $mode (@{ $parsed_mode->{modes} }) {
410 28 my $flag;
411 28 ▶ if ( ($flag) = $mode =~ /^\+(.)/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if (($flag) = $mode =~ /^\+(.)/) { } 28 0 28
elsif (($flag) = $mode =~ /^-(.)/) { } 0 0 0
412 28 ▶ $self->{STATE}{usermode} .= $flag if $self->{STATE}{usermode} !~ /$flag/;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"STATE"}{"usermode"} =~ /$flag/ 28 0 28
413 }
414 elsif ( ($flag) = $mode =~ /^-(.)/ ) {
415 0 $self->{STATE}{usermode} =~ s/$flag//;
416 }
417 28 $self->send_event_next(irc_user_mode => $who, $chan, $mode );
418 }
419 }
420  
421 77 return PCI_EAT_NONE;
422 }
423  
424 5 ▶sub S_topic {
Subroutine S_topic: called CC=1 SCAR=0.0
Pod undocumented
425 5 my ($self, undef) = splice @_, 0, 2;
426 5 my $who = ${ $_[0] };
427 5 my $chan = ${ $_[1] };
428 5 my $topic = ${ $_[2] };
429 5 my $map = $self->isupport('CASEMAPPING');
430 5 my $uchan = uc_irc($chan, $map);
431 5 push @{ $_[-1] }, $self->{STATE}{Chans}{$uchan}{Topic};
432  
433 $self->{STATE}{Chans}{ $uchan }{Topic} = {
434 5 Value => $topic,
435 SetBy => $who,
436 SetAt => time(),
437 };
438  
439 5 return PCI_EAT_NONE;
440 }
441  
442 # RPL_NAMES
443 35 ▶sub S_353 {
Subroutine S_353: called CC=14 SCAR=26.9
Pod undocumented
444 35 my ($self, undef) = splice @_, 0, 2;
445 35 my @data = @{ ${ $_[2] } };
446 35 ▶ shift @data if $data[0] =~ /^[@=*]$/;
Branch: 1 branch
BranchTrueFalseTotal
if $data[0] =~ /^[\@=*]$/ 35 0 35
447 35 my $chan = shift @data;
448 35 my @nicks = split /\s+/, shift @data;
449 35 my $map = $self->isupport('CASEMAPPING');
450 35 my $uchan = uc_irc($chan, $map);
451 35 ▶ my $prefix = $self->isupport('PREFIX') || { o => '@', v => '+' };
Condition50%1/2
$self->isupport('PREFIX') || {'o', '@', 'v', '+'}
l!l
350
MC/DC0%0/1
$self->isupport('PREFIX') || {'o', '@', 'v', '+'}
$self->isupport('PREFIX')
Truth table50%1/2
A
A= $self->isupport('PREFIX')
Aresult
11
00
452 35 my $search = join '|', map { quotemeta } values %$prefix;
453 35 $search = qr/(?:$search)/;
454  
455 35 for my $nick (@nicks) {
456 54 my $status;
457 54 ▶ if ( ($status) = $nick =~ /^($search+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($status) = $nick =~ /^($search+)/) 35 19 54
458 35 $nick =~ s/^($search+)//;
459 }
460  
461 54 my ($user, $host);
462 54 ▶ if ($self->isupport('UHNAMES')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isupport("UHNAMES")) 0 54 54
463 0 ($nick, $user, $host) = split /[!@]/, $nick;
464 }
465  
466 54 my $unick = uc_irc($nick, $map);
467 54 ▶ $status = '' if !defined $status;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $status 19 35 54
468 54 my $whatever = '';
469 54 ▶ my $existing = $self->{STATE}{Nicks}{$unick}{CHANS}{$uchan} || '';
Condition100%2/2
$self->{'STATE'}{'Nicks'}{$unick}{'CHANS'}{$uchan} || ''
l!l
153
MC/DC100%1/1
$self->{'STATE'}{'Nicks'}{$unick}{'CHANS'}{$uchan} || ''
$self->{'STATE'}{'Nicks'}{$unick}{'CHANS'}{$uchan}
Truth table100%2/2
A
A= $self->{'STATE'}{'Nicks'}{$unick}{'CHANS'}{$uchan}
Aresult
11
00
470  
471 54 for my $mode (keys %$prefix) {
472 162 ▶ if ($status =~ /\Q$prefix->{$mode}/ && $existing !~ /\Q$prefix->{$mode}/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status =~ /\Q$prefix->{$mode}\E/ and not $existing =~ /\Q$prefix->{$mode}\E/) 35 127 162
Condition66%2/3
$status =~ /\Q$prefix->{$mode}\E/ and not $existing =~ /\Q$prefix->{$mode}\E/
!ll&&!rl&&r
127035
MC/DC50%1/2
$status =~ /\Q$prefix->{$mode}\E/ and not $existing =~ /\Q$prefix->{$mode}\E/
$status =~ /\Q$prefix->{$mode}\E/ not $existing =~ /\Q$prefix->{$mode}\E/
Truth table66%2/3
A and not(B)
A= $status =~ /\Q$prefix->{$mode}\E/B= not $existing =~ /\Q$prefix->{$mode}\E/
ABresult
0X0
100
111
473 35 $whatever .= $mode;
474 }
475 }
476  
477 54 ▶ $existing .= $whatever if !length $existing || $existing !~ /$whatever/;
Branch: 1 branch
BranchTrueFalseTotal
unless length $existing and $existing =~ /$whatever/ 53 1 54
Condition66%2/3
length $existing and $existing =~ /$whatever/
!ll&&!rl&&r
5301
MC/DC50%1/2
length $existing and $existing =~ /$whatever/
length $existing $existing =~ /$whatever/
Truth table66%2/3
A and B
A= length $existingB= $existing =~ /$whatever/
ABresult
0X0
100
111
478 54 $self->{STATE}{Nicks}{$unick}{CHANS}{$uchan} = $existing;
479 54 $self->{STATE}{Chans}{$uchan}{Nicks}{$unick} = $existing;
480 54 $self->{STATE}{Nicks}{$unick}{Nick} = $nick;
481 54 ▶ if ($self->isupport('UHNAMES')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isupport("UHNAMES")) 0 54 54
482 0 $self->{STATE}{Nicks}{$unick}{User} = $user;
483 0 $self->{STATE}{Nicks}{$unick}{Host} = $host;
484 }
485 }
486 35 return PCI_EAT_NONE;
487 }
488  
489 # RPL_WHOREPLY
490 72 ▶sub S_352 {
Subroutine S_352: called CC=20 SCAR=30.4
Pod undocumented
491 72 my ($self, undef) = splice @_, 0, 2;
492 72 my ($chan, $user, $host, $server, $nick, $status, $rest) = @{ ${ $_[2] } };
493 72 my ($hops, $real) = split /\x20/, $rest, 2;
494 72 my $map = $self->isupport('CASEMAPPING');
495 72 my $unick = uc_irc($nick, $map);
496 72 my $uchan = uc_irc($chan, $map);
497  
498 72 $self->{STATE}{Nicks}{ $unick }{Nick} = $nick;
499 72 $self->{STATE}{Nicks}{ $unick }{User} = $user;
500 72 $self->{STATE}{Nicks}{ $unick }{Host} = $host;
501  
502 72 ▶ if ( !exists $self->{whojoiners} || $self->{whojoiners} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $self->{"whojoiners"} or $self->{"whojoiners"}) 72 0 72
Condition33%1/3
not exists $self->{"whojoiners"} or $self->{"whojoiners"}
l!l&&r!l&&!r
7200
MC/DC0%0/2
not exists $self->{"whojoiners"} or $self->{"whojoiners"}
not exists $self->{"whojoiners"} $self->{"whojoiners"}
Truth table33%1/3
not(A) or B
A= not exists $self->{"whojoiners"}B= $self->{"whojoiners"}
ABresult
1X1
011
000
503 72 $self->{STATE}{Nicks}{ $unick }{Hops} = $hops;
504 72 $self->{STATE}{Nicks}{ $unick }{Real} = $real;
505 72 $self->{STATE}{Nicks}{ $unick }{Server} = $server;
506 72 ▶ $self->{STATE}{Nicks}{ $unick }{IRCop} = 1 if $status =~ /\*/;
Branch: 1 branch
BranchTrueFalseTotal
if $status =~ /\*/ 1 71 72
507 }
508  
509 72 ▶ if ( exists $self->{STATE}{Chans}{ $uchan } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"STATE"}{"Chans"}{$uchan}) 59 13 72
510 59 my $whatever = '';
511 59 ▶ my $existing = $self->{STATE}{Nicks}{ $unick }{CHANS}{ $uchan } || '';
Condition100%2/2
$self->{'STATE'}{'Nicks'}{$unick}{'CHANS'}{$uchan} || ''
l!l
3524
MC/DC100%1/1
$self->{'STATE'}{'Nicks'}{$unick}{'CHANS'}{$uchan} || ''
$self->{'STATE'}{'Nicks'}{$unick}{'CHANS'}{$uchan}
Truth table100%2/2
A
A= $self->{'STATE'}{'Nicks'}{$unick}{'CHANS'}{$uchan}
Aresult
11
00
512 59 ▶ my $prefix = $self->isupport('PREFIX') || { o => '@', v => '+' };
Condition50%1/2
$self->isupport('PREFIX') || {'o', '@', 'v', '+'}
l!l
590
MC/DC0%0/1
$self->isupport('PREFIX') || {'o', '@', 'v', '+'}
$self->isupport('PREFIX')
Truth table50%1/2
A
A= $self->isupport('PREFIX')
Aresult
11
00
513  
514 59 for my $mode ( keys %{ $prefix } ) {
515 177 ▶ if ($status =~ /\Q$prefix->{$mode}/ && $existing !~ /\Q$prefix->{$mode}/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status =~ /\Q$prefix->{$mode}\E/ and not $existing =~ /\Q$prefix->{$mode}\E/) 35 142 177
Condition66%2/3
$status =~ /\Q$prefix->{$mode}\E/ and not $existing =~ /\Q$prefix->{$mode}\E/
!ll&&!rl&&r
142035
MC/DC50%1/2
$status =~ /\Q$prefix->{$mode}\E/ and not $existing =~ /\Q$prefix->{$mode}\E/
$status =~ /\Q$prefix->{$mode}\E/ not $existing =~ /\Q$prefix->{$mode}\E/
Truth table66%2/3
A and not(B)
A= $status =~ /\Q$prefix->{$mode}\E/B= not $existing =~ /\Q$prefix->{$mode}\E/
ABresult
0X0
100
111
516 35 $whatever .= $mode;
517 }
518 }
519  
520 59 ▶ $existing .= $whatever if !$existing || $existing !~ /$whatever/;
Branch: 1 branch
BranchTrueFalseTotal
unless $existing and $existing =~ /$whatever/ 24 35 59
Condition66%2/3
$existing and $existing =~ /$whatever/
!ll&&!rl&&r
24035
MC/DC50%1/2
$existing and $existing =~ /$whatever/
$existing $existing =~ /$whatever/
Truth table66%2/3
A and B
A= $existingB= $existing =~ /$whatever/
ABresult
0X0
100
111
521 59 $self->{STATE}{Nicks}{ $unick }{CHANS}{ $uchan } = $existing;
522 59 $self->{STATE}{Chans}{ $uchan }{Nicks}{ $unick } = $existing;
523 59 $self->{STATE}{Chans}{ $uchan }{Name} = $chan;
524  
525 59 ▶ if ($self->{STATE}{Chans}{ $uchan }{AWAY_SYNCH} && $unick ne uc_irc($self->nick_name(), $map)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"STATE"}{"Chans"}{$uchan}{"AWAY_SYNCH"} and $unick ne uc_irc($self->nick_name, $map)) 2 57 59
Condition100%3/3
$self->{"STATE"}{"Chans"}{$uchan}{"AWAY_SYNCH"} and $unick ne uc_irc($self->nick_name, $map)
!ll&&!rl&&r
5522
MC/DC100%2/2
$self->{"STATE"}{"Chans"}{$uchan}{"AWAY_SYNCH"} and $unick ne uc_irc($self->nick_name, $map)
$self->{"STATE"}{"Chans"}{$uchan}{"AWAY_SYNCH"} $unick ne uc_irc($self->nick_name, $map)
Truth table100%3/3
A and B
A= $self->{"STATE"}{"Chans"}{$uchan}{"AWAY_SYNCH"}B= $unick ne uc_irc($self->nick_name, $map)
ABresult
0X0
100
111
526 2 ▶ if ( $status =~ /G/ && !$self->{STATE}{Nicks}{ $unick }{Away} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($status =~ /G/ and not $self->{'STATE'}{'Nicks'}{$unick}{'Away'}) { } 1 1 2
elsif ($status =~ /H/ and $self->{'STATE'}{'Nicks'}{$unick}{'Away'}) { } 1 0 1
Condition66%2/3
$status =~ /G/ and not $self->{"STATE"}{"Nicks"}{$unick}{"Away"}
!ll&&!rl&&r
101
MC/DC50%1/2
$status =~ /G/ and not $self->{"STATE"}{"Nicks"}{$unick}{"Away"}
$status =~ /G/ not $self->{"STATE"}{"Nicks"}{$unick}{"Away"}
Truth table66%2/3
A and not(B)
A= $status =~ /G/B= not $self->{"STATE"}{"Nicks"}{$unick}{"Away"}
ABresult
0X0
100
111
527 1 $self->send_event_next(irc_user_away => $nick, [ $self->nick_channels( $nick ) ] );
528 }
529 ▶ elsif ($status =~ /H/ && $self->{STATE}{Nicks}{ $unick }{Away} ) {
Condition33%1/3
$status =~ /H/ and $self->{"STATE"}{"Nicks"}{$unick}{"Away"}
!ll&&!rl&&r
001
MC/DC0%0/2
$status =~ /H/ and $self->{"STATE"}{"Nicks"}{$unick}{"Away"}
$status =~ /H/ $self->{"STATE"}{"Nicks"}{$unick}{"Away"}
Truth table33%1/3
A and B
A= $status =~ /H/B= $self->{"STATE"}{"Nicks"}{$unick}{"Away"}
ABresult
0X0
100
111
530 1 $self->send_event_next(irc_user_back => $nick, [ $self->nick_channels( $nick ) ] );
531 }
532 }
533  
534 59 ▶ if ($self->{awaypoll}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"awaypoll"}) 8 51 59
535 8 ▶ $self->{STATE}{Nicks}{ $unick }{Away} = $status =~ /G/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$status =~ /G/ ? : 2 6 8
536 }
537 }
538  
539 72 return PCI_EAT_NONE;
540 }
541  
542 # RPL_ENDOFWHO
543 49 ▶sub S_315 {
Subroutine S_315: called CC=5 SCAR=16.2
Pod undocumented
544 49 my ($self, undef) = splice @_, 0, 2;
545 49 my $what = ${ $_[2] }->[0];
546 49 my $map = $self->isupport('CASEMAPPING');
547 49 my $uwhat = uc_irc($what, $map);
548  
549 49 ▶ if ( exists $self->{STATE}{Chans}{ $uwhat } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'STATE'}{'Chans'}{$uwhat}) { } 36 13 49
550 36 my $chan = $what; my $uchan = $uwhat;
551 36 ▶ if ( $self->_channel_sync($chan, 'WHO') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_channel_sync($chan, 'WHO')) { } 0 36 36
elsif ($self->{'STATE'}{'Chans'}{$uchan}{'AWAY_SYNCH'}) { } 2 34 36
552 0 my $rec = delete $self->{CHANNEL_SYNCH}{ $uchan };
553 0 $self->send_event_next(irc_chan_sync => $chan, time() - $rec->{_time} );
554 }
555 elsif ( $self->{STATE}{Chans}{ $uchan }{AWAY_SYNCH} ) {
556 2 $self->{STATE}{Chans}{ $uchan }{AWAY_SYNCH} = 0;
557 2 $poe_kernel->delay_add(_away_sync => $self->{awaypoll} => $chan );
558 2 $self->send_event_next(irc_away_sync_end => $chan );
559 }
560 }
561 else {
562 13 my $nick = $what; my $unick = $uwhat;
563 13 my $chan = shift @{ $self->{NICK_SYNCH}{ $unick } };
564 13 ▶ delete $self->{NICK_SYNCH}{ $unick } if !@{ $self->{NICK_SYNCH}{ $unick } };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"NICK_SYNCH"}{$unick};} 13 0 13
565 13 $self->send_event_next(irc_nick_sync => $nick, $chan );
566 }
567  
568 49 return PCI_EAT_NONE;
569 }
570  
571 # RPL_CREATIONTIME
572 34 ▶sub S_329 {
Subroutine S_329: called CC=1 SCAR=0.0
Pod undocumented
573 34 my ($self, undef) = splice @_, 0, 2;
574 34 my $map = $self->isupport('CASEMAPPING');
575 34 my $chan = ${ $_[2] }->[0];
576 34 my $time = ${ $_[2] }->[1];
577 34 my $uchan = uc_irc($chan, $map);
578  
579 34 $self->{STATE}->{Chans}{ $uchan }{CreationTime} = $time;
580 34 return PCI_EAT_NONE;
581 }
582  
583 # RPL_BANLIST
584 0 ▶sub S_367 {
Subroutine S_367: not called CC=1 SCAR=6.9
Pod undocumented
585 0 my ($self, undef) = splice @_, 0, 2;
586 0 my @args = @{ ${ $_[2] } };
587 0 my $chan = shift @args;
588 0 my $map = $self->isupport('CASEMAPPING');
589 0 my $uchan = uc_irc($chan, $map);
590 0 my ($mask, $who, $when) = @args;
591  
592 0 $self->{STATE}{Chans}{ $uchan }{Lists}{b}{ $mask } = {
593 SetBy => $who,
594 SetAt => $when,
595 };
596 0 return PCI_EAT_NONE;
597 }
598  
599 # RPL_ENDOFBANLIST
600 34 ▶sub S_368 {
Subroutine S_368: called CC=2 SCAR=6.9
Pod undocumented
601 34 my ($self, undef) = splice @_, 0, 2;
602 34 my @args = @{ ${ $_[2] } };
603 34 my $chan = shift @args;
604 34 my $map = $self->isupport('CASEMAPPING');
605 34 my $uchan = uc_irc($chan, $map);
606  
607 34 ▶ if ($self->_channel_sync($chan, 'BAN')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_channel_sync($chan, "BAN")) 33 1 34
608 33 my $rec = delete $self->{CHANNEL_SYNCH}{ $uchan };
609 33 $self->send_event_next(irc_chan_sync => $chan, time() - $rec->{_time} );
610 }
611  
612 34 return PCI_EAT_NONE;
613 }
614  
615 # RPL_INVITELIST
616 0 ▶sub S_346 {
Subroutine S_346: not called CC=1 SCAR=6.9
Pod undocumented
617 0 my ($self, undef) = splice @_, 0, 2;
618 0 my ($chan, $mask, $who, $when) = @{ ${ $_[2] } };
619 0 my $map = $self->isupport('CASEMAPPING');
620 0 my $uchan = uc_irc($chan, $map);
621 0 my $invex = $self->isupport('INVEX');
622  
623 0 $self->{STATE}{Chans}{ $uchan }{Lists}{ $invex }{ $mask } = {
624 SetBy => $who,
625 SetAt => $when
626 };
627  
628 0 return PCI_EAT_NONE;
629 }
630  
631 # RPL_ENDOFINVITELIST
632 1 ▶sub S_347 {
Subroutine S_347: called CC=1 SCAR=0.0
Pod undocumented
633 1 my ($self, undef) = splice @_, 0, 2;
634 1 my ($chan) = @{ ${ $_[2] } };
635 1 my $map = $self->isupport('CASEMAPPING');
636 1 my $uchan = uc_irc($chan, $map);
637  
638 1 $self->send_event_next(irc_chan_sync_invex => $chan);
639 1 return PCI_EAT_NONE;
640 }
641  
642 # RPL_EXCEPTLIST
643 0 ▶sub S_348 {
Subroutine S_348: not called CC=1 SCAR=6.9
Pod undocumented
644 0 my ($self, undef) = splice @_, 0, 2;
645 0 my ($chan, $mask, $who, $when) = @{ ${ $_[2] } };
646 0 my $map = $self->isupport('CASEMAPPING');
647 0 my $uchan = uc_irc($chan, $map);
648 0 my $excepts = $self->isupport('EXCEPTS');
649  
650 0 $self->{STATE}{Chans}{ $uchan }{Lists}{ $excepts }{ $mask } = {
651 SetBy => $who,
652 SetAt => $when,
653 };
654 0 return PCI_EAT_NONE;
655 }
656  
657 # RPL_ENDOFEXCEPTLIST
658 1 ▶sub S_349 {
Subroutine S_349: called CC=1 SCAR=0.0
Pod undocumented
659 1 my ($self, undef) = splice @_, 0, 2;
660 1 my ($chan) = @{ ${ $_[2] } };
661 1 my $map = $self->isupport('CASEMAPPING');
662 1 my $uchan = uc_irc($chan, $map);
663  
664 1 $self->send_event_next(irc_chan_sync_excepts => $chan);
665 1 return PCI_EAT_NONE;
666 }
667  
668 # RPL_CHANNELMODEIS
669 34 ▶sub S_324 {
Subroutine S_324: called CC=10 SCAR=23.3
Pod undocumented
670 34 my ($self, undef) = splice @_, 0, 2;
671 34 my @args = @{ ${ $_[2] } };
672 34 my $chan = shift @args;
673 34 my $map = $self->isupport('CASEMAPPING');
674 34 my $uchan = uc_irc($chan, $map);
675 34 ▶ my $modes = $self->isupport('CHANMODES') || [ qw(beI k l imnpstaqr) ];
Condition50%1/2
$self->isupport('CHANMODES') || ['beI', 'k', 'l', 'imnpstaqr']
l!l
340
MC/DC0%0/1
$self->isupport('CHANMODES') || ['beI', 'k', 'l', 'imnpstaqr']
$self->isupport('CHANMODES')
Truth table50%1/2
A
A= $self->isupport('CHANMODES')
Aresult
11
00
676 34 ▶ my $prefix = $self->isupport('PREFIX') || { o => '@', v => '+' };
Condition50%1/2
$self->isupport('PREFIX') || {'o', '@', 'v', '+'}
l!l
340
MC/DC0%0/1
$self->isupport('PREFIX') || {'o', '@', 'v', '+'}
$self->isupport('PREFIX')
Truth table50%1/2
A
A= $self->isupport('PREFIX')
Aresult
11
00
677  
678 34 my $parsed_mode = parse_mode_line($prefix, $modes, @args);
679 34 for my $mode (@{ $parsed_mode->{modes} }) {
680 76 $mode =~ s/\+//;
681 76 my $arg = '';
682 76 ▶ if ($mode =~ /[^$modes->[3]]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode =~ /[^$modes->[3]]/) 6 70 76
683 # doesn't match a mode with no args
684 6 $arg = shift @{ $parsed_mode->{args} };
685 }
686  
687 76 ▶ if ( $self->{STATE}{Chans}{ $uchan }{Mode} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'STATE'}{'Chans'}{$uchan}{'Mode'}) { } 60 16 76
688 60 ▶ $self->{STATE}{Chans}{ $uchan }{Mode} .= $mode if $self->{STATE}{Chans}{ $uchan }{Mode} !~ /$mode/;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"STATE"}{"Chans"}{$uchan}{"Mode"} =~ /$mode/ 26 34 60
689 }
690 else {
691 16 $self->{STATE}{Chans}{ $uchan }{Mode} = $mode;
692 }
693  
694 76 ▶ $self->{STATE}{Chans}{ $uchan }{ModeArgs}{ $mode } = $arg if defined ( $arg );
Branch: 1 branch
BranchTrueFalseTotal
if defined $arg 75 1 76
695 }
696  
697 34 ▶ if ( $self->{STATE}{Chans}{ $uchan }{Mode} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"STATE"}{"Chans"}{$uchan}{"Mode"}) 34 0 34
698 34 $self->{STATE}{Chans}{ $uchan }{Mode} = join('', sort {uc $a cmp uc $b} split //, $self->{STATE}{Chans}{ $uchan }{Mode} );
699 }
700  
701 34 ▶ if ( $self->_channel_sync($chan, 'MODE') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_channel_sync($chan, "MODE")) 0 34 34
702 0 my $rec = delete $self->{CHANNEL_SYNCH}{ $uchan };
703 0 $self->send_event_next(irc_chan_sync => $chan, time() - $rec->{_time} );
704 }
705  
706 34 return PCI_EAT_NONE;
707 }
708  
709 # RPL_TOPIC
710 4 ▶sub S_332 {
Subroutine S_332: called CC=1 SCAR=0.0
Pod undocumented
711 4 my ($self, undef) = splice @_, 0, 2;
712 4 my $chan = ${ $_[2] }->[0];
713 4 my $topic = ${ $_[2] }->[1];
714 4 my $map = $self->isupport('CASEMAPPING');
715 4 my $uchan = uc_irc($chan, $map);
716  
717 4 $self->{STATE}{Chans}{ $uchan }{Topic}{Value} = $topic;
718 4 return PCI_EAT_NONE;
719 }
720  
721 # RPL_TOPICWHOTIME
722 4 ▶sub S_333 {
Subroutine S_333: called CC=1 SCAR=0.0
Pod undocumented
723 4 my ($self, undef) = splice @_, 0, 2;
724 4 my ($chan, $who, $when) = @{ ${ $_[2] } };
725 4 my $map = $self->isupport('CASEMAPPING');
726 4 my $uchan = uc_irc($chan, $map);
727  
728 4 $self->{STATE}{Chans}{ $uchan }{Topic}{SetBy} = $who;
729 4 $self->{STATE}{Chans}{ $uchan }{Topic}{SetAt} = $when;
730  
731 4 return PCI_EAT_NONE;
732 }
733  
734 # Methods for STATE query
735 # Internal methods begin with '_'
736 #
737  
738 2 ▶sub umode {
Subroutine umode: called CC=1 SCAR=0.0
Pod documented
739 2 my ($self) = @_;
740 2 return $self->{STATE}{usermode};
741 }
742  
743 2 ▶sub is_user_mode_set {
Subroutine is_user_mode_set: called CC=5 SCAR=19.1
Pod documented
744 2 my ($self, $mode) = @_;
745  
746 2 ▶ if (!defined $mode) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $mode) 0 2 2
747 0 warn 'User mode is undefined';
748 0 return;
749 }
750  
751 2 ▶ $mode = (split //, $mode)[0] || return;
Condition50%1/2
(split(//, $mode, 0))[0] || (return)
l!l
20
MC/DC0%0/1
(split(//, $mode, 0))[0] || (return)
(split(//, $mode, 0))[0]
Truth table50%1/2
A
A= (split(//, $mode, 0))[0]
Aresult
11
00
752 2 $mode =~ s/[^A-Za-z]//g;
753 2 ▶ return if !$mode;
Branch: 1 branch
BranchTrueFalseTotal
unless $mode 0 2 2
754  
755 2 ▶ return 1 if $self->{STATE}{usermode} =~ /$mode/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"STATE"}{"usermode"} =~ /$mode/ 2 0 2
756 0 return;
757 }
758  
759 2 ▶sub _away_sync {
Subroutine _away_sync: called CC=1 SCAR=0.0
760 2 my ($self, $chan) = @_[OBJECT, ARG0];
761 2 my $map = $self->isupport('CASEMAPPING');
762 2 my $uchan = uc_irc($chan, $map);
763  
764 2 $self->{STATE}{Chans}{ $uchan }{AWAY_SYNCH} = 1;
765 2 $self->yield(who => $chan);
766 2 $self->send_event(irc_away_sync_start => $chan);
767  
768 2 return;
769 }
770  
771 104 ▶sub _channel_sync {
Subroutine _channel_sync: called CC=6 SCAR=18.0
772 104 my ($self, $chan, $sync) = @_;
773 104 my $map = $self->isupport('CASEMAPPING');
774 104 my $uchan = uc_irc($chan, $map);
775  
776 104 ▶ return if !$self->_channel_exists($chan) || !defined $self->{CHANNEL_SYNCH}{ $uchan };
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_channel_exists($chan) and defined $self->{"CHANNEL_SYNCH"}{$uchan} 5 99 104
Condition66%2/3
$self->_channel_exists($chan) and defined $self->{"CHANNEL_SYNCH"}{$uchan}
!ll&&!rl&&r
0599
MC/DC50%1/2
$self->_channel_exists($chan) and defined $self->{"CHANNEL_SYNCH"}{$uchan}
$self->_channel_exists($chan) defined $self->{"CHANNEL_SYNCH"}{$uchan}
Truth table66%2/3
A and B
A= $self->_channel_exists($chan)B= defined $self->{"CHANNEL_SYNCH"}{$uchan}
ABresult
0X0
100
111
777 99 ▶ $self->{CHANNEL_SYNCH}{ $uchan }{ $sync } = 1 if $sync;
Branch: 1 branch
BranchTrueFalseTotal
if $sync 99 0 99
778  
779 99 for my $item ( qw(BAN MODE WHO) ) {
780 165 ▶ return if !$self->{CHANNEL_SYNCH}{ $uchan }{ $item };
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"CHANNEL_SYNCH"}{$uchan}{$item} 66 99 165
781 }
782  
783 33 return 1;
784 }
785  
786 164 ▶sub _nick_exists {
Subroutine _nick_exists: called CC=2 SCAR=6.9
787 164 my ($self, $nick) = @_;
788 164 my $map = $self->isupport('CASEMAPPING');
789 164 my $unick = uc_irc($nick, $map);
790  
791 164 ▶ return 1 if exists $self->{STATE}{Nicks}{ $unick };
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"STATE"}{"Nicks"}{$unick} 144 20 164
792 20 return;
793 }
794  
795 140 ▶sub _channel_exists {
Subroutine _channel_exists: called CC=2 SCAR=7.4
796 140 my ($self, $chan) = @_;
797 140 my $map = $self->isupport('CASEMAPPING');
798 140 my $uchan = uc_irc($chan, $map);
799  
800 140 ▶ return 1 if exists $self->{STATE}{Chans}{ $uchan };
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"STATE"}{"Chans"}{$uchan} 140 0 140
801 0 return;
802 }
803  
804 8 ▶sub _nick_has_channel_mode {
Subroutine _nick_has_channel_mode: called CC=3 SCAR=11.0
805 8 my ($self, $chan, $nick, $flag) = @_;
806 8 my $map = $self->isupport('CASEMAPPING');
807 8 my $uchan = uc_irc($chan, $map);
808 8 my $unick = uc_irc($nick, $map);
809 8 $flag = (split //, $flag)[0];
810  
811 8 ▶ return if !$self->is_channel_member($uchan, $unick);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_channel_member($uchan, $unick) 0 8 8
812 8 ▶ return 1 if $self->{STATE}{Nicks}{ $unick }{CHANS}{ $uchan } =~ /$flag/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"STATE"}{"Nicks"}{$unick}{"CHANS"}{$uchan} =~ /$flag/ 1 7 8
813 7 return;
814 }
815  
816 # Returns all the channels that the bot is on with an indication of
817 # whether it has operator, halfop or voice.
818 66 ▶sub channels {
Subroutine channels: called CC=4 SCAR=13.9
Pod documented
819 66 my ($self) = @_;
820 66 my $map = $self->isupport('CASEMAPPING');
821 66 my $unick = uc_irc($self->nick_name(), $map);
822  
823 66 my %result;
824 66 ▶ if (defined $unick && $self->_nick_exists($unick)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $unick and $self->_nick_exists($unick)) 56 10 66
Condition100%3/3
defined $unick and $self->_nick_exists($unick)
!ll&&!rl&&r
1956
MC/DC100%2/2
defined $unick and $self->_nick_exists($unick)
defined $unick $self->_nick_exists($unick)
Truth table100%3/3
A and B
A= defined $unickB= $self->_nick_exists($unick)
ABresult
0X0
100
111
825 56 for my $uchan ( keys %{ $self->{STATE}{Nicks}{ $unick }{CHANS} } ) {
826 67 $result{ $self->{STATE}{Chans}{ $uchan }{Name} } = $self->{STATE}{Nicks}{ $unick }{CHANS}{ $uchan };
827 }
828 }
829  
830 66 return \%result;
831 }
832  
833 2 ▶sub nicks {
Subroutine nicks: called CC=1 SCAR=0.0
Pod documented
834 2 my ($self) = @_;
835 2 return map { $self->{STATE}{Nicks}{$_}{Nick} } keys %{ $self->{STATE}{Nicks} };
836 }
837  
838 58 ▶sub nick_info {
Subroutine nick_info: called CC=5 SCAR=16.9
Pod documented
839 58 my ($self, $nick) = @_;
840  
841 58 ▶ if (!defined $nick) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $nick) 0 58 58
842 0 warn 'Nickname is undefined';
843 0 return;
844 }
845  
846 58 my $map = $self->isupport('CASEMAPPING');
847 58 my $unick = uc_irc($nick, $map);
848  
849 58 ▶ return if !$self->_nick_exists($nick);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_nick_exists($nick) 9 49 58
850  
851 49 my $user = $self->{STATE}{Nicks}{ $unick };
852 49 my %result = %{ $user };
853  
854 # maybe we haven't synced this user's info yet
855 49 ▶ if (defined $result{User} && defined $result{Host}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $result{"User"} and defined $result{"Host"}) 49 0 49
Condition33%1/3
defined $result{"User"} and defined $result{"Host"}
!ll&&!rl&&r
0049
MC/DC0%0/2
defined $result{"User"} and defined $result{"Host"}
defined $result{"User"} defined $result{"Host"}
Truth table33%1/3
A and B
A= defined $result{"User"}B= defined $result{"Host"}
ABresult
0X0
100
111
856 49 $result{Userhost} = "$result{User}\@$result{Host}";
857 }
858 49 delete $result{'CHANS'};
859  
860 49 return \%result;
861 }
862  
863 16 ▶sub nick_long_form {
Subroutine nick_long_form: called CC=5 SCAR=18.3
Pod documented
864 16 my ($self, $nick) = @_;
865  
866 16 ▶ if (!defined $nick) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $nick) 0 16 16
867 0 warn 'Nickname is undefined';
868 0 return;
869 }
870  
871 16 my $map = $self->isupport('CASEMAPPING');
872 16 my $unick = uc_irc($nick, $map);
873  
874 16 ▶ return if !$self->_nick_exists($nick);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_nick_exists($nick) 0 16 16
875  
876 16 my $user = $self->{STATE}{Nicks}{ $unick };
877 16 ▶ return unless exists $user->{User} && exists $user->{Host};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $user->{"User"} and exists $user->{"Host"} 0 16 16
Condition33%1/3
exists $user->{"User"} and exists $user->{"Host"}
!ll&&!rl&&r
0016
MC/DC0%0/2
exists $user->{"User"} and exists $user->{"Host"}
exists $user->{"User"} exists $user->{"Host"}
Truth table33%1/3
A and B
A= exists $user->{"User"}B= exists $user->{"Host"}
ABresult
0X0
100
111
878 16 return "$user->{Nick}!$user->{User}\@$user->{Host}";
879 }
880  
881 12 ▶sub nick_channels {
Subroutine nick_channels: called CC=3 SCAR=11.7
Pod documented
882 12 my ($self, $nick) = @_;
883  
884 12 ▶ if (!defined $nick) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $nick) 0 12 12
885 0 warn 'Nickname is undefined';
886 0 return;
887 }
888 12 my $map = $self->isupport('CASEMAPPING');
889 12 my $unick = uc_irc($nick, $map);
890  
891 12 ▶ return if !$self->_nick_exists($nick);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_nick_exists($nick) 0 12 12
892 12 return map { $self->{STATE}{Chans}{$_}{Name} } keys %{ $self->{STATE}{Nicks}{ $unick }{CHANS} };
893 }
894  
895 6 ▶sub channel_list {
Subroutine channel_list: called CC=3 SCAR=11.7
Pod documented
896 6 my ($self, $chan) = @_;
897  
898 6 ▶ if (!defined $chan) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chan) 0 6 6
899 0 warn 'Channel is undefined';
900 0 return;
901 }
902  
903 6 my $map = $self->isupport('CASEMAPPING');
904 6 my $uchan = uc_irc($chan, $map);
905  
906 6 ▶ return if !$self->_channel_exists($chan);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_channel_exists($chan) 0 6 6
907 6 return map { $self->{STATE}{Nicks}{$_}{Nick} } keys %{ $self->{STATE}{Chans}{ $uchan }{Nicks} };
908 }
909  
910 4 ▶sub is_away {
Subroutine is_away: called CC=6 SCAR=23.5
Pod documented
911 4 my ($self, $nick) = @_;
912  
913 4 ▶ if (!defined $nick) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $nick) 0 4 4
914 0 warn 'Nickname is undefined';
915 0 return;
916 }
917  
918 4 my $map = $self->isupport('CASEMAPPING');
919 4 my $unick = uc_irc($nick, $map);
920  
921 4 ▶ if ($unick eq uc_irc($self->nick_name())) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unick eq uc_irc($self->nick_name)) 4 0 4
922 # more accurate
923 4 ▶ return 1 if $self->{STATE}{away};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"STATE"}{"away"} 1 3 4
924 3 return;
925 }
926  
927 0 ▶ return if !$self->_nick_exists($nick);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_nick_exists($nick) 0 0 0
928 0 ▶ return 1 if $self->{STATE}{Nicks}{ $unick }{Away};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"STATE"}{"Nicks"}{$unick}{"Away"} 0 0 0
929 0 return;
930 }
931  
932 2 ▶sub is_operator {
Subroutine is_operator: called CC=4 SCAR=18.6
Pod documented
933 2 my ($self, $nick) = @_;
934  
935 2 ▶ if (!defined $nick) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $nick) 0 2 2
936 0 warn 'Nickname is undefined';
937 0 return;
938 }
939  
940 2 my $map = $self->isupport('CASEMAPPING');
941 2 my $unick = uc_irc($nick, $map);
942  
943 2 ▶ return if !$self->_nick_exists($nick);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_nick_exists($nick) 2 0 2
944  
945 0 ▶ return 1 if $self->{STATE}{Nicks}{ $unick }{IRCop};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"STATE"}{"Nicks"}{$unick}{"IRCop"} 0 0 0
946 0 return;
947 }
948  
949 8 ▶sub is_channel_mode_set {
Subroutine is_channel_mode_set: called CC=7 SCAR=21.8
Pod documented
950 8 my ($self, $chan, $mode) = @_;
951  
952 8 ▶ if (!defined $chan || !defined $mode) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chan and defined $mode) 0 8 8
Condition33%1/3
defined $chan and defined $mode
!ll&&!rl&&r
008
MC/DC0%0/2
defined $chan and defined $mode
defined $chan defined $mode
Truth table33%1/3
A and B
A= defined $chanB= defined $mode
ABresult
0X0
100
111
953 0 warn 'Channel or mode is undefined';
954 0 return;
955 }
956  
957 8 my $map = $self->isupport('CASEMAPPING');
958 8 my $uchan = uc_irc($chan, $map);
959 8 $mode = (split //, $mode)[0];
960  
961 8 ▶ return if !$self->_channel_exists($chan) || !$mode;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_channel_exists($chan) and $mode 0 8 8
Condition33%1/3
$self->_channel_exists($chan) and $mode
!ll&&!rl&&r
008
MC/DC0%0/2
$self->_channel_exists($chan) and $mode
$self->_channel_exists($chan) $mode
Truth table33%1/3
A and B
A= $self->_channel_exists($chan)B= $mode
ABresult
0X0
100
111
962 8 $mode =~ s/[^A-Za-z]//g;
963  
964 8 ▶ if (defined $self->{STATE}{Chans}{ $uchan }{Mode}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"STATE"}{"Chans"}{$uchan}{"Mode"} and $self->{"STATE"}{"Chans"}{$uchan}{"Mode"} =~ /$mode/) 2 6 8
Condition66%2/3
defined $self->{"STATE"}{"Chans"}{$uchan}{"Mode"} and $self->{"STATE"}{"Chans"}{$uchan}{"Mode"} =~ /$mode/
!ll&&!rl&&r
062
MC/DC50%1/2
defined $self->{"STATE"}{"Chans"}{$uchan}{"Mode"} and $self->{"STATE"}{"Chans"}{$uchan}{"Mode"} =~ /$mode/
defined $self->{"STATE"}{"Chans"}{$uchan}{"Mode"} $self->{"STATE"}{"Chans"}{$uchan}{"Mode"} =~ /$mode/
Truth table66%2/3
A and B
A= defined $self->{"STATE"}{"Chans"}{$uchan}{"Mode"}B= $self->{"STATE"}{"Chans"}{$uchan}{"Mode"} =~ /$mode/
ABresult
0X0
100
111
965 && $self->{STATE}{Chans}{ $uchan }{Mode} =~ /$mode/) {
966 2 return 1;
967 }
968  
969 6 return;
970 }
971  
972 0 ▶sub is_channel_synced {
Subroutine is_channel_synced: not called CC=2 SCAR=17.9
Pod documented
973 0 my ($self, $chan) = @_;
974  
975 0 ▶ if (!defined $chan) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chan) 0 0 0
976 0 warn 'Channel is undefined';
977 0 return;
978 }
979  
980 0 return $self->_channel_sync($chan);
981 }
982  
983 2 ▶sub channel_creation_time {
Subroutine channel_creation_time: called CC=4 SCAR=15.2
Pod documented
984 2 my ($self, $chan) = @_;
985  
986 2 ▶ if (!defined $chan) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chan) 0 2 2
987 0 warn 'Channel is undefined';
988 0 return;
989 }
990  
991 2 my $map = $self->isupport('CASEMAPPING');
992 2 my $uchan = uc_irc($chan, $map);
993  
994 2 ▶ return if !$self->_channel_exists($chan);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_channel_exists($chan) 0 2 2
995 2 ▶ return if !exists $self->{STATE}{Chans}{ $uchan }{CreationTime};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"STATE"}{"Chans"}{$uchan}{"CreationTime"} 0 2 2
996  
997 2 return $self->{STATE}{Chans}{ $uchan }{CreationTime};
998 }
999  
1000 3 ▶sub channel_limit {
Subroutine channel_limit: called CC=5 SCAR=17.0
Pod documented
1001 3 my ($self, $chan) = @_;
1002  
1003 3 ▶ if (!defined $chan) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chan) 0 3 3
1004 0 warn 'Channel is undefined';
1005 0 return;
1006 }
1007  
1008 3 my $map = $self->isupport('CASEMAPPING');
1009 3 my $uchan = uc_irc($chan, $map);
1010  
1011 3 ▶ return if !$self->_channel_exists($chan);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_channel_exists($chan) 0 3 3
1012  
1013 3 ▶ if ( $self->is_channel_mode_set($chan, 'l')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_channel_mode_set($chan, "l") and defined $self->{"STATE"}{"Chans"}{$uchan}{"ModeArgs"}{"l"}) 1 2 3
Condition66%2/3
$self->is_channel_mode_set($chan, "l") and defined $self->{"STATE"}{"Chans"}{$uchan}{"ModeArgs"}{"l"}
!ll&&!rl&&r
201
MC/DC50%1/2
$self->is_channel_mode_set($chan, "l") and defined $self->{"STATE"}{"Chans"}{$uchan}{"ModeArgs"}{"l"}
$self->is_channel_mode_set($chan, "l") defined $self->{"STATE"}{"Chans"}{$uchan}{"ModeArgs"}{"l"}
Truth table66%2/3
A and B
A= $self->is_channel_mode_set($chan, "l")B= defined $self->{"STATE"}{"Chans"}{$uchan}{"ModeArgs"}{"l"}
ABresult
0X0
100
111
1014 && defined $self->{STATE}{Chans}{ $uchan }{ModeArgs}{l} ) {
1015 1 return $self->{STATE}{Chans}{ $uchan }{ModeArgs}{l};
1016 }
1017  
1018 2 return;
1019 }
1020  
1021 2 ▶sub channel_key {
Subroutine channel_key: called CC=5 SCAR=19.3
Pod documented
1022 2 my ($self, $chan) = @_;
1023  
1024 2 ▶ if (!defined $chan) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chan) 0 2 2
1025 0 warn 'Channel is undefined';
1026 0 return;
1027 }
1028  
1029 2 my $map = $self->isupport('CASEMAPPING');
1030 2 my $uchan = uc_irc($chan, $map);
1031 2 ▶ return if !$self->_channel_exists($chan);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_channel_exists($chan) 0 2 2
1032  
1033 2 ▶ if ( $self->is_channel_mode_set($chan, 'k')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_channel_mode_set($chan, "k") and defined $self->{"STATE"}{"Chans"}{$uchan}{"ModeArgs"}{"k"}) 0 2 2
Condition33%1/3
$self->is_channel_mode_set($chan, "k") and defined $self->{"STATE"}{"Chans"}{$uchan}{"ModeArgs"}{"k"}
!ll&&!rl&&r
200
MC/DC0%0/2
$self->is_channel_mode_set($chan, "k") and defined $self->{"STATE"}{"Chans"}{$uchan}{"ModeArgs"}{"k"}
$self->is_channel_mode_set($chan, "k") defined $self->{"STATE"}{"Chans"}{$uchan}{"ModeArgs"}{"k"}
Truth table33%1/3
A and B
A= $self->is_channel_mode_set($chan, "k")B= defined $self->{"STATE"}{"Chans"}{$uchan}{"ModeArgs"}{"k"}
ABresult
0X0
100
111
1034 && defined $self->{STATE}{Chans}{ $uchan }{ModeArgs}{k} ) {
1035 0 return $self->{STATE}{Chans}{ $uchan }{ModeArgs}{k};
1036 }
1037  
1038 2 return;
1039 }
1040  
1041 0 ▶sub channel_modes {
Subroutine channel_modes: not called CC=5 SCAR=34.0
Pod documented
1042 0 my ($self, $chan) = @_;
1043  
1044 0 ▶ if (!defined $chan) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chan) 0 0 0
1045 0 warn 'Channel is undefined';
1046 0 return;
1047 }
1048  
1049 0 my $map = $self->isupport('CASEMAPPING');
1050 0 my $uchan = uc_irc($chan, $map);
1051 0 ▶ return if !$self->_channel_exists($chan);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_channel_exists($chan) 0 0 0
1052  
1053 0 my %modes;
1054 0 ▶ if ( defined $self->{STATE}{Chans}{ $uchan }{Mode} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"STATE"}{"Chans"}{$uchan}{"Mode"}) 0 0 0
1055 0 %modes = map { ($_ => '') } split(//, $self->{STATE}{Chans}{ $uchan }{Mode});
1056 }
1057 0 ▶ if ( defined $self->{STATE}{Chans}{ $uchan }->{ModeArgs} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"STATE"}{"Chans"}{$uchan}{"ModeArgs"}) 0 0 0
1058 0 my %args = %{ $self->{STATE}{Chans}{ $uchan }{ModeArgs} };
1059 0 @modes{keys %args} = values %args;
1060 }
1061  
1062 0 return \%modes;
1063 }
1064  
1065 11 ▶sub is_channel_member {
Subroutine is_channel_member: called CC=6 SCAR=22.4
Pod documented
1066 11 my ($self, $chan, $nick) = @_;
1067  
1068 11 ▶ if (!defined $chan || !defined $nick) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chan and defined $nick) 0 11 11
Condition33%1/3
defined $chan and defined $nick
!ll&&!rl&&r
0011
MC/DC0%0/2
defined $chan and defined $nick
defined $chan defined $nick
Truth table33%1/3
A and B
A= defined $chanB= defined $nick
ABresult
0X0
100
111
1069 0 warn 'Channel or nickname is undefined';
1070 0 return;
1071 }
1072  
1073 11 my $map = $self->isupport('CASEMAPPING');
1074 11 my $uchan = uc_irc($chan, $map);
1075 11 my $unick = uc_irc($nick, $map);
1076  
1077 11 ▶ return if !$self->_channel_exists($chan) || !$self->_nick_exists($nick);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_channel_exists($chan) and $self->_nick_exists($nick) 0 11 11
Condition33%1/3
$self->_channel_exists($chan) and $self->_nick_exists($nick)
!ll&&!rl&&r
0011
MC/DC0%0/2
$self->_channel_exists($chan) and $self->_nick_exists($nick)
$self->_channel_exists($chan) $self->_nick_exists($nick)
Truth table33%1/3
A and B
A= $self->_channel_exists($chan)B= $self->_nick_exists($nick)
ABresult
0X0
100
111
1078 11 ▶ return 1 if defined $self->{STATE}{Chans}{ $uchan }{Nicks}{ $unick };
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"STATE"}{"Chans"}{$uchan}{"Nicks"}{$unick} 11 0 11
1079 0 return;
1080 }
1081  
1082 4 ▶sub is_channel_operator {
Subroutine is_channel_operator: called CC=4 SCAR=15.9
Pod documented
1083 4 my ($self, $chan, $nick) = @_;
1084  
1085 4 ▶ if (!defined $chan || !defined $nick) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chan and defined $nick) 0 4 4
Condition33%1/3
defined $chan and defined $nick
!ll&&!rl&&r
004
MC/DC0%0/2
defined $chan and defined $nick
defined $chan defined $nick
Truth table33%1/3
A and B
A= defined $chanB= defined $nick
ABresult
0X0
100
111
1086 0 warn 'Channel or nickname is undefined';
1087 0 return;
1088 }
1089  
1090 4 ▶ return 1 if $self->_nick_has_channel_mode($chan, $nick, 'o');
Branch: 1 branch
BranchTrueFalseTotal
if $self->_nick_has_channel_mode($chan, $nick, "o") 1 3 4
1091 3 return;
1092 }
1093  
1094 2 ▶sub has_channel_voice {
Subroutine has_channel_voice: called CC=4 SCAR=17.2
Pod documented
1095 2 my ($self, $chan, $nick) = @_;
1096  
1097 2 ▶ if (!defined $chan || !defined $nick) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chan and defined $nick) 0 2 2
Condition33%1/3
defined $chan and defined $nick
!ll&&!rl&&r
002
MC/DC0%0/2
defined $chan and defined $nick
defined $chan defined $nick
Truth table33%1/3
A and B
A= defined $chanB= defined $nick
ABresult
0X0
100
111
1098 0 warn 'Channel or nickname is undefined';
1099 0 return;
1100 }
1101  
1102 2 ▶ return 1 if $self->_nick_has_channel_mode($chan, $nick, 'v');
Branch: 1 branch
BranchTrueFalseTotal
if $self->_nick_has_channel_mode($chan, $nick, "v") 0 2 2
1103 2 return;
1104 }
1105  
1106 2 ▶sub is_channel_halfop {
Subroutine is_channel_halfop: called CC=4 SCAR=17.2
Pod documented
1107 2 my ($self, $chan, $nick) = @_;
1108  
1109 2 ▶ if (!defined $chan || !defined $nick) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chan and defined $nick) 0 2 2
Condition33%1/3
defined $chan and defined $nick
!ll&&!rl&&r
002
MC/DC0%0/2
defined $chan and defined $nick
defined $chan defined $nick
Truth table33%1/3
A and B
A= defined $chanB= defined $nick
ABresult
0X0
100
111
1110 0 warn 'Channel or nickname is undefined';
1111 0 return;
1112 }
1113  
1114 2 ▶ return 1 if $self->_nick_has_channel_mode($chan, $nick, 'h');
Branch: 1 branch
BranchTrueFalseTotal
if $self->_nick_has_channel_mode($chan, $nick, "h") 0 2 2
1115 2 return;
1116 }
1117  
1118 0 ▶sub is_channel_owner {
Subroutine is_channel_owner: not called CC=4 SCAR=30.0
Pod documented
1119 0 my ($self, $chan, $nick) = @_;
1120  
1121 0 ▶ if (!defined $chan || !defined $nick) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chan and defined $nick) 0 0 0
Condition0%0/3
defined $chan and defined $nick
!ll&&!rl&&r
000
MC/DC0%0/2
defined $chan and defined $nick
defined $chan defined $nick
Truth table0%0/3
A and B
A= defined $chanB= defined $nick
ABresult
0X0
100
111
1122 0 warn 'Channel or nickname is undefined';
1123 0 return;
1124 }
1125  
1126 0 ▶ return 1 if $self->_nick_has_channel_mode($chan, $nick, 'q');
Branch: 1 branch
BranchTrueFalseTotal
if $self->_nick_has_channel_mode($chan, $nick, "q") 0 0 0
1127 0 return;
1128 }
1129  
1130 0 ▶sub is_channel_admin {
Subroutine is_channel_admin: not called CC=4 SCAR=30.0
Pod documented
1131 0 my ($self, $chan, $nick) = @_;
1132  
1133 0 ▶ if (!defined $chan || !defined $nick) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chan and defined $nick) 0 0 0
Condition0%0/3
defined $chan and defined $nick
!ll&&!rl&&r
000
MC/DC0%0/2
defined $chan and defined $nick
defined $chan defined $nick
Truth table0%0/3
A and B
A= defined $chanB= defined $nick
ABresult
0X0
100
111
1134 0 warn 'Channel or nickname is undefined';
1135 0 return;
1136 }
1137  
1138 0 ▶ return 1 if $self->_nick_has_channel_mode($chan, $nick, 'a');
Branch: 1 branch
BranchTrueFalseTotal
if $self->_nick_has_channel_mode($chan, $nick, "a") 0 0 0
1139 0 return;
1140 }
1141  
1142 2 ▶sub ban_mask {
Subroutine ban_mask: called CC=6 SCAR=18.8
Pod documented
1143 2 my ($self, $chan, $mask) = @_;
1144  
1145 2 ▶ if (!defined $chan || !defined $mask) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chan and defined $mask) 0 2 2
Condition33%1/3
defined $chan and defined $mask
!ll&&!rl&&r
002
MC/DC0%0/2
defined $chan and defined $mask
defined $chan defined $mask
Truth table33%1/3
A and B
A= defined $chanB= defined $mask
ABresult
0X0
100
111
1146 0 warn 'Channel or mask is undefined';
1147 0 return;
1148 }
1149  
1150 2 my $map = $self->isupport('CASEMAPPING');
1151 2 $mask = normalize_mask($mask);
1152 2 my @result;
1153  
1154 2 ▶ return if !$self->_channel_exists($chan);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_channel_exists($chan) 0 2 2
1155  
1156 # Convert the mask from IRC to regex.
1157 2 $mask = uc_irc($mask, $map);
1158 2 $mask = quotemeta $mask;
1159 2 $mask =~ s/\\\*/[\x01-\xFF]{0,}/g;
1160 2 $mask =~ s/\\\?/[\x01-\xFF]{1,1}/g;
1161  
1162 2 for my $nick ( $self->channel_list($chan) ) {
1163 3 ▶ push @result, $nick if uc_irc($self->nick_long_form($nick)) =~ /^$mask$/;
Branch: 1 branch
BranchTrueFalseTotal
if uc_irc($self->nick_long_form($nick)) =~ /^$mask$/ 2 1 3
1164 }
1165  
1166 2 return @result;
1167 }
1168  
1169  
1170 0 ▶sub channel_ban_list {
Subroutine channel_ban_list: not called CC=4 SCAR=30.0
Pod documented
1171 0 my ($self, $chan) = @_;
1172  
1173 0 ▶ if (!defined $chan) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chan) 0 0 0
1174 0 warn 'Channel is undefined';
1175 0 return;
1176 }
1177  
1178 0 my $map = $self->isupport('CASEMAPPING');
1179 0 my $uchan = uc_irc($chan, $map);
1180 0 my %result;
1181  
1182 0 ▶ return if !$self->_channel_exists($chan);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_channel_exists($chan) 0 0 0
1183  
1184 0 ▶ if ( defined $self->{STATE}{Chans}{ $uchan }{Lists}{b} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"STATE"}{"Chans"}{$uchan}{"Lists"}{"b"}) 0 0 0
1185 0 %result = %{ $self->{STATE}{Chans}{ $uchan }{Lists}{b} };
1186 }
1187  
1188 0 return \%result;
1189 }
1190  
1191 0 ▶sub channel_except_list {
Subroutine channel_except_list: not called CC=4 SCAR=30.0
Pod documented
1192 0 my ($self, $chan) = @_;
1193  
1194 0 ▶ if (!defined $chan) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chan) 0 0 0
1195 0 warn 'Channel is undefined';
1196 0 return;
1197 }
1198  
1199 0 my $map = $self->isupport('CASEMAPPING');
1200 0 my $uchan = uc_irc($chan, $map);
1201 0 my $excepts = $self->isupport('EXCEPTS');
1202 0 my %result;
1203  
1204 0 ▶ return if !$self->_channel_exists($chan);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_channel_exists($chan) 0 0 0
1205  
1206 0 ▶ if ( defined $self->{STATE}{Chans}{ $uchan }{Lists}{ $excepts } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"STATE"}{"Chans"}{$uchan}{"Lists"}{$excepts}) 0 0 0
1207 0 %result = %{ $self->{STATE}{Chans}{ $uchan }{Lists}{ $excepts } };
1208 }
1209  
1210 0 return \%result;
1211 }
1212  
1213 0 ▶sub channel_invex_list {
Subroutine channel_invex_list: not called CC=4 SCAR=30.0
Pod documented
1214 0 my ($self, $chan) = @_;
1215  
1216 0 ▶ if (!defined $chan) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chan) 0 0 0
1217 0 warn 'Channel is undefined';
1218 0 return;
1219 }
1220  
1221 0 my $map = $self->isupport('CASEMAPPING');
1222 0 my $uchan = uc_irc($chan, $map);
1223 0 my $invex = $self->isupport('INVEX');
1224 0 my %result;
1225  
1226 0 ▶ return if !$self->_channel_exists($chan);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_channel_exists($chan) 0 0 0
1227  
1228 0 ▶ if ( defined $self->{STATE}{Chans}{ $uchan }{Lists}{ $invex } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"STATE"}{"Chans"}{$uchan}{"Lists"}{$invex}) 0 0 0
1229 0 %result = %{ $self->{STATE}{Chans}{ $uchan }{Lists}{ $invex } };
1230 }
1231  
1232 0 return \%result;
1233 }
1234  
1235 2 ▶sub channel_topic {
Subroutine channel_topic: called CC=4 SCAR=14.3
Pod documented
1236 2 my ($self, $chan) = @_;
1237  
1238 2 ▶ if (!defined $chan) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chan) 0 2 2
1239 0 warn 'Channel is undefined';
1240 0 return;
1241 }
1242  
1243 2 my $map = $self->isupport('CASEMAPPING');
1244 2 my $uchan = uc_irc($chan, $map);
1245 2 my %result;
1246  
1247 2 ▶ return if !$self->_channel_exists($chan);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_channel_exists($chan) 0 2 2
1248  
1249 2 ▶ if ( defined $self->{STATE}{Chans}{ $uchan }{Topic} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"STATE"}{"Chans"}{$uchan}{"Topic"}) 1 1 2
1250 1 %result = %{ $self->{STATE}{Chans}{ $uchan }{Topic} };
1251 }
1252  
1253 2 return \%result;
1254 }
1255  
1256 0 ▶sub channel_url {
Subroutine channel_url: not called CC=3 SCAR=24.8
Pod documented
1257 0 my ($self, $chan) = @_;
1258  
1259 0 ▶ if (!defined $chan) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chan) 0 0 0
1260 0 warn 'Channel is undefined';
1261 0 return;
1262 }
1263  
1264 0 my $map = $self->isupport('CASEMAPPING');
1265 0 my $uchan = uc_irc($chan, $map);
1266  
1267 0 ▶ return if !$self->_channel_exists($chan);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_channel_exists($chan) 0 0 0
1268 0 return $self->{STATE}{Chans}{ $uchan }{Url};
1269 }
1270  
1271 0 ▶sub nick_channel_modes {
Subroutine nick_channel_modes: not called CC=4 SCAR=30.0
Pod documented
1272 0 my ($self, $chan, $nick) = @_;
1273  
1274 0 ▶ if (!defined $chan || !defined $nick) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chan and defined $nick) 0 0 0
Condition0%0/3
defined $chan and defined $nick
!ll&&!rl&&r
000
MC/DC0%0/2
defined $chan and defined $nick
defined $chan defined $nick
Truth table0%0/3
A and B
A= defined $chanB= defined $nick
ABresult
0X0
100
111
1275 0 warn 'Channel or nick is undefined';
1276 0 return;
1277 }
1278  
1279 0 my $map = $self->isupport('CASEMAPPING');
1280 0 my $uchan = uc_irc($chan, $map);
1281 0 my $unick = uc_irc($nick, $map);
1282  
1283 0 ▶ return if !$self->is_channel_member($chan, $nick);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_channel_member($chan, $nick) 0 0 0
1284  
1285 0 return $self->{STATE}{Nicks}{ $unick }{CHANS}{ $uchan };
1286 }
1287  
1288 21 1;
1289  
1290 =encoding utf8
1291  
1292 =head1 NAME
1293  
1294 POE::Component::IRC::State - A fully event-driven IRC client module with
1295 nickname and channel tracking
1296  
1297 =head1 SYNOPSIS
1298  
1299 # A simple Rot13 'encryption' bot
1300  
1301 use strict;
1302 use warnings;
1303 use POE qw(Component::IRC::State);
1304  
1305 my $nickname = 'Flibble' . $$;
1306 my $ircname = 'Flibble the Sailor Bot';
1307 my $ircserver = 'irc.blahblahblah.irc';
1308 my $port = 6667;
1309  
1310 my @channels = ( '#Blah', '#Foo', '#Bar' );
1311  
1312 # We create a new PoCo-IRC object and component.
1313 my $irc = POE::Component::IRC::State->spawn(
1314 nick => $nickname,
1315 server => $ircserver,
1316 port => $port,
1317 ircname => $ircname,
1318 ) or die "Oh noooo! $!";
1319  
1320 POE::Session->create(
1321 package_states => [
1322 main => [ qw(_default _start irc_001 irc_public) ],
1323 ],
1324 heap => { irc => $irc },
1325 );
1326  
1327 $poe_kernel->run();
1328  
1329 sub _start {
1330 my ($kernel, $heap) = @_[KERNEL, HEAP];
1331  
1332 # We get the session ID of the component from the object
1333 # and register and connect to the specified server.
1334 my $irc_session = $heap->{irc}->session_id();
1335 $kernel->post( $irc_session => register => 'all' );
1336 $kernel->post( $irc_session => connect => { } );
1337 return;
1338 }
1339  
1340 sub irc_001 {
1341 my ($kernel, $sender) = @_[KERNEL, SENDER];
1342  
1343 # Get the component's object at any time by accessing the heap of
1344 # the SENDER
1345 my $poco_object = $sender->get_heap();
1346 print "Connected to ", $poco_object->server_name(), "\n";
1347  
1348 # In any irc_* events SENDER will be the PoCo-IRC session
1349 $kernel->post( $sender => join => $_ ) for @channels;
1350 return;
1351 }
1352  
1353 sub irc_public {
1354 my ($kernel ,$sender, $who, $where, $what) = @_[KERNEL, SENDER, ARG0 .. ARG2];
1355 my $nick = ( split /!/, $who )[0];
1356 my $channel = $where->[0];
1357 my $poco_object = $sender->get_heap();
1358  
1359 if ( my ($rot13) = $what =~ /^rot13 (.+)/ ) {
1360 # Only operators can issue a rot13 command to us.
1361 return if !$poco_object->is_channel_operator( $channel, $nick );
1362  
1363 $rot13 =~ tr[a-zA-Z][n-za-mN-ZA-M];
1364 $kernel->post( $sender => privmsg => $channel => "$nick: $rot13" );
1365 }
1366 return;
1367 }
1368  
1369 # We registered for all events, this will produce some debug info.
1370 sub _default {
1371 my ($event, $args) = @_[ARG0 .. $#_];
1372 my @output = ( "$event: " );
1373  
1374 for my $arg ( @$args ) {
1375 if (ref $arg eq 'ARRAY') {
1376 push( @output, '[' . join(', ', @$arg ) . ']' );
1377 }
1378 else {
1379 push ( @output, "'$arg'" );
1380 }
1381 }
1382 print join ' ', @output, "\n";
1383 return 0;
1384 }
1385  
1386 =head1 DESCRIPTION
1387  
1388 POE::Component::IRC::State is a sub-class of L<POE::Component::IRC|POE::Component::IRC>
1389 which tracks IRC state entities such as nicks and channels. See the
1390 documentation for L<POE::Component::IRC|POE::Component::IRC> for general usage.
1391 This document covers the extra methods that POE::Component::IRC::State provides.
1392  
1393 The component tracks channels and nicks, so that it always has a current
1394 snapshot of what channels it is on and who else is on those channels. The
1395 returned object provides methods to query the collected state.
1396  
1397 =head1 CONSTRUCTORS
1398  
1399 POE::Component::IRC::State's constructors, and its C<connect> event, all
1400 take the same arguments as L<POE::Component::IRC|POE::Component::IRC> does, as
1401 well as two additional ones:
1402  
1403 B<'AwayPoll'>, the interval (in seconds) in which to poll (i.e. C<WHO #channel>)
1404 the away status of channel members. Defaults to 0 (disabled). If enabled, you
1405 will receive C<irc_away_sync_*> / L<C<irc_user_away>|/irc_user_away> /
1406 L<C<irc_user_back>|/irc_user_back> events, and will be able to use the
1407 L<C<is_away>|/is_away> method for users other than yourself. This can cause
1408 a lot of increase in traffic, especially if you are on big channels, so if you
1409 do use this, you probably don't want to set it too low. For reference, X-Chat
1410 uses 300 seconds (5 minutes).
1411  
1412 B<'WhoJoiners'>, a boolean indicating whether the component should send a
1413 C<WHO nick> for every person which joins a channel. Defaults to on
1414 (the C<WHO> is sent). If you turn this off, L<C<is_operator>|/is_operator>
1415 will not work and L<C<nick_info>|/nick_info> will only return the keys
1416 B<'Nick'>, B<'User'>, B<'Host'> and B<'Userhost'>.
1417  
1418 =head1 METHODS
1419  
1420 All of the L<POE::Component::IRC|POE::Component::IRC> methods are supported,
1421 plus the following:
1422  
1423 =head2 C<ban_mask>
1424  
1425 Expects a channel and a ban mask, as passed to MODE +b-b. Returns a list of
1426 nicks on that channel that match the specified ban mask or an empty list if
1427 the channel doesn't exist in the state or there are no matches.
1428  
1429 =head2 C<channel_ban_list>
1430  
1431 Expects a channel as a parameter. Returns a hashref containing the banlist
1432 if the channel is in the state, a false value if not. The hashref keys are the
1433 entries on the list, each with the keys B<'SetBy'> and B<'SetAt'>. These keys
1434 will hold the nick!hostmask of the user who set the entry (or just the nick
1435 if it's all the ircd gives us), and the time at which it was set respectively.
1436  
1437 =head2 C<channel_creation_time>
1438  
1439 Expects a channel as parameter. Returns channel creation time or a false value.
1440  
1441 =head2 C<channel_except_list>
1442  
1443 Expects a channel as a parameter. Returns a hashref containing the ban
1444 exception list if the channel is in the state, a false value if not. The
1445 hashref keys are the entries on the list, each with the keys B<'SetBy'> and
1446 B<'SetAt'>. These keys will hold the nick!hostmask of the user who set the
1447 entry (or just the nick if it's all the ircd gives us), and the time at which
1448 it was set respectively.
1449  
1450 =head2 C<channel_invex_list>
1451  
1452 Expects a channel as a parameter. Returns a hashref containing the invite
1453 exception list if the channel is in the state, a false value if not. The
1454 hashref keys are the entries on the list, each with the keys B<'SetBy'> and
1455 B<'SetAt'>. These keys will hold the nick!hostmask of the user who set the
1456 entry (or just the nick if it's all the ircd gives us), and the time at which
1457 it was set respectively.
1458  
1459 =head2 C<channel_key>
1460  
1461 Expects a channel as parameter. Returns the channel key or a false value.
1462  
1463 =head2 C<channel_limit>
1464  
1465 Expects a channel as parameter. Returns the channel limit or a false value.
1466  
1467 =head2 C<channel_list>
1468  
1469 Expects a channel as parameter. Returns a list of all nicks on the specified
1470 channel. If the component happens to not be on that channel an empty list will
1471 be returned.
1472  
1473 =head2 C<channel_modes>
1474  
1475 Expects a channel as parameter. Returns a hash ref keyed on channel mode, with
1476 the mode argument (if any) as the value. Returns a false value instead if the
1477 channel is not in the state.
1478  
1479 =head2 C<channels>
1480  
1481 Takes no parameters. Returns a hashref, keyed on channel name and whether the
1482 bot is operator, halfop or
1483 has voice on that channel.
1484  
1485 for my $channel ( keys %{ $irc->channels() } ) {
1486 $irc->yield( 'privmsg' => $channel => 'm00!' );
1487 }
1488  
1489 =head2 C<channel_topic>
1490  
1491 Expects a channel as a parameter. Returns a hashref containing topic
1492 information if the channel is in the state, a false value if not. The hashref
1493 contains the following keys: B<'Value'>, B<'SetBy'>, B<'SetAt'>. These keys
1494 will hold the topic itself, the nick!hostmask of the user who set it (or just
1495 the nick if it's all the ircd gives us), and the time at which it was set
1496 respectively.
1497  
1498 If the component happens to not be on the channel, nothing will be returned.
1499  
1500 =head2 C<channel_url>
1501  
1502 Expects a channel as a parameter. Returns the channel's URL. If the channel
1503 has no URL or the component is not on the channel, nothing will be returned.
1504  
1505 =head2 C<has_channel_voice>
1506  
1507 Expects a channel and a nickname as parameters. Returns a true value if
1508 the nick has voice on the specified channel. Returns false if the nick does
1509 not have voice on the channel or if the nick/channel does not exist in the state.
1510  
1511 =head2 C<is_away>
1512  
1513 Expects a nick as parameter. Returns a true value if the specified nick is away.
1514 Returns a false value if the nick is not away or not in the state. This will
1515 only work for your IRC user unless you specified a value for B<'AwayPoll'> in
1516 L<C<spawn>|POE::Component::IRC/spawn>.
1517  
1518 =head2 C<is_channel_admin>
1519  
1520 Expects a channel and a nickname as parameters. Returns a true value if
1521 the nick is an admin on the specified channel. Returns false if the nick is
1522 not an admin on the channel or if the nick/channel does not exist in the state.
1523  
1524 =head2 C<is_channel_halfop>
1525  
1526 Expects a channel and a nickname as parameters. Returns a true value if
1527 the nick is a half-operator on the specified channel. Returns false if the nick
1528 is not a half-operator on the channel or if the nick/channel does not exist in
1529 the state.
1530  
1531 =head2 C<is_channel_member>
1532  
1533 Expects a channel and a nickname as parameters. Returns a true value if
1534 the nick is on the specified channel. Returns false if the nick is not on the
1535 channel or if the nick/channel does not exist in the state.
1536  
1537 =head2 C<is_channel_mode_set>
1538  
1539 Expects a channel and a single mode flag C<[A-Za-z]>. Returns a true value
1540 if that mode is set on the channel.
1541  
1542 =head2 C<is_channel_operator>
1543  
1544 Expects a channel and a nickname as parameters. Returns a true value if
1545 the nick is an operator on the specified channel. Returns false if the nick is
1546 not an operator on the channel or if the nick/channel does not exist in the state.
1547  
1548 =head2 C<is_channel_owner>
1549  
1550 Expects a channel and a nickname as parameters. Returns a true value if
1551 the nick is an owner on the specified channel. Returns false if the nick is
1552 not an owner on the channel or if the nick/channel does not exist in the state.
1553  
1554 =head2 C<is_channel_synced>
1555  
1556 Expects a channel as a parameter. Returns true if the channel has been synced.
1557 Returns false if it has not been synced or if the channel is not in the state.
1558  
1559 =head2 C<is_operator>
1560  
1561 Expects a nick as parameter. Returns a true value if the specified nick is
1562 an IRC operator. Returns a false value if the nick is not an IRC operator
1563 or is not in the state.
1564  
1565 =head2 C<is_user_mode_set>
1566  
1567 Expects single user mode flag C<[A-Za-z]>. Returns a true value if that user
1568 mode is set.
1569  
1570 =head2 C<nick_channel_modes>
1571  
1572 Expects a channel and a nickname as parameters. Returns the modes of the
1573 specified nick on the specified channel (ie. qaohv). If the nick is not on the
1574 channel in the state, a false value will be returned.
1575  
1576 =head2 C<nick_channels>
1577  
1578 Expects a nickname. Returns a list of the channels that that nickname and the
1579 component are on. An empty list will be returned if the nickname does not
1580 exist in the state.
1581  
1582 =head2 C<nick_info>
1583  
1584 Expects a nickname. Returns a hashref containing similar information to that
1585 returned by WHOIS. Returns a false value if the nickname doesn't exist in the
1586 state. The hashref contains the following keys:
1587  
1588 B<'Nick'>, B<'User'>, B<'Host'>, B<'Userhost'>, B<'Hops'>, B<'Real'>,
1589 B<'Server'> and, if applicable, B<'IRCop'>.
1590  
1591 =head2 C<nick_long_form>
1592  
1593 Expects a nickname. Returns the long form of that nickname, ie. C<nick!user@host>
1594 or a false value if the nick is not in the state.
1595  
1596 =head2 C<nicks>
1597  
1598 Takes no parameters. Returns a list of all the nicks, including itself, that it
1599 knows about. If the component happens to be on no channels then an empty list
1600 is returned.
1601  
1602 =head2 C<umode>
1603  
1604 Takes no parameters. Returns the current user mode set for the bot.
1605  
1606 =head1 OUTPUT EVENTS
1607  
1608 =head2 Augmented events
1609  
1610 New parameters are added to the following
1611 L<POE::Component::IRC|POE::Component::IRC> events.
1612  
1613 =head3 C<irc_quit>
1614  
1615 See also L<C<irc_quit>|POE::Component::IRC/irc_quit> in
1616 L<POE::Component::IRC|POE::Component::IRC>.
1617  
1618 Additional parameter C<ARG2> contains an arrayref of channel names that are
1619 common to the quitting client and the component.
1620  
1621 =head3 C<irc_nick>
1622  
1623 See also L<C<irc_nick>|POE::Component::IRC/irc_nick> in
1624 L<POE::Component::IRC|POE::Component::IRC>.
1625  
1626 Additional parameter C<ARG2> contains an arrayref of channel names that are
1627 common to the nick hanging client and the component.
1628  
1629 =head3 C<irc_kick>
1630  
1631 See also L<C<irc_kick>|POE::Component::IRC/irc_kick> in
1632 L<POE::Component::IRC|POE::Component::IRC>.
1633  
1634 Additional parameter C<ARG4> contains the full nick!user@host of the kicked
1635 individual.
1636  
1637 =head3 C<irc_topic>
1638  
1639 See also L<C<irc_kick>|POE::Component::IRC/irc_kick> in
1640 L<POE::Component::IRC|POE::Component::IRC>.
1641  
1642 Additional parameter C<ARG3> contains the old topic hashref, like the one
1643 returned by L<C<channel_topic>|/channel_topic>.
1644  
1645 =head3 C<irc_disconnected>
1646  
1647 =head3 C<irc_error>
1648  
1649 =head3 C<irc_socketerr>
1650  
1651 These three all have two additional parameters. C<ARG1> is a hash of
1652 information about your IRC user (see L<C<nick_info>|/nick_info>), while
1653 C<ARG2> is a hash of the channels you were on (see
1654 L<C<channels>|/channels>).
1655  
1656 =head2 New events
1657  
1658 As well as all the usual L<POE::Component::IRC|POE::Component::IRC> C<irc_*>
1659 events, there are the following events you can register for:
1660  
1661 =head3 C<irc_away_sync_start>
1662  
1663 Sent whenever the component starts to synchronise the away statuses of channel
1664 members. C<ARG0> is the channel name. You will only receive this event if you
1665 specified a value for B<'AwayPoll'> in L<C<spawn>|POE::Component::IRC/spawn>.
1666  
1667 =head3 C<irc_away_sync_end>
1668  
1669 Sent whenever the component has completed synchronising the away statuses of
1670 channel members. C<ARG0> is the channel name. You will only receive this event if
1671 you specified a value for B<'AwayPoll'> in L<C<spawn>|POE::Component::IRC/spawn>.
1672  
1673 =head3 C<irc_chan_mode>
1674  
1675 This is almost identical to L<C<irc_mode>|POE::Component::IRC/irc_mode>,
1676 except that it's sent once for each individual mode with it's respective
1677 argument if it has one (ie. the banmask if it's +b or -b). However, this
1678 event is only sent for channel modes.
1679  
1680 =head3 C<irc_chan_sync>
1681  
1682 Sent whenever the component has completed synchronising a channel that it has
1683 joined. C<ARG0> is the channel name and C<ARG1> is the time in seconds that
1684 the channel took to synchronise.
1685  
1686 =head3 C<irc_chan_sync_invex>
1687  
1688 Sent whenever the component has completed synchronising a channel's INVEX
1689 (invite list). Usually triggered by the component being opped on a channel.
1690 C<ARG0> is the channel name.
1691  
1692 =head3 C<irc_chan_sync_excepts>
1693  
1694 Sent whenever the component has completed synchronising a channel's EXCEPTS
1695 (ban exemption list). Usually triggered by the component being opped on a
1696 channel. C<ARG0> is the channel.
1697  
1698 =head3 C<irc_nick_sync>
1699  
1700 Sent whenever the component has completed synchronising a user who has joined
1701 a channel the component is on. C<ARG0> is the user's nickname and C<ARG1> the
1702 channel they have joined.
1703  
1704 =head3 C<irc_user_away>
1705  
1706 Sent when an IRC user sets his/her status to away. C<ARG0> is the nickname,
1707 C<ARG1> is an arrayref of channel names that are common to the nickname
1708 and the component. You will only receive this event if you specified a value
1709 for B<'AwayPoll'> in L<C<spawn>|POE::Component::IRC/spawn>.
1710  
1711 B<Note:> This above is only for users I<other than yourself>. To know when you
1712 change your own away status, register for the C<irc_305> and C<irc_306> events.
1713  
1714 =head3 C<irc_user_back>
1715  
1716 Sent when an IRC user unsets his/her away status. C<ARG0> is the nickname,
1717 C<ARG1> is an arrayref of channel names that are common to the nickname and
1718 the component. You will only receive this event if you specified a value for
1719 B<'AwayPoll'> in L<C<spawn>|POE::Component::IRC/spawn>.
1720  
1721 B<Note:> This above is only for users I<other than yourself>. To know when you
1722 change your own away status, register for the C<irc_305> and C<irc_306> events.
1723  
1724 =head3 C<irc_user_mode>
1725  
1726 This is almost identical to L<C<irc_mode>|POE::Component::IRC/irc_mode>,
1727 except it is sent for each individual umode that is being set.
1728  
1729 =head1 CAVEATS
1730  
1731 The component gathers information by registering for C<irc_quit>, C<irc_nick>,
1732 C<irc_join>, C<irc_part>, C<irc_mode>, C<irc_kick> and various numeric replies.
1733 When the component is asked to join a channel, when it joins it will issue
1734 'WHO #channel', 'MODE #channel', and 'MODE #channel b'. These will solicit
1735 between them the numerics, C<irc_352>, C<irc_324> and C<irc_329>, respectively.
1736 When someone joins a channel the bot is on, it issues a 'WHO nick'. You may
1737 want to ignore these.
1738  
1739 Currently, whenever the component sees a topic or channel list change, it will
1740 use C<time> for the SetAt value and the full address of the user who set it
1741 for the SetBy value. When an ircd gives us its record of such changes, it will
1742 use its own time (obviously) and may only give us the nickname of the user,
1743 rather than their full address. Thus, if our C<time> and the ircd's time do
1744 not match, or the ircd uses the nickname only, ugly inconsistencies can develop.
1745 This leaves the B<'SetAt'> and B<'SetBy'> values inaccurate at best, and you
1746 should use them with this in mind (for now, at least).
1747  
1748 =head1 AUTHOR
1749  
1750 Chris Williams <chris@bingosnet.co.uk>
1751  
1752 With contributions from Lyndon Miller.
1753  
1754 =head1 LICENCE
1755  
1756 This module may be used, modified, and distributed under the same
1757 terms as Perl itself. Please see the license that came with your Perl
1758 distribution for details.
1759  
1760 =head1 SEE ALSO
1761  
1762 L<POE::Component::IRC|POE::Component::IRC>
1763  
1764 L<POE::Component::IRC::Qnet::State|POE::Component::IRC::Qnet::State>
1765  
1766 =cut
« Component/IRC/Plugin/Console.pm ↑ Summary Component/IRC/Plugin/Proxy.pm »