| 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"
MC/DC0%0/1
$config->{"host"} ||= "chat.freenode.net"
$config->{"host"}
Truth table0%0/2
A
A= $config->{"host"}
| |||||||||||||||||||||||||||||||||
| 27 | 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))
| |||||||||||||||||||||||||||||||||
| 28 | 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"}
| |||||||||||||||||||||||||||||||||
| 29 | 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"}
| |||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | $config->{type} ||= 'notice'; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$config->{"type"} ||= "notice"
MC/DC0%0/1
$config->{"type"} ||= "notice"
$config->{"type"}
Truth table0%0/2
A
A= $config->{"type"}
| |||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | croak "Invalid type settings $config->{type}" | ||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | unless exists $TYPES{ $config->{type} }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | # Add default port | ||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | $config->{host} .= ':6667' unless $config->{host} =~ /:\d+$/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | my $socket = IO::Socket::IP->new($config->{host}) | ||||||||||||||||||||||||||||||||
| 39 | 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: $@")
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 49 | 0 | info "Got $line"; | |||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ($line =~ /End of \/MOTD/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||