blib/lib/Dancer/Plugin/IRCNotice.pm

filter: Statementstmt 51.0% 25 / 49 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 87.5% 7 / 8 Podpod n/a totaltotal 34.4% 32 / 93 CC 12 SCAR 45.9
CC
12
Cov
33%
__ANON__
156.0
BEGIN
1.0
BEGIN
1.0
CRAP 98.9
↑ Summary
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 Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Dancer ':syntax';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Dancer::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use IO::Socket::IP;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 our $VERSION = '0.06';
13  
14 1 our %TYPES = (
15 notice => 'NOTICE',
16 message => 'PRIVMSG',
17 );
18  
19 0 ▶register notify => sub {
Subroutine __ANON__: not called CC=12 SCAR=50.5
20 0 my ($message) = @_;
21  
22 0 info "Sending notification: $message";
23  
24 0 my $config = plugin_setting;
25  
26 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
27 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
28 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
29 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
30 0 ▶ $config->{type} ||= 'notice';
Condition0%0/2
$config->{"type"} ||= "notice"
l!l
00
MC/DC0%0/1
$config->{"type"} ||= "notice"
$config->{"type"}
Truth table0%0/2
A
A= $config->{"type"}
Aresult
11
00
31  
32 croak "Invalid type settings $config->{type}"
33 0 ▶ unless exists $TYPES{ $config->{type} };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Dancer::Plugin::IRCNotice::TYPES{$config->{"type"}} 0 0 0
34  
35 # Add default port
36 0 ▶ $config->{host} .= ':6667' unless $config->{host} =~ /:\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $config->{"host"} =~ /:\d+$/ 0 0 0
37  
38 my $socket = IO::Socket::IP->new($config->{host})
39 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
40  
41 # TODO error handling srsly
42  
43 0 info "Registering as $config->{nick}";
44  
45 0 $socket->say("NICK $config->{nick}");
46 0 $socket->say("USER $config->{nick} . . :$config->{name}");
47  
48 0 ▶ while (my $line = $socket->getline) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = $socket->getline) 0 0 0
49 0 info "Got $line";
50  
51 0 ▶ if ($line =~ /End of \/MOTD/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ m[End of /MOTD]) 0 0 0
52 0 info "Sending notice to $config->{channel}";
53  
54 0 $socket->say("$TYPES{$config->{type}} $config->{channel} :$message");
55 0 $socket->say('QUIT');
56  
57 0 info 'Notice sent';
58 0 return;
59 }
60 }
61  
62 0 info 'Notice not sent';
63 0 return;
64 1 };
65  
66 1 register_plugin;
67  
68 1 1;
69 __END__
↑ Summary