| 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"
MC/DC0%0/1
$config->{"host"} ||= "chat.freenode.net"
$config->{"host"}
Truth table0%0/2
A
A= $config->{"host"}
| |||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | $config->{nick} ||= sprintf('dpin%04u', int(rand() * 10000)); | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$config->{"nick"} ||= sprintf("dpin%04u", int((rand()) * 10000))
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))
| |||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | $config->{name} ||= $config->{nick}; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$config->{"name"} ||= $config->{"nick"}
MC/DC0%0/2
$config->{"name"} ||= $config->{"nick"}
$config->{"name"}
$config->{"nick"}
Truth table0%0/3
A ||= B
A= $config->{"name"}B= $config->{"nick"}
| |||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | $config->{channel} ||= '#dpintest'; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$config->{"channel"} ||= "#dpintest"
MC/DC0%0/1
$config->{"channel"} ||= "#dpintest"
$config->{"channel"}
Truth table0%0/2
A
A= $config->{"channel"}
| |||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | fork and return if $config->{fork}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$config->{'fork'} && (fork && (return))
fork and return
MC/DC0%0/2
$config->{'fork'} && (fork && (return))
$config->{'fork'}
fork
Truth table0%0/3
A && B
A= $config->{'fork'}B= fork
| |||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | # Add default port | ||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | $config->{host} .= ':6667' unless $config->{host} =~ /:\d+$/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | my $socket = IO::Socket::IP->new($config->{host}) | ||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | or warning "Cannot create socket: $@" and return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
(my $socket = 'IO::Socket::IP'->new($config->{'host'})) || warning("Cannot create socket: $@") && (return)
warning("Cannot create socket: $@") and return
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: $@")
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 41 | 0 | info "Got $line"; | |||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if ($line =~ /End of \/MOTD/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 51 | 0 | return; | |||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 0 | info "Notice not sent"; | |||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | exit if $config->{fork}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 58 | 0 | return; | |||||||||||||||||||||||||||||||
| 59 | 1 | }; | |||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | 1 | register_plugin; | |||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | 1 | 1; | |||||||||||||||||||||||||||||||
| 64 | __END__ | ||||||||||||||||||||||||||||||||