blib/lib/Dancer/Plugin/IRCNotice.pm

filter: Statementstmt 45.6% 21 / 46 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 85.7% 6 / 7 Podpod n/a totaltotal 27.8% 27 / 97 SCAR 45.3
CC
14
Cov
26%
__ANON__
210.0
BEGIN
1.0
BEGIN
1.0
CRAP 92.6
↑ Summary Build »
1 package Dancer::Plugin::IRCNotice;
2  
3 1 ▶use 5.008_005;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Dancer ':syntax';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Dancer::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use IO::Socket::IP;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = '0.05';
12  
13 register notify => sub {
14 0 ▶ my ($message) = @_;
Subroutine __ANON__: not called CC=14 SCAR=53.5
15  
16 0 info "Sending notification: $message";
17  
18 0 my $config = plugin_setting;
19  
20 0 ▶ $config->{host} ||= 'chat.freenode.net';
Condition0%0/2
$config->{"host"} ||= "chat.freenode.net"
l!l
00
MC/DC0%0/1
$config->{"host"} ||= "chat.freenode.net"
$config->{"host"}
Truth table0%0/2
A
A= $config->{"host"}
Aresult
11
00
21 0 ▶ $config->{nick} ||= sprintf('dpin%04u', int(rand() * 10000));
Condition0%0/3
$config->{"nick"} ||= sprintf("dpin%04u", int((rand()) * 10000))
l!l&&r!l&&!r
000
MC/DC0%0/2
$config->{"nick"} ||= sprintf("dpin%04u", int((rand()) * 10000))
$config->{"nick"} sprintf("dpin%04u", int((rand()) * 10000))
Truth table0%0/3
A ||= B
A= $config->{"nick"}B= sprintf("dpin%04u", int((rand()) * 10000))
ABresult
1X1
011
000
22 0 ▶ $config->{name} ||= $config->{nick};
Condition0%0/3
$config->{"name"} ||= $config->{"nick"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$config->{"name"} ||= $config->{"nick"}
$config->{"name"} $config->{"nick"}
Truth table0%0/3
A ||= B
A= $config->{"name"}B= $config->{"nick"}
ABresult
1X1
011
000
23 0 ▶ $config->{channel} ||= '#dpintest';
Condition0%0/2
$config->{"channel"} ||= "#dpintest"
l!l
00
MC/DC0%0/1
$config->{"channel"} ||= "#dpintest"
$config->{"channel"}
Truth table0%0/2
A
A= $config->{"channel"}
Aresult
11
00
24  
25 0 ▶ fork and return if $config->{fork};
Branch: 1 branch
BranchTrueFalseTotal
if $config->{"fork"} 0 0 0
Condition0%0/5
$config->{'fork'} && (fork && (return))
!ll&&!rl&&r
000
fork and return
!ll
00
MC/DC0%0/2
$config->{'fork'} && (fork && (return))
$config->{'fork'} fork
Truth table0%0/3
A && B
A= $config->{'fork'}B= fork
ABresult
0X0
100
111
26  
27 # Add default port
28 0 ▶ $config->{host} .= ':6667' unless $config->{host} =~ /:\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $config->{"host"} =~ /:\d+$/ 0 0 0
29  
30 my $socket = IO::Socket::IP->new($config->{host})
31 0 ▶ or warning "Cannot create socket: $@" and return;
Branch: 1 branch
BranchTrueFalseTotal
my $socket = "IO::Socket::IP"->new($config->{"host"}) or warning("Cannot create socket: $@") and return 0 0 0
Condition0%0/5
(my $socket = 'IO::Socket::IP'->new($config->{'host'})) || warning("Cannot create socket: $@") && (return)
l!l&&r!l&&!r
000
warning("Cannot create socket: $@") and return
!ll
00
MC/DC0%0/2
(my $socket = 'IO::Socket::IP'->new($config->{'host'})) || warning("Cannot create socket: $@") && (return)
(my $socket = 'IO::Socket::IP'->new($config->{'host'})) warning("Cannot create socket: $@")
Truth table0%0/3
A || B
A= (my $socket = 'IO::Socket::IP'->new($config->{'host'}))B= warning("Cannot create socket: $@")
ABresult
1X1
011
000
32  
33 # TODO error handling srsly
34  
35 0 info "Registering as $config->{nick}";
36  
37 0 $socket->say("NICK $config->{nick}");
38 0 $socket->say("USER $config->{nick} . . :$config->{name}");
39  
40 0 ▶ while (my $line = $socket->getline) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = $socket->getline) 0 0 0
41 0 info "Got $line";
42  
43 0 ▶ if ($line =~ /End of \/MOTD/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ m[End of /MOTD]) 0 0 0
44 0 info "Sending notice to $config->{channel}";
45  
46 0 $socket->say("NOTICE $config->{channel} :$message");
47 0 $socket->say("QUIT");
48  
49 0 info "Notice sent";
50 0 ▶ exit if $config->{fork};
Branch: 1 branch
BranchTrueFalseTotal
if $config->{"fork"} 0 0 0
51 0 return;
52 }
53 }
54  
55 0 info "Notice not sent";
56  
57 0 ▶ exit if $config->{fork};
Branch: 1 branch
BranchTrueFalseTotal
if $config->{"fork"} 0 0 0
58 0 return;
59 1 };
60  
61 1 register_plugin;
62  
63 1 1;
64 __END__
↑ Summary Build »