Component/IRC/Plugin/ISupport.pm

filter: Statementstmt 93.8% 91 / 97 Branchbran 84.6% 22 / 26 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 95.6% 22 / 23 Podpod 42.8% 3 / 7 totaltotal 88.2% 142 / 161 CC 17 SCAR 9.9
CC
17
Cov
91%
__ANON__
6.0
_default
5.0
S_005
5.0
CRAP 2.7
« Component/IRC/Plugin/CTCP.pm ↑ Summary Component/IRC/Plugin/FollowTail.pm »
1 package POE::Component::IRC::Plugin::ISupport;
2 79 $POE::Component::IRC::Plugin::ISupport::VERSION = '6.95';
3 79 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 79 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 79 ▶use POE::Component::IRC::Plugin qw(:ALL);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 116 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
8 116 return bless { }, shift;
9 }
10  
11 116 ▶sub PCI_register {
Subroutine PCI_register: called CC=1 SCAR=0.0
Pod undocumented
12 116 my ($self, $irc) = splice @_, 0, 2;
13  
14 116 $irc->plugin_register( $self => SERVER => qw(all) );
15 116 $self->{irc} = $irc;
16 $self->{parser} = {
17 90 ▶ CASEMAPPING => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
18 90 my ($support, $key, $val) = @_;
19 90 $support->{$key} = $val;
20 },
21 1 ▶ CHANLIMIT => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
22 1 my ($support, $key, $val) = @_;
23 1 ▶ while ($val =~ /([^:]+):(\d+),?/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /([^:]+):(\d+),?/g) 1 1 2
24 1 my ($k, $v) = ($1, $2);
25 1 @{ $support->{$key} }{ split(//, $k) } = ($v) x length $k;
26 }
27 },
28 90 ▶ CHANMODES => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
29 90 my ($support, $key, $val) = @_;
30 90 $support->{$key} = [ split(/,/, $val) ];
31 },
32 90 ▶ CHANTYPES => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
33 90 my ($support, $key, $val) = @_;
34 90 $support->{$key} = [ split(//, $val) ];
35 },
36 1 ▶ ELIST => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
37 1 my ($support, $key, $val) = @_;
38 1 $support->{$key} = [ split(//, $val) ];
39 },
40 0 ▶ IDCHAN => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
41 0 my ($support, $key, $val) = @_;
42 0 ▶ while ($val =~ /([^:]+):(\d+),?/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /([^:]+):(\d+),?/g) 0 0 0
43 0 my ($k, $v) = ($1, $2);
44 0 @{ $support->{$key} }{ split(//, $k) } = ($v) x length $k;
45 }
46 },
47 1 ▶ MAXLIST => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
48 1 my ($support, $key, $val) = @_;
49 1 ▶ while ($val =~ /([^:]+):(\d+),?/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /([^:]+):(\d+),?/g) 1 1 2
50 1 my ($k, $v) = ($1, $2);
51 1 @{ $support->{$key} }{ split(//, $k) } = ($v) x length $k;
52 }
53 },
54 90 ▶ PREFIX => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
55 90 my ($support, $key, $val) = @_;
56 90 ▶ if (my ($k, $v) = $val =~ /\(([^)]+)\)(.*)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $val =~ /\(([^)]+)\)(.*)/) 90 0 90
57 90 @{ $support->{$key} }{ split(//, $k) } = split(//, $v);
58 }
59 },
60 1 ▶ STATUSMSG => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
61 1 my ($support, $key, $val) = @_;
62 1 $support->{$key} = [ split(//, $val) ];
63 },
64 1 ▶ TARGMAX => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
65 1 my ($support, $key, $val) = @_;
66 1 ▶ while ($val =~ /([^:]+):(\d*),?/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /([^:]+):(\d*),?/g) 8 1 9
67 8 my ($k, $v) = ($1, $2);
68 8 $support->{$key}->{$k} = $v;
69 }
70 },
71 90 ▶ EXCEPTS => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
72 90 my ($support, $flag) = @_;
73 90 $support->{$flag} = 'e';
74 },
75 90 ▶ INVEX => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
76 90 my ($support, $flag) = @_;
77 90 $support->{$flag} = 'I';
78 },
79 116 };
80  
81 116 return 1;
82 }
83  
84 116 ▶sub PCI_unregister {
Subroutine PCI_unregister: called CC=1 SCAR=0.0
Pod undocumented
85 116 my ($self, $irc) = splice @_, 0, 2;
86 116 delete $self->{irc};
87 116 return 1;
88 }
89  
90 91 ▶sub S_connected {
Subroutine S_connected: called CC=1 SCAR=0.0
Pod undocumented
91 91 my ($self, $irc) = splice @_, 0, 2;
92  
93 91 $self->{server} = { };
94 91 $self->{got_005} = 0;
95 91 $self->{done_005} = 0;
96 91 return PCI_EAT_NONE;
97 }
98  
99 181 ▶sub S_005 {
Subroutine S_005: called CC=5 SCAR=16.1
Pod undocumented
100 181 my ($self, $irc, @args) = @_;
101 181 my @vals = @{ ${ $args[2] } };
102 181 pop @vals;
103 181 my $support = $self->{server};
104  
105 181 for my $val (@vals) {
106 1364 ▶ if ($val =~ /=/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /=/) { } 1001 363 1364
107 1001 my $key;
108 1001 ($key, $val) = split(/=/, $val, 2);
109 1001 ▶ if (defined $self->{parser}->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'parser'}{$key}) { } 365 636 1001
110 365 $self->{parser}->{$key}->($support, $key, $val);
111 }
112 else {
113 # AWAYLEN CHANNELLEN CHIDLEN CHARSET EXCEPTS INVEX KICKLEN
114 # MAXBANS MAXCHANNELS MAXTARGETS MODES NETWORK NICKLEN STD
115 # TOPICLEN WATCH
116 636 $support->{$key} = $val;
117 }
118 }
119 else {
120 363 ▶ if (defined $self->{parser}->{$val}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'parser'}{$val}) { } 180 183 363
121 180 $self->{parser}->{$val}->($support, $val);
122 }
123 else {
124 # ACCEPT CALLERID CAPAB CNOTICE CPRIVMSG FNC KNOCK MAXNICKLEN
125 # NAMESX NOQUIT PENALTY RFC2812 SAFELIST UHNAMES USERIP
126 # VCHANS WALLCHOPS WALLVOICES WHOX
127 183 $support->{$val} = 'on';
128 }
129 }
130 }
131  
132 181 $self->{got_005}++;
133 181 return PCI_EAT_NONE;
134 }
135  
136 3636 ▶sub _default {
Subroutine _default: called CC=5 SCAR=16.1
137 3636 my ($self, $irc, $event) = @_;
138  
139 3636 ▶ return PCI_EAT_NONE if $self->{done_005};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"done_005"} 2316 1320 3636
140 1320 ▶ return PCI_EAT_NONE if !$self->{got_005};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"got_005"} 1213 107 1320
141  
142 107 ▶ if ($event =~ /^S_(\d+)/ and $1 > 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($event =~ /^S_(\d+)/ and $1 > 5) 90 17 107
Condition66%2/3
$event =~ /^S_(\d+)/ and $1 > 5
!ll&&!rl&&r
17090
MC/DC50%1/2
$event =~ /^S_(\d+)/ and $1 > 5
$event =~ /^S_(\d+)/ $1 > 5
Truth table66%2/3
A and B
A= $event =~ /^S_(\d+)/B= $1 > 5
ABresult
0X0
100
111
143 90 $self->{done_005} = 1;
144 90 $irc->send_event_now(irc_isupport => $self);
145 }
146  
147 107 return PCI_EAT_NONE;
148 }
149  
150 2054 ▶sub isupport {
Subroutine isupport: called CC=3 SCAR=11.0
Pod documented
151 2054 my $self = shift;
152 2054 ▶ my $value = uc ( $_[0] ) || return;
Condition50%1/2
uc $_[0] || (return)
l!l
20540
MC/DC0%0/1
uc $_[0] || (return)
uc $_[0]
Truth table50%1/2
A
A= uc $_[0]
Aresult
11
00
153  
154 2054 ▶ return $self->{server}->{$value} if defined $self->{server}->{$value};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"server"}{$value} 1629 425 2054
155 425 return;
156 }
157  
158 1 ▶sub isupport_dump_keys {
Subroutine isupport_dump_keys: called CC=2 SCAR=7.2
Pod documented
159 1 my $self = shift;
160  
161 1 ▶ if ( keys %{ $self->{server} } > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$$self{"server"};} > 0) 1 0 1
162 1 return keys %{ $self->{server} };
163 }
164 0 return;
165 }
166  
167 79 1;
168  
169 =encoding utf8
170  
171 =head1 NAME
172  
173 POE::Component::IRC::Plugin::ISupport - A PoCo-IRC plugin that handles server
174 capabilities
175  
176 =head1 DESCRIPTION
177  
178 This handles the C<irc_005> messages that come from the server. They
179 define the capabilities support by the server.
180  
181 =head1 METHODS
182  
183 =head2 C<new>
184  
185 Takes no arguments.
186  
187 Returns a plugin object suitable for feeding to
188 L<POE::Component::IRC|POE::Component::IRC>'s C<plugin_add> method.
189  
190 =head2 C<isupport>
191  
192 Takes one argument. the server capability to query. Returns a false value on
193 failure or a value representing the applicable capability. A full list of
194 capabilities is available at L<http://www.irc.org/tech_docs/005.html>.
195  
196 =head2 C<isupport_dump_keys>
197  
198 Takes no arguments, returns a list of the available server capabilities,
199 which can be used with C<isupport>.
200  
201 =head1 INPUT
202  
203 This module handles the following PoCo-IRC signals:
204  
205 =head2 C<irc_005> (RPL_ISUPPORT or RPL_PROTOCTL)
206  
207 Denotes the capabilities of the server.
208  
209 =head2 C<all>
210  
211 Once the next signal is received that is I<greater> than C<irc_005>,
212 it emits an C<irc_isupport> signal.
213  
214 =head1 OUTPUT EVENTS
215  
216 =head2 C<irc_isupport>
217  
218 Emitted by: the first signal received after C<irc_005>
219  
220 C<ARG0> will be the plugin object itself for ease of use.
221  
222 This is emitted when the support report has finished.
223  
224 =head1 AUTHOR
225  
226 Jeff C<japhy> Pinyan, F<japhy@perlmonk.org>
227  
228 =head1 SEE ALSO
229  
230 L<POE::Component::IRC|POE::Component::IRC>
231  
232 L<POE::Component::IRC::Plugin|POE::Component::IRC::Plugin>
233  
234 =cut
« Component/IRC/Plugin/CTCP.pm ↑ Summary Component/IRC/Plugin/FollowTail.pm »