Perlcritic overhaul, add missing 'use module', update cpanfile, replace Mojo::Log with Log::Any
* Use more strict policy in perlcritic (add more policies) * Add missing Use Encode and Use File::Spec in Craniac.pm * Replace Mojo::Log with Log::Any, as Log::Any can catch stacktraces * Update cpanfile
This commit is contained in:
@@ -9,7 +9,7 @@ package Craniac;
|
||||
# проигнорировать.
|
||||
|
||||
# Общие модули - синтаксис, кодировки итд
|
||||
use 5.018;
|
||||
use 5.018; ## no critic (ProhibitImplicitImport)
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
@@ -17,14 +17,17 @@ use open qw (:std :utf8);
|
||||
use English qw ( -no_match_vars );
|
||||
|
||||
# Модули для работы приложения
|
||||
use Data::Dumper qw (Dumper);
|
||||
use Digest::SHA qw (sha1_base64);
|
||||
use Hailo;
|
||||
use Mojo::IOLoop;
|
||||
use Mojo::IOLoop::Signal;
|
||||
use Mojo::Log;
|
||||
use Encode qw (encode_utf8);
|
||||
use File::Spec ();
|
||||
use Hailo ();
|
||||
use Log::Any qw ($log);
|
||||
use Mojo::IOLoop ();
|
||||
use Mojo::IOLoop::Signal ();
|
||||
# Чтобы "уж точно" использовать hiredis-биндинги, загрузим этот модуль перед Mojo::Redis
|
||||
use Protocol::Redis::XS;
|
||||
use Mojo::Redis;
|
||||
use Protocol::Redis::XS ();
|
||||
use Mojo::Redis ();
|
||||
use Math::Random::Secure qw (irand);
|
||||
use Text::Fuzzy qw (distance_edits);
|
||||
|
||||
@@ -42,22 +45,7 @@ sub brains (@);
|
||||
sub RunCraniac ();
|
||||
|
||||
my $c = LoadConf ();
|
||||
my $loglevel = $c->{'loglevel'} // 'info';
|
||||
my $fwd_cnt = $c->{'forward_max'} // 5;
|
||||
my $logfile;
|
||||
my $log;
|
||||
|
||||
if (defined $c->{'log'}) {
|
||||
$logfile = $c->{'log'};
|
||||
} elsif (defined $c->{'debug_log'}) {
|
||||
$logfile = $c->{'debug_log'};
|
||||
}
|
||||
|
||||
if (defined $logfile) {
|
||||
$log = Mojo::Log->new (path => $logfile, level => $loglevel);
|
||||
} else {
|
||||
$log = Mojo::Log->new (path => '/dev/null', level => 'fatal');
|
||||
}
|
||||
|
||||
my $hailo;
|
||||
|
||||
@@ -127,7 +115,7 @@ sub brains (@) {
|
||||
$hailo->{$chatid} = eval {
|
||||
Hailo->new (
|
||||
brain => $brainname,
|
||||
order => 3
|
||||
order => 3,
|
||||
);
|
||||
};
|
||||
|
||||
@@ -267,8 +255,8 @@ my $parse_message = sub {
|
||||
userid => $userid,
|
||||
chatid => $chatid,
|
||||
plugin => $m->{plugin},
|
||||
message => $reply
|
||||
}
|
||||
message => $reply,
|
||||
},
|
||||
);
|
||||
}
|
||||
} else {
|
||||
@@ -312,8 +300,8 @@ my $parse_message = sub {
|
||||
userid => $userid,
|
||||
chatid => $chatid,
|
||||
plugin => $m->{plugin},
|
||||
message => $reply
|
||||
}
|
||||
message => $reply,
|
||||
},
|
||||
);
|
||||
|
||||
return;
|
||||
@@ -337,8 +325,8 @@ my $parse_message = sub {
|
||||
userid => $userid,
|
||||
chatid => $chatid,
|
||||
plugin => $m->{plugin},
|
||||
message => $reply
|
||||
}
|
||||
message => $reply,
|
||||
},
|
||||
);
|
||||
|
||||
return;
|
||||
@@ -380,8 +368,8 @@ my $parse_message = sub {
|
||||
userid => $userid,
|
||||
chatid => $chatid,
|
||||
plugin => $m->{plugin},
|
||||
message => $reply
|
||||
}
|
||||
message => $reply,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -408,7 +396,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;
|
||||
}
|
||||
|
||||
@@ -421,7 +409,7 @@ sub RunCraniac () {
|
||||
$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');
|
||||
@@ -438,11 +426,11 @@ sub RunCraniac () {
|
||||
my ($conn, $error) = @_;
|
||||
$log->error ("[ERROR] Redis connection error: $error");
|
||||
return;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
my $pubsub = $redis->pubsub;
|
||||
@@ -453,13 +441,13 @@ sub RunCraniac () {
|
||||
$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;
|
||||
|
||||
Reference in New Issue
Block a user