Pocosi/Status.pm

filter: Statementstmt 7.4% 21 / 282 Branchbran 0.0% 0 / 62 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 21.6% 8 / 37 Podpod 0.0% 0 / 25 totaltotal 7.1% 29 / 406 CC 35 SCAR 27.6
CC
35
Cov
6%
_dump
72.0
_default
42.0
_event_debug
12.0
CRAP 15.8
« Pocosi.pm ↑ Summary
1 package App::Pocosi::Status;
2 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 $App::Pocosi::Status::AUTHORITY = 'cpan:HINRIK';
4 }
5 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 $App::Pocosi::Status::VERSION = '0.03';
7 }
8  
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use IRC::Utils qw(decode_irc strip_color strip_formatting numeric_to_name);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use POE::Component::Server::IRC::Plugin qw(PCSI_EAT_NONE);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
17 0 my ($package) = shift;
18 0 ▶ croak "$package requires an even number of arguments" if @_ & 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ & 1 0 0 0
19 0 return bless { @_ }, $package;
20 }
21  
22 0 ▶sub PCSI_register {
Subroutine PCSI_register: not called CC=1 SCAR=6.9
Pod undocumented
23 0 my ($self, $ircd, %args) = @_;
24 0 $ircd->raw_events(1);
25 0 $ircd->plugin_register($self, 'SERVER', 'all');
26 0 return 1;
27 }
28  
29 0 ▶sub PCSI_unregister {
Subroutine PCSI_unregister: not called CC=1 SCAR=6.9
Pod undocumented
30 0 return 1;
31 }
32  
33 0 ▶sub verbose {
Subroutine verbose: not called CC=1 SCAR=6.9
Pod undocumented
34 0 my ($self, $value) = @_;
35 0 $self->{Verbose} = $value;
36 0 return;
37 }
38  
39 0 ▶sub trace {
Subroutine trace: not called CC=1 SCAR=6.9
Pod undocumented
40 0 my ($self, $value) = @_;
41 0 $self->{Trace} = $value;
42 0 return;
43 }
44  
45 0 ▶sub _normalize {
Subroutine _normalize: not called CC=1 SCAR=6.9
46 0 my ($line) = @_;
47 0 $line = decode_irc($line);
48 0 $line = strip_color($line);
49 0 $line = strip_formatting($line);
50 0 return $line;
51 }
52  
53 0 ▶sub _dump {
Subroutine _dump: not called CC=8 SCAR=42.8
54 0 my ($arg) = @_;
55  
56 0 ▶ if (ref $arg eq 'ARRAY') {
Branch: 4 branches
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 0 0 0
elsif (ref $arg eq 'HASH') { } 0 0 0
elsif (ref $arg) { } 0 0 0
elsif (defined $arg) { } 0 0 0
57 0 my @elems;
58 0 for my $elem (@$arg) {
59 0 push @elems, _dump($elem);
60 }
61 0 return '['. join(', ', @elems) .']';
62 }
63 elsif (ref $arg eq 'HASH') {
64 0 my @pairs;
65 0 for my $key (keys %$arg) {
66 0 push @pairs, [$key, _dump($arg->{$key})];
67 }
68 0 return '{'. join(', ', map { "$_->[0] => $_->[1]" } @pairs) .'}';
69 }
70 elsif (ref $arg) {
71 0 require overload;
72 0 return overload::StrVal($arg);
73 }
74 elsif (defined $arg) {
75 0 ▶ return $arg if looks_like_number($arg);
Branch: 1 branch
BranchTrueFalseTotal
if &looks_like_number($arg) 0 0 0
76 0 return "'".decode_irc($arg)."'";
77 }
78 else {
79 0 return 'undef';
80 }
81 }
82  
83 0 ▶sub _event_debug {
Subroutine _event_debug: not called CC=3 SCAR=24.8
84 0 my ($self, $ircd, $args, $event) = @_;
85  
86 0 ▶ if (!defined $event) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $event) 0 0 0
87 0 $event = (caller(1))[3];
88 0 $event =~ s/.*:://;
89 }
90  
91 0 pop @$args;
92 0 my @output;
93 0 for my $i (0..$#{ $args }) {
94 0 push @output, "ARG$i: " . _dump(${ $args->[$i] });
95 }
96  
97 $ircd->send_event_next(
98 0 'ircd_plugin_status',
99 $self,
100 'debug',
101 "$event: ".join(', ', @output),
102 );
103 0 return;
104 }
105  
106 0 ▶sub IRCD_connected {
Subroutine IRCD_connected: not called CC=2 SCAR=17.9
Pod undocumented
107 0 my ($self, $ircd) = splice @_, 0, 2;
108 0 my $addr = ${ $_[1] };
109 0 my $port = ${ $_[2] };
110 0 my $peer = ${ $_[5] };
111  
112 0 my $msg = "Connected to peer $peer on $addr:$port";
113 0 ▶ $self->_event_debug($ircd, \@_) if $self->{Trace};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Trace"} 0 0 0
114 0 $ircd->send_event_next('ircd_plugin_status', $self, 'normal', $msg);
115 0 return PCSI_EAT_NONE;
116 }
117  
118 0 ▶sub IRCD_socketerr {
Subroutine IRCD_socketerr: not called CC=2 SCAR=17.9
Pod undocumented
119 0 my ($self, $ircd) = splice @_, 0, 2;
120 0 my $args = ${ $_[0] };
121 0 my $op = ${ $_[1] };
122 0 my $error = ${ $_[3] };
123 0 my $addr = $args->{remoteaddress};
124 0 my $port = $args->{remoteport};
125 0 my $peer = $args->{name};
126  
127 0 my $msg = "Failed to connect to peer $peer on $addr:$port. Operation $op failed: $error";
128 0 ▶ $self->_event_debug($ircd, \@_) if $self->{Trace};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Trace"} 0 0 0
129 0 $ircd->send_event_next('ircd_plugin_status', $self, 'normal', $msg);
130 0 return PCSI_EAT_NONE;
131 }
132  
133 0 ▶sub IRCD_listener_add {
Subroutine IRCD_listener_add: not called CC=2 SCAR=17.9
Pod undocumented
134 0 my ($self, $ircd) = splice @_, 0, 2;
135 0 my $port = ${ $_[0] };
136 0 my $addr = ${ $_[2] };
137  
138 0 my $msg = "Started listening on $addr:$port";
139 0 ▶ $self->_event_debug($ircd, \@_) if $self->{Trace};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Trace"} 0 0 0
140 0 $ircd->send_event_next('ircd_plugin_status', $self, 'normal', $msg);
141 0 return PCSI_EAT_NONE;
142 }
143  
144 0 ▶sub IRCD_listener_del {
Subroutine IRCD_listener_del: not called CC=2 SCAR=17.9
Pod undocumented
145 0 my ($self, $ircd) = splice @_, 0, 2;
146 0 my $port = ${ $_[0] };
147 0 my $addr = ${ $_[2] };
148  
149 0 my $msg = "Stopped listening on $addr:$port";
150 0 ▶ $self->_event_debug($ircd, \@_) if $self->{Trace};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Trace"} 0 0 0
151 0 $ircd->send_event_next('ircd_plugin_status', $self, 'normal', $msg);
152 0 return PCSI_EAT_NONE;
153 }
154  
155 0 ▶sub IRCD_listener_failure {
Subroutine IRCD_listener_failure: not called CC=2 SCAR=17.9
Pod undocumented
156 0 my ($self, $ircd) = splice @_, 0, 2;
157 0 my $op = ${ $_[1] };
158 0 my $error = ${ $_[3] };
159 0 my $port = ${ $_[4] };
160 0 my $addr = ${ $_[5] };
161  
162 0 ▶ $self->_event_debug($ircd, \@_) if $self->{Trace};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Trace"} 0 0 0
163 0 $self->{Pocosi}->shutdown("Failed to listen on $addr:$port. Operation $op failed: $error");
164 0 return PCSI_EAT_NONE;
165 }
166  
167 0 ▶sub IRCD_compressed_conn {
Subroutine IRCD_compressed_conn: not called CC=2 SCAR=17.9
Pod undocumented
168 0 my ($self, $ircd) = splice @_, 0, 2;
169 0 my $id = ${ $_[0] };
170 0 my ($addr, $port) = $ircd->connection_info($id);
171  
172 0 my $msg = "Compressed connection to peer $addr:$port";
173 0 ▶ $self->_event_debug($ircd, \@_) if $self->{Trace};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Trace"} 0 0 0
174 0 $ircd->send_event_next('ircd_plugin_status', $self, 'normal', $msg);
175 0 return PCSI_EAT_NONE;
176 }
177  
178 0 ▶sub IRCD_daemon_error {
Subroutine IRCD_daemon_error: not called CC=2 SCAR=17.9
Pod undocumented
179 0 my ($self, $ircd) = splice @_, 0, 2;
180 0 my $peer = ${ $_[1] };
181 0 my $reason = ${ $_[2] };
182  
183 0 my $msg = "Failed to register with peer $peer: $reason";
184 0 ▶ $self->_event_debug($ircd, \@_) if $self->{Trace};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Trace"} 0 0 0
185 0 $ircd->send_event_next('ircd_plugin_status', $self, 'normal', $msg);
186 0 return PCSI_EAT_NONE;
187 }
188  
189 0 ▶sub IRCD_daemon_server {
Subroutine IRCD_daemon_server: not called CC=2 SCAR=17.9
Pod undocumented
190 0 my ($self, $ircd) = splice @_, 0, 2;
191 0 my $new_server = ${ $_[0] };
192 0 my $by_server = ${ $_[1] };
193 0 my $hops = ${ $_[2] };
194  
195 0 my $msg = "Server $new_server (hops: $hops) introduced to the network by $by_server";
196 0 ▶ $self->_event_debug($ircd, \@_) if $self->{Trace};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Trace"} 0 0 0
197 0 $ircd->send_event_next('ircd_plugin_status', $self, 'normal', $msg);
198 0 return PCSI_EAT_NONE;
199 }
200  
201 0 ▶sub IRCD_daemon_squit {
Subroutine IRCD_daemon_squit: not called CC=2 SCAR=17.9
Pod undocumented
202 0 my ($self, $ircd) = splice @_, 0, 2;
203 0 my $server = ${ $_[0] };
204  
205 0 my $msg = "Server $server quit from the network";
206 0 ▶ $self->_event_debug($ircd, \@_) if $self->{Trace};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Trace"} 0 0 0
207 0 $ircd->send_event_next('ircd_plugin_status', $self, 'normal', $msg);
208 0 return PCSI_EAT_NONE;
209 }
210  
211 0 ▶sub IRCD_daemon_rehash {
Subroutine IRCD_daemon_rehash: not called CC=2 SCAR=17.9
Pod undocumented
212 0 my ($self, $ircd) = splice @_, 0, 2;
213 0 my $oper = ${ $_[0] };
214  
215 0 my $msg = "Operator $oper issued a REHASH";
216 0 ▶ $self->_event_debug($ircd, \@_) if $self->{Trace};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Trace"} 0 0 0
217 0 $ircd->send_event_next('ircd_plugin_status', $self, 'normal', $msg);
218 0 return PCSI_EAT_NONE;
219 }
220  
221 0 ▶sub IRCD_daemon_die {
Subroutine IRCD_daemon_die: not called CC=2 SCAR=17.9
Pod undocumented
222 0 my ($self, $ircd) = splice @_, 0, 2;
223 0 my $oper = ${ $_[0] };
224  
225 0 my $msg = "Operator $oper issued a DIE";
226 0 ▶ $self->_event_debug($ircd, \@_) if $self->{Trace};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Trace"} 0 0 0
227 0 $ircd->send_event_next('ircd_plugin_status', $self, 'normal', $msg);
228 0 return PCSI_EAT_NONE;
229 }
230  
231 0 ▶sub IRCD_daemon_gline {
Subroutine IRCD_daemon_gline: not called CC=2 SCAR=17.9
Pod undocumented
232 0 my ($self, $ircd) = splice @_, 0, 2;
233 0 my $oper = ${ $_[0] };
234 0 my $u_mask = ${ $_[1] };
235 0 my $h_mask = ${ $_[2] };
236 0 my $reason = _normalize(${ $_[3] });
237  
238 0 my $msg = "Operator $oper set a GLINE on $u_mask\@$h_mask because: $reason";
239 0 ▶ $self->_event_debug($ircd, \@_) if $self->{Trace};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Trace"} 0 0 0
240 0 $ircd->send_event_next('ircd_plugin_status', $self, 'normal', $msg);
241 0 return PCSI_EAT_NONE;
242 }
243  
244 0 ▶sub IRCD_daemon_kline {
Subroutine IRCD_daemon_kline: not called CC=2 SCAR=17.9
Pod undocumented
245 0 my ($self, $ircd) = splice @_, 0, 2;
246 0 my $oper = ${ $_[0] };
247 0 my $target = ${ $_[1] };
248 0 my $secs = ${ $_[2] };
249 0 my $u_mask = ${ $_[3] };
250 0 my $h_mask = ${ $_[4] };
251 0 my $reason = _normalize(${ $_[5] });
252  
253 0 my $msg = "Operator $oper set a KLINE on $target ($u_mask\@$h_mask) for $secs seconds because: $reason";
254 0 ▶ $self->_event_debug($ircd, \@_) if $self->{Trace};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Trace"} 0 0 0
255 0 $ircd->send_event_next('ircd_plugin_status', $self, 'normal', $msg);
256 0 return PCSI_EAT_NONE;
257 }
258  
259 0 ▶sub IRCD_daemon_rkline {
Subroutine IRCD_daemon_rkline: not called CC=1 SCAR=6.9
Pod undocumented
260 0 my ($self, $ircd) = splice @_, 0, 2;
261 0 my $oper = ${ $_[0] };
262 0 my $target = ${ $_[1] };
263 0 my $secs = ${ $_[2] };
264 0 my $u_mask = ${ $_[3] };
265 0 my $h_mask = ${ $_[4] };
266 0 my $reason = _normalize(${ $_[5] });
267  
268 0 my $msg = "Operator $oper set an RKLINE on $target ($u_mask\@$h_mask) for $secs seconds because: $reason";
269 0 $ircd->send_event_next('ircd_plugin_status', $self, 'normal', $msg);
270 0 return PCSI_EAT_NONE;
271 }
272  
273 0 ▶sub IRCD_daemon_unkline {
Subroutine IRCD_daemon_unkline: not called CC=2 SCAR=17.9
Pod undocumented
274 0 my ($self, $ircd) = splice @_, 0, 2;
275 0 my $oper = ${ $_[0] };
276 0 my $target = ${ $_[1] };
277 0 my $u_mask = ${ $_[2] };
278 0 my $h_mask = ${ $_[3] };
279  
280 0 my $msg = "Operator $oper removed KLINE on $target ($u_mask\@$h_mask)";
281 0 ▶ $self->_event_debug($ircd, \@_) if $self->{Trace};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Trace"} 0 0 0
282 0 $ircd->send_event_next('ircd_plugin_status', $self, 'normal', $msg);
283 0 return PCSI_EAT_NONE;
284 }
285  
286 0 ▶sub IRCD_daemon_locops {
Subroutine IRCD_daemon_locops: not called CC=2 SCAR=17.9
Pod undocumented
287 0 my ($self, $ircd) = splice @_, 0, 2;
288 0 my $oper = ${ $_[0] };
289 0 my $message = _normalize(${ $_[0] });
290  
291 0 my $msg = "LOCOPS message from $oper: $message";
292 0 ▶ $self->_event_debug($ircd, \@_) if $self->{Trace};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Trace"} 0 0 0
293 0 $ircd->send_event_next('ircd_plugin_status', $self, 'normal', $msg);
294 0 return PCSI_EAT_NONE;
295 }
296  
297 0 ▶sub IRCD_daemon_operwall {
Subroutine IRCD_daemon_operwall: not called CC=2 SCAR=17.9
Pod undocumented
298 0 my ($self, $ircd) = splice @_, 0, 2;
299 0 my $oper = ${ $_[0] };
300 0 my $message = _normalize(${ $_[0] });
301  
302 0 my $msg = "OPERWALL message from $oper: $message";
303 0 ▶ $self->_event_debug($ircd, \@_) if $self->{Trace};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Trace"} 0 0 0
304 0 $ircd->send_event_next('ircd_plugin_status', $self, 'normal', $msg);
305 0 return PCSI_EAT_NONE;
306 }
307  
308 0 ▶sub IRCD_daemon_wallops {
Subroutine IRCD_daemon_wallops: not called CC=2 SCAR=17.9
Pod undocumented
309 0 my ($self, $ircd) = splice @_, 0, 2;
310 0 my $oper = ${ $_[0] };
311 0 my $message = _normalize(${ $_[0] });
312  
313 0 my $msg = "WALLOPS message from $oper: $message";
314 0 ▶ $self->_event_debug($ircd, \@_) if $self->{Trace};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Trace"} 0 0 0
315 0 $ircd->send_event_next('ircd_plugin_status', $self, 'normal', $msg);
316 0 return PCSI_EAT_NONE;
317 }
318  
319 0 ▶sub IRCD_raw_input {
Subroutine IRCD_raw_input: not called CC=2 SCAR=17.9
Pod undocumented
320 0 my ($self, $ircd) = splice @_, 0, 2;
321 0 ▶ return PCSI_EAT_NONE if !$self->{Verbose};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"Verbose"} 0 0 0
322 0 my $id = ${ $_[0] };
323 0 my $raw = _normalize(${ $_[1] });
324 0 $ircd->send_event_next('ircd_plugin_status', $self, 'debug', "<<< $id: $raw");
325 0 return PCSI_EAT_NONE;
326 }
327  
328 0 ▶sub IRCD_raw_output {
Subroutine IRCD_raw_output: not called CC=2 SCAR=17.9
Pod undocumented
329 0 my ($self, $ircd) = splice @_, 0, 2;
330 0 ▶ return PCSI_EAT_NONE if !$self->{Verbose};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"Verbose"} 0 0 0
331 0 my $id = ${ $_[0] };
332 0 my $raw = _normalize(${ $_[1] });
333 0 $ircd->send_event_next('ircd_plugin_status', $self, 'debug', ">>> $id: $raw");
334 0 return PCSI_EAT_NONE;
335 }
336  
337 0 ▶sub _default {
Subroutine _default: not called CC=6 SCAR=37.4
338 0 my ($self, $ircd, $event) = splice @_, 0, 3;
339 0 ▶ return PCSI_EAT_NONE if !$self->{Trace};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"Trace"} 0 0 0
340 0 ▶ return PCSI_EAT_NONE if $event =~ /^IRCD_plugin_/;
Branch: 1 branch
BranchTrueFalseTotal
if $event =~ /^IRCD_plugin_/ 0 0 0
341  
342 0 ▶ if (my ($numeric) = $event =~ /^IRCD_cmd_(\d+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($numeric) = $event =~ /^IRCD_cmd_(\d+)$/) 0 0 0
343 0 my $name = numeric_to_name($numeric);
344 0 ▶ $event .= " ($name)" if defined $name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 0 0 0
345 }
346  
347 0 ▶ $self->_event_debug($ircd, \@_, $event) if $self->{Trace};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Trace"} 0 0 0
348 0 return PCSI_EAT_NONE;
349 }
350  
351 1 1;
352  
353 =encoding utf8
354  
355 =head1 NAME
356  
357 App::Pocosi::Status - A PoCo-Server-IRC plugin which logs IRC status
358  
359 =head1 DESCRIPTION
360  
361 This plugin is used internally by L<App::Pocosi|App::Pocosi>. No need for
362 you to use it.
363  
364 =head1 AUTHOR
365  
366 Hinrik E<Ouml>rn SigurE<eth>sson, hinrik.sig@gmail.com
367  
368 =cut
« Pocosi.pm ↑ Summary