diff --git a/.perlcriticrc b/.perlcriticrc index 5c50483..6893176 100644 --- a/.perlcriticrc +++ b/.perlcriticrc @@ -1,3 +1,18 @@ +#!/usr/bin/env perlcritic +# Задействованные модули критика: +# +# Perl::Critic::More +# Perl::Critic::Pulp +# Perl::Critic::TooMuchCode +# Perl::Critic::Lax +# Perl::Critic::CognitiveComplexity +# Perl::Critic::Policy::CompileTime +# Perl::Critic::Policy::ProhibitImplicitImport +# Perl::Critic::Policy::Dynamic::NoIndirect +# Perl::Critic::StricterSubs +# Perl::Critic::Policy::ProhibitImplicitImport +# Perl::Critic::Policy::CodeLayout::RequireUseUTF8 + [-CodeLayout::RequireTidyCode] [-ValuesAndExpressions::ProhibitMagicNumbers] [-ControlStructures::ProhibitUnlessBlocks] @@ -14,4 +29,14 @@ [-Subroutines::ProhibitExplicitReturnUndef] [-RegularExpressions::ProhibitEscapedMetacharacters] [-InputOutput::RequireBriefOpen] -[-Modules::ProhibitExcessMainComplexity] \ No newline at end of file +[-Modules::ProhibitExcessMainComplexity] +[-Editor::RequireEmacsFileVariables] +[-TooMuchCode::ProhibitUnnecessaryUTF8Pragma] +[-ValuesAndExpressions::RequireConstantOnLeftSideOfEquality] +[-Lax::RequireConstantOnLeftSideOfEquality::ExceptEq] +[-Lax::ProhibitEmptyQuotes::ExceptAsFallback] +[-TooMuchCode::ProhibitDuplicateLiteral] +[-CodeLayout::RequireASCII] +[-ErrorHandling::RequireUseOfExceptions] +[-Miscellanea::ProhibitUnrestrictedNoCritic] +[-ValuesAndExpressions::RestrictLongStrings] diff --git a/bin/aleesa-games b/bin/aleesa-games index 172c47d..86c2e14 100755 --- a/bin/aleesa-games +++ b/bin/aleesa-games @@ -1,6 +1,6 @@ #!/usr/bin/perl -use 5.018; +use 5.018; ## no critic (ProhibitImplicitImport) use strict; use warnings; use utf8; @@ -29,9 +29,10 @@ no Cwd; use Cwd::utf8 qw (chdir abs_path); use File::Basename qw (basename dirname); use File::Path qw (make_path); +use File::Spec (); use Log::Any qw ($log); -use Log::Any::Adapter; -use Log::Any::For::Std; +use Log::Any::Adapter (); +use Log::Any::For::Std (); use POSIX qw (setgid setuid setsid); use Conf qw (LoadConf); @@ -70,8 +71,8 @@ if ($UID == 0) { make_path ( $piddir, { uid => $uid, - group => $gid - } + group => $gid, + }, ); } @@ -82,8 +83,8 @@ if ($UID == 0) { make_path ( $logdir, { uid => $uid, - group => $gid - } + group => $gid, + }, ) or die "Unable to create $logdir: $OS_ERROR\n"; } } @@ -103,14 +104,14 @@ if (defined $logfile) { # verbosity paticulary for CHI. Log::Any::Adapter->set ( { - category => 'CHI::Driver' + category => 'CHI::Driver', }, 'File', $logfile, - log_level => 'warn' + log_level => 'warn', ); } else { - Log::Any::Adapter->set ('File', '/dev/null'); + Log::Any::Adapter->set ('File', File::Spec->devnull); } # По-умолчанию, демонизируемся, если явно не указано, что этого делать не надо @@ -126,7 +127,7 @@ my $apath = abs_path $PROGRAM_NAME; unless (defined $apath) { $log->fatal ("[FATAL] Unable to get abs_path: $OS_ERROR\n"); exit 1; -}; +} my $pidfile = sprintf '%s/%s.pid', $piddir, basename $apath; $log->info ("[INFO] Creating pidfile at $pidfile"); @@ -152,7 +153,7 @@ $PROGRAM_NAME = abs_path $PROGRAM_NAME; ## no critic (Variables::Re # И запустим уже наш сервис RunGames (); -if (-f $pidfile) { +if (-e $pidfile) { unlink $pidfile; } @@ -160,11 +161,11 @@ exit 0; sub daemonize { __fork (); - POSIX::setsid (); - open STDIN, '<', '/dev/null'; ## no critic (InputOutput::RequireCheckedSyscalls, InputOutput::RequireCheckedOpen) + setsid (); + open STDIN, '<', File::Spec->devnull; ## no critic (InputOutput::RequireCheckedSyscalls, InputOutput::RequireCheckedOpen) # we handle STDOUT && STDERR via Log::Any::For::Std, so do not close them explicitly - #open STDOUT, '>', '/dev/null'; ## no critic (InputOutput::RequireCheckedSyscalls, InputOutput::RequireCheckedOpen) - #open STDERR, '>', '/dev/null'; ## no critic (InputOutput::RequireCheckedSyscalls, InputOutput::RequireCheckedOpen) + #open STDOUT, '>', File::Spec->devnull; ## no critic (InputOutput::RequireCheckedSyscalls, InputOutput::RequireCheckedOpen) + #open STDERR, '>', File::Spec->devnull; ## no critic (InputOutput::RequireCheckedSyscalls, InputOutput::RequireCheckedOpen) __fork (); umask 0; return; @@ -188,7 +189,7 @@ sub __fork { sub __signal_handler { $log->info ("[INFO] Caught a signal $OS_ERROR"); - if (-f $pidfile) { + if (-e $pidfile) { unlink $pidfile; } diff --git a/bin/gamedata_seed.pl b/bin/gamedata_seed.pl index 608a191..78945ae 100644 --- a/bin/gamedata_seed.pl +++ b/bin/gamedata_seed.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -use 5.018; +use 5.018; ## no critic (ProhibitImplicitImport) use strict; use warnings; use utf8; diff --git a/cpanfile b/cpanfile index af53140..713bdde 100644 --- a/cpanfile +++ b/cpanfile @@ -1,3 +1,4 @@ +## no critic requires 'Carp', '==1.50'; requires 'Clone', '==0.45'; requires 'Cwd::utf8', '==0.011'; @@ -10,6 +11,7 @@ requires 'English', '0'; requires 'Exporter', '==5.74'; requires 'File::Basename', '0'; requires 'File::Path', '==2.18'; +requires 'File::Spec', '==3.75'; requires 'JSON::XS', '==4.03'; requires 'Log::Any', '==1.710'; requires 'Log::Any::Adapter', '==1.710'; diff --git a/lib/Conf.pm b/lib/Conf.pm index 9f6928c..f583667 100644 --- a/lib/Conf.pm +++ b/lib/Conf.pm @@ -1,14 +1,14 @@ 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); diff --git a/lib/Games.pm b/lib/Games.pm index 603314b..98aba3b 100644 --- a/lib/Games.pm +++ b/lib/Games.pm @@ -1,7 +1,7 @@ package Games; # Общие модули - синтаксис, кодировки итд -use 5.018; +use 5.018; ## no critic (ProhibitImplicitImport) use strict; use warnings; use utf8; @@ -9,14 +9,13 @@ use open qw (:std :utf8); # Модули для работы приложения use Clone qw (clone); -use Data::Dumper; +use Data::Dumper qw (Dumper); 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 Conf qw (LoadConf); use Games::Archeologist qw (Dig); @@ -99,7 +98,7 @@ my $parse_message = sub { if (defined $answer->{message}) { $self->json ($send_to)->notify ( - $send_to => $answer + $send_to => $answer, ); } @@ -110,7 +109,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; } @@ -123,7 +122,7 @@ sub RunGames { $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'); @@ -140,11 +139,11 @@ sub RunGames { my ($conn, $error) = @_; $log->error ("[ERROR] Redis connection error: $error"); return; - } + }, ); return; - } + }, ); my $pubsub = $redis->pubsub; @@ -155,13 +154,13 @@ sub RunGames { $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; diff --git a/lib/Games/Archeologist.pm b/lib/Games/Archeologist.pm index 1bbedfb..1457eca 100644 --- a/lib/Games/Archeologist.pm +++ b/lib/Games/Archeologist.pm @@ -1,12 +1,12 @@ package Games::Archeologist; -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 DBI; +use DBI (); use Log::Any qw ($log); use Math::Random::Secure qw (irand); diff --git a/lib/Games/Fisher.pm b/lib/Games/Fisher.pm index cca30fd..e253bd5 100644 --- a/lib/Games/Fisher.pm +++ b/lib/Games/Fisher.pm @@ -1,12 +1,12 @@ package Games::Fisher; -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 DBI; +use DBI (); use Log::Any qw ($log); use Math::Random::Secure qw (irand); diff --git a/lib/Games/Gamestat.pm b/lib/Games/Gamestat.pm index 7150364..9e3088f 100644 --- a/lib/Games/Gamestat.pm +++ b/lib/Games/Gamestat.pm @@ -1,12 +1,12 @@ package Games::Gamestat; # Stores and calculates player stats for games -use 5.018; +use 5.018; ## no critic (ProhibitImplicitImport) use strict; use warnings; use utf8; use open qw (:std :utf8); -use DBI; +use DBI (); use English qw ( -no_match_vars ); use File::Path qw (make_path); use Mojo::Util qw (trim); diff --git a/lib/Util.pm b/lib/Util.pm index 6a8b8f7..012b73f 100644 --- a/lib/Util.pm +++ b/lib/Util.pm @@ -1,6 +1,6 @@ package Util; -use 5.018; +use 5.018; ## no critic (ProhibitImplicitImport) use strict; use warnings; use utf8; @@ -8,7 +8,7 @@ use open qw (:std :utf8); use English qw ( -no_match_vars ); use Digest::SHA qw (sha1_base64); -use Encode; +use Encode qw (encode_utf8); use version; our $VERSION = qw (1.0); use Exporter qw (import);