| 1 | # You may distribute under the terms of either the GNU General Public License | ||||||||||||||||||||||||||
| 2 | # or the Artistic License (the same terms as Perl itself) | ||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||
| 4 | # (C) Paul Evans, 2010-2014 -- leonerd@leonerd.org.uk | ||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||
| 6 | package Protocol::IRC::Client; | ||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||
| 8 | 10 | ▶ | use strict; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 9 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 10 | 10 | ▶ | use 5.010; # // | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 11 | 10 | ▶ | use base qw( Protocol::IRC ); | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||
| 13 | 10 | our $VERSION = '0.10'; | |||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||
| 15 | 10 | ▶ | use Carp; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||
| 17 | =head1 NAME | ||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||
| 19 | C<Protocol::IRC::Client> - IRC protocol handling for a client | ||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||
| 21 | =head1 DESCRIPTION | ||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||
| 23 | This mix-in class provides a layer of IRC message handling logic suitable for | ||||||||||||||||||||||||||
| 24 | an IRC client. It builds upon L<Protocol::IRC> to provide extra message | ||||||||||||||||||||||||||
| 25 | processing useful to IRC clients, such as handling inbound server numerics. | ||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||
| 27 | It provides some of the methods required by C<Protocol::IRC>: | ||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||
| 29 | =over 4 | ||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||
| 31 | =item * isupport | ||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||
| 33 | =back | ||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||
| 35 | =cut | ||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||
| 37 | =head1 METHODS | ||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||
| 39 | =cut | ||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||
| 41 | =head2 $value = $irc->isupport( $key ) | ||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||
| 43 | Returns an item of information from the server's C<005 ISUPPORT> lines. | ||||||||||||||||||||||||||
| 44 | Traditionally IRC servers use all-capital names for keys. | ||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||
| 46 | =cut | ||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||
| 48 | # A few hardcoded defaults from RFC 2812 | ||||||||||||||||||||||||||
| 49 | 10 | my %ISUPPORT = ( | |||||||||||||||||||||||||
| 50 | channame_re => qr/^[#&]/, | ||||||||||||||||||||||||||
| 51 | prefixflag_re => qr/^[\@+]/, | ||||||||||||||||||||||||||
| 52 | chanmodes_list => [qw( b k l imnpst )], # TODO: ov | ||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||
| 55 | sub isupport | ||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||
| 57 | 236 | ▶ | my $self = shift; | ||||||||||||||||||||||||
|
Subroutine
isupport: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 58 | 236 | my ( $field ) = @_; | |||||||||||||||||||||||||
| 59 | 236 | ▶ | return $self->{Protocol_IRC_isupport}->{$field} // $ISUPPORT{$field}; | ||||||||||||||||||||||||
|
Condition100%3/3
$self->{"Protocol_IRC_isupport"}{$field} // $ISUPPORT{$field}
MC/DC100%2/2
$self->{"Protocol_IRC_isupport"}{$field} // $ISUPPORT{$field}
$self->{"Protocol_IRC_isupport"}{$field}
$ISUPPORT{$field}
Truth table100%3/3
A // B
A= $self->{"Protocol_IRC_isupport"}{$field}B= $ISUPPORT{$field}
| |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||
| 62 | sub on_message_RPL_ISUPPORT | ||||||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||||||
| 64 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||
|
Subroutine
on_message_RPL_ISUPPORT: called CC=10 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||
| 65 | 2 | my ( $message, $hints ) = @_; | |||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||
| 67 | 2 | ▶ | my $isupport = $self->{Protocol_IRC_isupport} ||= {}; | ||||||||||||||||||||||||
|
Condition50%1/2
$self->{"Protocol_IRC_isupport"} ||= {}
MC/DC0%0/1
$self->{"Protocol_IRC_isupport"} ||= {}
$self->{"Protocol_IRC_isupport"}
Truth table50%1/2
A
A= $self->{"Protocol_IRC_isupport"}
| |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||
| 69 | 2 | foreach my $entry ( @{ $hints->{isupport} } ) { | |||||||||||||||||||||||||
| 70 | 9 | my ( $name, $value ) = $entry =~ m/^([A-Z]+)(?:=(.*))?$/; | |||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||
| 72 | 9 | ▶ | $value = 1 if !defined $value; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||
| 74 | 9 | $isupport->{$name} = $value; | |||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||
| 76 | 9 | ▶ | if( $name eq "PREFIX" ) { | ||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||
| 77 | 2 | my $prefix = $value; | |||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||
| 79 | 2 | ▶ | my ( $prefix_modes, $prefix_flags ) = $prefix =~ m/^\(([a-z]+)\)(.+)$/i | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 80 | or warn( "Unable to parse PREFIX=$value" ), next; | ||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||
| 82 | 2 | $isupport->{prefix_modes} = $prefix_modes; | |||||||||||||||||||||||||
| 83 | 2 | $isupport->{prefix_flags} = $prefix_flags; | |||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||
| 85 | 2 | $isupport->{prefixflag_re} = qr/[$prefix_flags]/; | |||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||
| 87 | 2 | my %prefix_map; | |||||||||||||||||||||||||
| 88 | 2 | $prefix_map{substr $prefix_modes, $_, 1} = substr $prefix_flags, $_, 1 for ( 0 .. length($prefix_modes) - 1 ); | |||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||
| 90 | 2 | $isupport->{prefix_map_m2f} = \%prefix_map; | |||||||||||||||||||||||||
| 91 | 2 | $isupport->{prefix_map_f2m} = { reverse %prefix_map }; | |||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||
| 93 | elsif( $name eq "CHANMODES" ) { | ||||||||||||||||||||||||||
| 94 | 2 | $isupport->{chanmodes_list} = [ split( m/,/, $value ) ]; | |||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||
| 96 | elsif( $name eq "CASEMAPPING" ) { | ||||||||||||||||||||||||||
| 97 | # TODO | ||||||||||||||||||||||||||
| 98 | # $self->{nick_folded} = $self->casefold_name( $self->{nick} ); | ||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||
| 100 | elsif( $name eq "CHANTYPES" ) { | ||||||||||||||||||||||||||
| 101 | 1 | $isupport->{channame_re} = qr/^[$value]/; | |||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||
| 105 | 2 | return 0; | |||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||
| 108 | =head2 $info = $irc->server_info( $key ) | ||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||
| 110 | Returns an item of information from the server's C<004> line. C<$key> should | ||||||||||||||||||||||||||
| 111 | one of | ||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||
| 113 | =over 8 | ||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||
| 115 | =item * host | ||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||
| 117 | =item * version | ||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||
| 119 | =item * usermodes | ||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||
| 121 | =item * channelmodes | ||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||
| 123 | =back | ||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||
| 125 | =cut | ||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||
| 127 | sub server_info | ||||||||||||||||||||||||||
| 128 | { | ||||||||||||||||||||||||||
| 129 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||
|
Subroutine
server_info: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||
| 130 | 1 | my ( $key ) = @_; | |||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||
| 132 | 1 | return $self->{Protocol_IRC_server_info}{$key}; | |||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||
| 135 | sub on_message_RPL_MYINFO | ||||||||||||||||||||||||||
| 136 | { | ||||||||||||||||||||||||||
| 137 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||
|
Subroutine
on_message_RPL_MYINFO: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||
| 138 | 1 | my ( $message, $hints ) = @_; | |||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||
| 140 | 1 | @{$self->{Protocol_IRC_server_info}}{qw( host version usermodes channelmodes )} = | |||||||||||||||||||||||||
| 141 | 1 | @{$hints}{qw( serverhost serverversion usermodes channelmodes )}; | |||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||
| 143 | 1 | return 0; | |||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||
| 146 | =head1 GATING MESSAGES | ||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||
| 148 | If messages with a gating disposition are received, extra processing is | ||||||||||||||||||||||||||
| 149 | applied. Messages whose gating effect is C<more> are simply collected up by | ||||||||||||||||||||||||||
| 150 | pushing the hints hash to an array. Added to this hash is the command name | ||||||||||||||||||||||||||
| 151 | itself, so that in the case of multiple message types (for example C<WHOIS> | ||||||||||||||||||||||||||
| 152 | replies) the individual messages can still be identified. | ||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||
| 154 | When the effect of C<done> or C<fail> is eventually received, this collected | ||||||||||||||||||||||||||
| 155 | array is passed as C<$data> to a handler in one of the following places: | ||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||
| 157 | =over 4 | ||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||
| 159 | =item 1. | ||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||
| 161 | A method called C<on_gate_EFFECT_GATE> | ||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||
| 163 | $client->on_gate_EFFECT_GATE( $message, $hints, $data ) | ||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||
| 165 | =item 2. | ||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||
| 167 | A method called C<on_gate_EFFECT> | ||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||
| 169 | $client->on_gate_EFFECT( 'GATE', $message, $hints, $data ) | ||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||
| 171 | =item 3. | ||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||
| 173 | A method called C<on_gate> | ||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||
| 175 | $client->on_gate( 'EFFECT, 'GATE', $message, $hints, $data ) | ||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||
| 177 | =back | ||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||
| 179 | =cut | ||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||
| 181 | sub on_message_gate | ||||||||||||||||||||||||||
| 182 | { | ||||||||||||||||||||||||||
| 183 | 15 | ▶ | my $self = shift; | ||||||||||||||||||||||||
|
Subroutine
on_message_gate: called CC=7 SCAR=19.7
Pod
undocumented
| |||||||||||||||||||||||||||
| 184 | 15 | my ( $effect, $gate, $message, $hints ) = @_; | |||||||||||||||||||||||||
| 185 | 15 | ▶ | my $target = $hints->{target_name_folded} // "*"; | ||||||||||||||||||||||||
|
Condition100%2/2
$hints->{"target_name_folded"} // "*"
MC/DC100%1/1
$hints->{"target_name_folded"} // "*"
$hints->{"target_name_folded"}
Truth table100%2/2
A
A= $hints->{"target_name_folded"}
| |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||
| 187 | 15 | ▶ | if( $effect eq "more" ) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 188 | 10 | push @{ $self->{Protocol_IRC_gate}{$target}{$gate} }, { | |||||||||||||||||||||||||
| 189 | %$hints, | ||||||||||||||||||||||||||
| 190 | command => $message->command_name, | ||||||||||||||||||||||||||
| 191 | }; | ||||||||||||||||||||||||||
| 192 | 10 | return 1; | |||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||
| 195 | 5 | my $data = delete $self->{Protocol_IRC_gate}{$target}{$gate}; | |||||||||||||||||||||||||
| 196 | 5 | ▶ | keys %{ $self->{Protocol_IRC_gate}{$target} } or delete $self->{Protocol_IRC_gate}{$target}; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||
| 198 | 5 | my %hints = ( | |||||||||||||||||||||||||
| 199 | %$hints, | ||||||||||||||||||||||||||
| 200 | synthesized => 1, | ||||||||||||||||||||||||||
| 201 | ); | ||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||
| 203 | 5 | ▶ | $self->invoke( "on_gate_${effect}_$gate", $message, \%hints, $data ) and $hints{handled} = 1; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 204 | 5 | ▶ | $self->invoke( "on_gate_$effect", $gate, $message, \%hints, $data ) and $hints{handled} = 1; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 205 | 5 | ▶ | $self->invoke( "on_gate", $effect, $gate, $message, \%hints, $data ) and $hints{handled} = 1; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||
| 207 | 5 | return $hints{handled}; | |||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||
| 210 | =head1 INTERNAL MESSAGE HANDLING | ||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||
| 212 | The following messages are handled internally by C<Protocol::IRC::Client>. | ||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||
| 214 | =cut | ||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||
| 216 | sub _invoke_synthetic | ||||||||||||||||||||||||||
| 217 | { | ||||||||||||||||||||||||||
| 218 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||
|
Subroutine
_invoke_synthetic: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||
| 219 | 5 | my ( $command, $message, $hints, @morehints ) = @_; | |||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||
| 221 | 5 | my %hints = ( | |||||||||||||||||||||||||
| 222 | %$hints, | ||||||||||||||||||||||||||
| 223 | synthesized => 1, | ||||||||||||||||||||||||||
| 224 | @morehints, | ||||||||||||||||||||||||||
| 225 | ); | ||||||||||||||||||||||||||
| 226 | 5 | delete $hints{handled}; | |||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||
| 228 | 5 | ▶ | $self->invoke( "on_message_$command", $message, \%hints ) and $hints{handled} = 1; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 229 | 5 | ▶ | $self->invoke( "on_message", $command, $message, \%hints ) and $hints{handled} = 1; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||
| 231 | 5 | return $hints{handled}; | |||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||
| 234 | =head2 CAP | ||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||
| 236 | This message takes a sub-verb as its second argument, and a list of capability | ||||||||||||||||||||||||||
| 237 | names as its third. On receipt of a C<CAP> message, the verb is extracted and | ||||||||||||||||||||||||||
| 238 | set as the C<verb> hint, and the list capabilities set as the keys of a hash | ||||||||||||||||||||||||||
| 239 | given as the C<caps> hint. These are then passed to an event called | ||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||
| 241 | $irc->on_message_cap_VERB( $message, \%hints ) | ||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||
| 243 | or | ||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||
| 245 | $irc->on_message_cap( 'VERB', $message, \%hints ) | ||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||
| 247 | =cut | ||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||
| 249 | sub on_message_CAP | ||||||||||||||||||||||||||
| 250 | { | ||||||||||||||||||||||||||
| 251 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||
|
Subroutine
on_message_CAP: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||
| 252 | 3 | my ( $message, $hints ) = @_; | |||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||
| 254 | 3 | my $verb = $message->arg(1); | |||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||
| 256 | my %hints = ( | ||||||||||||||||||||||||||
| 257 | %$hints, | ||||||||||||||||||||||||||
| 258 | verb => $verb, | ||||||||||||||||||||||||||
| 259 | 3 | caps => { map { $_ => 1 } split m/ /, $message->arg(2) }, | |||||||||||||||||||||||||
| 260 | ); | ||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||
| 262 | 3 | ▶ | $self->invoke( "on_message_cap_$verb", $message, \%hints ) and $hints{handled} = 1; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 263 | 3 | ▶ | $self->invoke( "on_message_cap", $verb, $message, \%hints ) and $hints{handled} = 1; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||
| 265 | 3 | return $hints{handled}; | |||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||
| 268 | =head2 MODE (on channels) and 324 (RPL_CHANNELMODEIS) | ||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||
| 270 | These message involve channel modes. The raw list of channel modes is parsed | ||||||||||||||||||||||||||
| 271 | into an array containing one entry per affected piece of data. Each entry will | ||||||||||||||||||||||||||
| 272 | contain at least a C<type> key, indicating what sort of mode or mode change | ||||||||||||||||||||||||||
| 273 | it is: | ||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||
| 275 | =over 8 | ||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||
| 277 | =item list | ||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||
| 279 | The mode relates to a list; bans, invites, etc.. | ||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||
| 281 | =item value | ||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||
| 283 | The mode sets a value about the channel | ||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||
| 285 | =item bool | ||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||
| 287 | The mode is a simple boolean flag about the channel | ||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||
| 289 | =item occupant | ||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||
| 291 | The mode relates to a user in the channel | ||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||
| 293 | =back | ||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||
| 295 | Every mode type then provides a C<mode> key, containing the mode character | ||||||||||||||||||||||||||
| 296 | itself, and a C<sense> key which is an empty string, C<+>, or C<->. | ||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||
| 298 | For C<list> and C<value> types, the C<value> key gives the actual list entry | ||||||||||||||||||||||||||
| 299 | or value being set. | ||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||
| 301 | For C<occupant> types, a C<flag> key gives the mode converted into an occupant | ||||||||||||||||||||||||||
| 302 | flag (by the C<prefix_mode2flag> method), C<nick> and C<nick_folded> store the | ||||||||||||||||||||||||||
| 303 | user name affected. | ||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||
| 305 | C<boolean> types do not create any extra keys. | ||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||
| 307 | =cut | ||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||
| 309 | sub prepare_hints_channelmode | ||||||||||||||||||||||||||
| 310 | { | ||||||||||||||||||||||||||
| 311 | 12 | ▶ | my $self = shift; | ||||||||||||||||||||||||
|
Subroutine
prepare_hints_channelmode: called CC=13 SCAR=25.7
Pod
undocumented
| |||||||||||||||||||||||||||
| 312 | 12 | my ( $message, $hints ) = @_; | |||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||
| 314 | 12 | my ( $listmodes, $argmodes, $argsetmodes, $boolmodes ) = @{ $self->isupport( 'chanmodes_list' ) }; | |||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||
| 316 | 12 | my $modechars = $hints->{modechars}; | |||||||||||||||||||||||||
| 317 | 12 | my @modeargs = @{ $hints->{modeargs} }; | |||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||
| 319 | 12 | my @modes; # [] -> { type => $, sense => $, mode => $, arg => $ } | |||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||
| 321 | 12 | my $sense = 0; | |||||||||||||||||||||||||
| 322 | 12 | foreach my $modechar ( split( m//, $modechars ) ) { | |||||||||||||||||||||||||
| 323 | 29 | ▶ | $sense = 1, next if $modechar eq "+"; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 324 | 22 | ▶ | $sense = -1, next if $modechar eq "-"; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||
| 326 | 16 | my $hasarg; | |||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||
| 328 | 16 | my $mode = { | |||||||||||||||||||||||||
| 329 | mode => $modechar, | ||||||||||||||||||||||||||
| 330 | sense => $sense, | ||||||||||||||||||||||||||
| 331 | }; | ||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||
| 333 | 16 | ▶ | if( index( $listmodes, $modechar ) > -1 ) { | ||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||
| 334 | 2 | $mode->{type} = 'list'; | |||||||||||||||||||||||||
| 335 | 2 | ▶ | $mode->{value} = shift @modeargs if ( $sense != 0 ); | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||
| 337 | elsif( index( $argmodes, $modechar ) > -1 ) { | ||||||||||||||||||||||||||
| 338 | 2 | $mode->{type} = 'value'; | |||||||||||||||||||||||||
| 339 | 2 | ▶ | $mode->{value} = shift @modeargs if ( $sense != 0 ); | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||
| 341 | elsif( index( $argsetmodes, $modechar ) > -1 ) { | ||||||||||||||||||||||||||
| 342 | 4 | $mode->{type} = 'value'; | |||||||||||||||||||||||||
| 343 | 4 | ▶ | $mode->{value} = shift @modeargs if ( $sense > 0 ); | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||
| 345 | elsif( index( $boolmodes, $modechar ) > -1 ) { | ||||||||||||||||||||||||||
| 346 | 3 | $mode->{type} = 'bool'; | |||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||
| 348 | elsif( my $flag = $self->prefix_mode2flag( $modechar ) ) { | ||||||||||||||||||||||||||
| 349 | 5 | $mode->{type} = 'occupant'; | |||||||||||||||||||||||||
| 350 | 5 | $mode->{flag} = $flag; | |||||||||||||||||||||||||
| 351 | 5 | ▶ | $mode->{nick} = shift @modeargs if ( $sense != 0 ); | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 352 | 5 | $mode->{nick_folded} = $self->casefold_name( $mode->{nick} ); | |||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||
| 354 | else { | ||||||||||||||||||||||||||
| 355 | # TODO: Err... not recognised ... what do I do? | ||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||
| 358 | # TODO: Consider a per-mode event here... | ||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||
| 360 | 16 | push @modes, $mode; | |||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||
| 363 | 12 | $hints->{modes} = \@modes; | |||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||
| 366 | sub prepare_hints_MODE | ||||||||||||||||||||||||||
| 367 | { | ||||||||||||||||||||||||||
| 368 | 12 | ▶ | my $self = shift; | ||||||||||||||||||||||||
|
Subroutine
prepare_hints_MODE: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||
| 369 | 12 | my ( $message, $hints ) = @_; | |||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||
| 371 | 12 | ▶ | if( $hints->{target_type} eq "channel" ) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 372 | 12 | $self->prepare_hints_channelmode( $message, $hints ); | |||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||
| 376 | sub prepare_hints_RPL_CHANNELMODEIS | ||||||||||||||||||||||||||
| 377 | { | ||||||||||||||||||||||||||
| 378 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||
|
Subroutine
prepare_hints_RPL_CHANNELMODEIS: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||
| 379 | 0 | my ( $message, $hints ) = @_; | |||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||
| 381 | 0 | $self->prepare_hints_channelmode( $message, $hints ); | |||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||
| 384 | =head2 RPL_WHOREPLY and RPL_ENDOFWHO | ||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||
| 386 | These messages will be collected up, per channel, and formed into a single | ||||||||||||||||||||||||||
| 387 | synthesized event called C<who>. | ||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||
| 389 | Its hints hash will contain an extra key, C<who>, which will be an ARRAY ref | ||||||||||||||||||||||||||
| 390 | containing the lines of the WHO reply. Each line will be a HASH reference | ||||||||||||||||||||||||||
| 391 | containing: | ||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||
| 393 | =over 8 | ||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||
| 395 | =item user_ident | ||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||
| 397 | =item user_host | ||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||
| 399 | =item user_server | ||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||
| 401 | =item user_nick | ||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||
| 403 | =item user_nick_folded | ||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||
| 405 | =item user_flags | ||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||
| 407 | =back | ||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||
| 409 | =cut | ||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||
| 411 | sub on_gate_done_who | ||||||||||||||||||||||||||
| 412 | { | ||||||||||||||||||||||||||
| 413 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||
|
Subroutine
on_gate_done_who: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||
| 414 | 1 | my ( $message, $hints, $data ) = @_; | |||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||
| 416 | my @who = map { | ||||||||||||||||||||||||||
| 417 | 1 | my $b = $_; | |||||||||||||||||||||||||
| 418 | 1 | +{ map { $_ => $b->{$_} } qw( user_ident user_host user_server user_nick user_nick_folded user_flags ) } | |||||||||||||||||||||||||
| 419 | } @$data; | ||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||
| 421 | 1 | $self->_invoke_synthetic( "who", $message, $hints, | |||||||||||||||||||||||||
| 422 | who => \@who, | ||||||||||||||||||||||||||
| 423 | ); | ||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||
| 426 | =head2 RPL_NAMEREPLY and RPL_ENDOFNAMES | ||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||
| 428 | These messages will be collected up, per channel, and formed into a single | ||||||||||||||||||||||||||
| 429 | synthesized event called C<names>. | ||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||
| 431 | Its hints hash will contain an extra key, C<names>, which will be an ARRAY ref | ||||||||||||||||||||||||||
| 432 | containing the usernames in the channel. Each will be a HASH reference | ||||||||||||||||||||||||||
| 433 | containing: | ||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||
| 435 | =over 8 | ||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||
| 437 | =item nick | ||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||
| 439 | =item flag | ||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||
| 441 | =back | ||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||
| 443 | =cut | ||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||
| 445 | sub on_gate_done_names | ||||||||||||||||||||||||||
| 446 | { | ||||||||||||||||||||||||||
| 447 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||
|
Subroutine
on_gate_done_names: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||
| 448 | 1 | my ( $message, $hints, $data ) = @_; | |||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||
| 450 | 1 | my @names = map { @{ $_->{names} } } @$data; | |||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||
| 452 | 1 | my $prefixflag_re = $self->isupport( 'prefixflag_re' ); | |||||||||||||||||||||||||
| 453 | 1 | my $re = qr/^($prefixflag_re)?(.*)$/; | |||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||
| 455 | 1 | my %names; | |||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||
| 457 | 1 | foreach my $name ( @names ) { | |||||||||||||||||||||||||
| 458 | 3 | ▶ | my ( $flag, $nick ) = $name =~ $re or next; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||
| 460 | 3 | ▶ | $flag ||= ''; # make sure it's defined | ||||||||||||||||||||||||
|
Condition100%2/2
$flag ||= ""
MC/DC100%1/1
$flag ||= ""
$flag
Truth table100%2/2
A
A= $flag
| |||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||
| 462 | 3 | $names{ $self->casefold_name( $nick ) } = { nick => $nick, flag => $flag }; | |||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||
| 465 | 1 | $self->_invoke_synthetic( "names", $message, $hints, | |||||||||||||||||||||||||
| 466 | names => \%names, | ||||||||||||||||||||||||||
| 467 | ); | ||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||
| 470 | =head2 RPL_BANLIST and RPL_ENDOFBANS | ||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||
| 472 | These messages will be collected up, per channel, and formed into a single | ||||||||||||||||||||||||||
| 473 | synthesized event called C<bans>. | ||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||
| 475 | Its hints hash will contain an extra key, C<bans>, which will be an ARRAY ref | ||||||||||||||||||||||||||
| 476 | containing the ban lines. Each line will be a HASH reference containing: | ||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||
| 478 | =over 8 | ||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||
| 480 | =item mask | ||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||
| 482 | User mask of the ban | ||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||
| 484 | =item by_nick | ||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||
| 486 | =item by_nick_folded | ||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||
| 488 | Nickname of the user who set the ban | ||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||
| 490 | =item timestamp | ||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||
| 492 | UNIX timestamp the ban was created | ||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||
| 494 | =back | ||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||
| 496 | =cut | ||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||
| 498 | sub on_gate_done_bans | ||||||||||||||||||||||||||
| 499 | { | ||||||||||||||||||||||||||
| 500 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||
|
Subroutine
on_gate_done_bans: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||
| 501 | 1 | my ( $message, $hints, $data ) = @_; | |||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||
| 503 | my @bans = map { | ||||||||||||||||||||||||||
| 504 | 1 | my $b = $_; | |||||||||||||||||||||||||
| 505 | 2 | +{ map { $_ => $b->{$_} } qw( mask by_nick by_nick_folded timestamp ) } | |||||||||||||||||||||||||
| 506 | } @$data; | ||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||
| 508 | 1 | $self->_invoke_synthetic( "bans", $message, $hints, | |||||||||||||||||||||||||
| 509 | bans => \@bans, | ||||||||||||||||||||||||||
| 510 | ); | ||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||
| 513 | =head2 RPL_MOTD, RPL_MOTDSTART and RPL_ENDOFMOTD | ||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||
| 515 | These messages will be collected up into a synthesized event called C<motd>. | ||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||
| 517 | Its hints hash will contain an extra key, C<motd>, which will be an ARRAY ref | ||||||||||||||||||||||||||
| 518 | containing the lines of the MOTD. | ||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||
| 520 | =cut | ||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||
| 522 | sub on_gate_done_motd | ||||||||||||||||||||||||||
| 523 | { | ||||||||||||||||||||||||||
| 524 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||
|
Subroutine
on_gate_done_motd: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||
| 525 | 1 | my ( $message, $hints, $data ) = @_; | |||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||
| 527 | $self->_invoke_synthetic( "motd", $message, $hints, | ||||||||||||||||||||||||||
| 528 | 1 | motd => [ map { $_->{text} } @$data ], | |||||||||||||||||||||||||
| 529 | ); | ||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||
| 532 | =head2 RPL_WHOIS* and RPL_ENDOFWHOIS | ||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||
| 534 | These messages will be collected up into a synthesized event called C<whois>. | ||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||
| 536 | Each C<RPL_WHOIS*> reply will be stripped of the standard hints hash keys, | ||||||||||||||||||||||||||
| 537 | leaving whatever remains. Added to this will be a key called C<whois>, whose | ||||||||||||||||||||||||||
| 538 | value will be the command name, minus the leading C<RPL_WHOIS>, and converted | ||||||||||||||||||||||||||
| 539 | to lowercase. | ||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||
| 541 | =cut | ||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||
| 543 | sub on_gate_done_whois | ||||||||||||||||||||||||||
| 544 | { | ||||||||||||||||||||||||||
| 545 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||
|
Subroutine
on_gate_done_whois: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||
| 546 | 1 | my ( $message, $hints, $data ) = @_; | |||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||
| 548 | 1 | my @whois; | |||||||||||||||||||||||||
| 549 | my $channels; | ||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||
| 551 | 1 | foreach my $h ( @$data ) { | |||||||||||||||||||||||||
| 552 | # Just delete all the standard hints from each one | ||||||||||||||||||||||||||
| 553 | 4 | delete @{$h}{keys %$hints}; | |||||||||||||||||||||||||
| 554 | 4 | ( $h->{whois} = lc delete $h->{command} ) =~ s/^rpl_whois//; | |||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||
| 556 | # Combine all the 'channels' results into one list | ||||||||||||||||||||||||||
| 557 | 4 | ▶ | if( $h->{whois} eq "channels" ) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 558 | 2 | ▶ | if( $channels ) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 559 | 1 | push @{$channels->{channels}}, @{$h->{channels}}; | |||||||||||||||||||||||||
| 560 | 1 | next; | |||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||
| 562 | 1 | $channels = $h; | |||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||
| 565 | 3 | push @whois, $h; | |||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||
| 568 | 1 | $self->_invoke_synthetic( "whois", $message, $hints, whois => \@whois ); | |||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||
| 571 | =head1 AUTHOR | ||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||
| 573 | Paul Evans <leonerd@leonerd.org.uk> | ||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||
| 575 | =cut | ||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||
| 577 | 10 | 0x55AA; | |||||||||||||||||||||||||