More critic! Also use Encode instead of utf8::encode

This commit is contained in:
eleksir
2022-02-19 16:56:15 +03:00
parent 8bbb18bbc2
commit e31998ffcc
12 changed files with 112 additions and 64 deletions

View File

@@ -1,7 +1,7 @@
package Phrases;
# Общие модули - синтаксис, кодировки итд
use 5.018;
use 5.018; ## no critic (ProhibitImplicitImport)
use strict;
use warnings;
use utf8;
@@ -12,12 +12,12 @@ use Clone qw (clone);
use Log::Any qw ($log);
use Math::Random::Secure qw (irand);
# Чтобы "уж точно" использовать hiredis-биндинги, загрузим этот модуль перед Mojo::Redis
use Protocol::Redis::XS;
use Mojo::Redis;
use Mojo::IOLoop;
use Mojo::IOLoop::Signal;
use Protocol::Redis::XS ();
use Mojo::Redis ();
use Mojo::IOLoop ();
use Mojo::IOLoop::Signal ();
use Mojo::Util qw (trim);
use Data::Dumper;
use Data::Dumper qw (Dumper);
use Conf qw (LoadConf);
use Fortune qw (Fortune);
@@ -107,7 +107,7 @@ my $parse_message = sub {
$reply = KarmaSet (
$m->{chatid},
trim (substr $m->{message}, 0, -2),
substr $m->{message}, -2
substr $m->{message}, -2,
);
# Если у нас более одной строки - пусть с этим разбирается craniac, у него есть *мозги*
} else {
@@ -122,7 +122,7 @@ my $parse_message = sub {
$answer->{message} = $reply;
$self->json ($send_to)->notify (
$send_to => $answer
$send_to => $answer,
);
}
@@ -133,7 +133,7 @@ my $__signal_handler = sub {
my ($self, $name) = @_;
$log->info ("[INFO] Caught a signal $name");
if (defined $main::pidfile && -f $main::pidfile) {
if (defined $main::pidfile && -e $main::pidfile) {
unlink $main::pidfile;
}
@@ -146,7 +146,7 @@ sub RunPhrases {
$log->info ("[INFO] Connecting to $c->{server}, $c->{port}");
my $redis = Mojo::Redis->new (
sprintf 'redis://%s:%s/1', $c->{server}, $c->{port}
sprintf 'redis://%s:%s/1', $c->{server}, $c->{port},
);
$log->info ('[INFO] Registering connection-event callback');
@@ -163,11 +163,11 @@ sub RunPhrases {
my ($conn, $error) = @_;
$log->error ("[ERROR] Redis connection error: $error");
return;
}
},
);
return;
}
},
);
my $pubsub = $redis->pubsub;
@@ -178,13 +178,13 @@ sub RunPhrases {
$log->debug ("[DEBUG] Subscribing to $channel");
$sub->{$channel} = $pubsub->json ($channel)->listen (
$channel => sub { $parse_message->(@_); }
$channel => sub { $parse_message->(@_); },
);
}
Mojo::IOLoop::Signal->on (
TERM => $__signal_handler,
INT => $__signal_handler
INT => $__signal_handler,
);
do { Mojo::IOLoop->start } until Mojo::IOLoop->is_running;