Perlcritic overhaul, update cpanfile
This commit is contained in:
22
lib/Conf.pm
22
lib/Conf.pm
@@ -1,14 +1,13 @@
|
||||
package Conf;
|
||||
# loads config
|
||||
# Загружает конфиг файл
|
||||
|
||||
use 5.018;
|
||||
use 5.018; ## no critic (ProhibitImplicitImport)
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
use open qw (:std :utf8);
|
||||
use English qw ( -no_match_vars );
|
||||
use Encode qw (encode);
|
||||
use JSON::XS;
|
||||
use JSON::XS ();
|
||||
|
||||
use version; our $VERSION = qw (1.0);
|
||||
use Exporter qw (import);
|
||||
@@ -16,17 +15,26 @@ our @EXPORT_OK = qw (LoadConf);
|
||||
|
||||
sub LoadConf {
|
||||
my $c = 'data/config.json';
|
||||
open my $CH, '<', $c or die "[FATAL] No conf at $c: $OS_ERROR\n";
|
||||
my $json;
|
||||
my $CH;
|
||||
|
||||
unless (open $CH, '<', $c) {
|
||||
die "[FATAL] No conf at $c: $OS_ERROR\n";
|
||||
}
|
||||
|
||||
my $len = (stat $c) [7];
|
||||
my $json;
|
||||
my $readlen = read $CH, $json, $len;
|
||||
$json = encode 'UTF-8', $json;
|
||||
|
||||
unless ($readlen) {
|
||||
close $CH; ## no critic (InputOutput::RequireCheckedSyscalls
|
||||
die "[FATAL] Unable to read $c: $OS_ERROR\n";
|
||||
}
|
||||
|
||||
if ($readlen != $len) {
|
||||
close $CH; ## no critic (InputOutput::RequireCheckedSyscalls
|
||||
die "[FATAL] File $c is $len bytes on disk, but we read only $readlen bytes\n";
|
||||
}
|
||||
|
||||
close $CH; ## no critic (InputOutput::RequireCheckedSyscalls
|
||||
my $j = JSON::XS->new->utf8->relaxed;
|
||||
return $j->decode ($json);
|
||||
|
||||
27
lib/Misc.pm
27
lib/Misc.pm
@@ -1,7 +1,7 @@
|
||||
package Misc;
|
||||
|
||||
# Общие модули - синтаксис, кодировки итд
|
||||
use 5.018;
|
||||
use 5.018; ## no critic (ProhibitImplicitImport)
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
@@ -10,13 +10,12 @@ use open qw (:std :utf8);
|
||||
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 Data::Dumper;
|
||||
use Protocol::Redis::XS ();
|
||||
use Mojo::Redis ();
|
||||
use Mojo::IOLoop ();
|
||||
use Mojo::IOLoop::Signal ();
|
||||
use Data::Dumper qw (Dumper);
|
||||
|
||||
use Conf qw (LoadConf);
|
||||
|
||||
@@ -136,7 +135,7 @@ my $parse_message = sub {
|
||||
$log->debug ("[DEBUG] Sending message to channel $send_to " . Dumper ($answer));
|
||||
|
||||
$self->json ($send_to)->notify (
|
||||
$send_to => $answer
|
||||
$send_to => $answer,
|
||||
);
|
||||
|
||||
return;
|
||||
@@ -146,7 +145,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;
|
||||
}
|
||||
|
||||
@@ -159,7 +158,7 @@ sub RunMisc {
|
||||
$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');
|
||||
@@ -176,11 +175,11 @@ sub RunMisc {
|
||||
my ($conn, $error) = @_;
|
||||
$log->error ("[ERROR] Redis connection error: $error");
|
||||
return;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
my $pubsub = $redis->pubsub;
|
||||
@@ -191,13 +190,13 @@ sub RunMisc {
|
||||
$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