From dcd72991e2d01ab1465afa494c0b6b4a1fd36e25 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Sun, 7 Dec 2014 00:45:28 +0200 Subject: [PATCH] Use perlcritic --- MANIFEST | 2 ++ lib/Gruntmaster/Data.pm | 14 +++++++------- t/perlcritic.t | 12 ++++++++++++ t/perlcriticrc | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 t/perlcritic.t create mode 100644 t/perlcriticrc diff --git a/MANIFEST b/MANIFEST index c3bc284..618fefa 100644 --- a/MANIFEST +++ b/MANIFEST @@ -15,3 +15,5 @@ MANIFEST README t/Gruntmaster-Data.t t/tools.t +t/perlcritic.t +t/perlcriticrc diff --git a/lib/Gruntmaster/Data.pm b/lib/Gruntmaster/Data.pm index b274443..694fc8e 100644 --- a/lib/Gruntmaster/Data.pm +++ b/lib/Gruntmaster/Data.pm @@ -29,14 +29,14 @@ use constant JOBS_PER_PAGE => 10; sub dynsub{ our ($name, $sub) = @_; - no strict 'refs'; + no strict 'refs'; ## no critic (Strict) *$name = subname $name => $sub } BEGIN { for my $rs (qw/contest contest_problem job open problem user/) { my $rsname = ucfirst $rs; - $rsname =~ s/_([a-z])/\u$1/g; + $rsname =~ s/_([a-z])/\u$1/gs; dynsub PL_N($rs) => sub { $_[0]->resultset($rsname) }; dynsub $rs => sub { $_[0]->resultset($rsname)->find($_[1]) }; } @@ -66,15 +66,15 @@ sub standings { next if $time < 0; my $value = $job->problem->value; my $factor = $job->result ? 0 : 1; - $factor = $1 / 100 if $job->result_text =~ /^(\d+ )/; + $factor = $1 / 100 if $job->result_text =~ /^(\d+ )/s; $scores{$job->owner->id}{$job->problem->id} = int ($factor * calc_score ($value, $time, $tries{$job->owner->id}{$job->problem->id}++, $ct->stop - $ct->start)); } else { - no warnings 'numeric'; + no warnings 'numeric'; ## no critic (ProhibitNoWarnings) $scores{$job->owner->id}{$job->problem->id} = 0 + $job->result_text || ($job->result ? 0 : 100) } } - my @st = sort { $b->{score} <=> $a->{score} or $a->{user}->id cmp $b->{user}->id} map { + my @st = sort { $b->{score} <=> $a->{score} or $a->{user}->id cmp $b->{user}->id} map { ## no critic (ProhibitReverseSortBlock) my $user = $_; +{ user => $self->user($user), @@ -91,7 +91,7 @@ sub standings { sub user_list { my $rs = $_[0]->users->search(undef, {order_by => 'name', columns => USER_PUBLIC_COLUMNS}); - [ map +{ $_->get_columns }, $rs->all ] + [ map { { $_->get_columns } } $rs->all ] } sub user_entry { @@ -118,7 +118,7 @@ sub problem_entry { my ($self, $id, $contest, $user) = @_; my $pb = $self->problems->find($id, {columns => PROBLEM_PUBLIC_COLUMNS, prefetch => 'owner'}); my $running = $contest && $self->contest($contest)->is_running; - eval { + eval { ## no critic (RequireCheckingReturnValueOfEval) $self->opens->create({ contest => $contest, problem => $id, diff --git a/t/perlcritic.t b/t/perlcritic.t new file mode 100644 index 0000000..1a4ac7a --- /dev/null +++ b/t/perlcritic.t @@ -0,0 +1,12 @@ +#!/usr/bin/perl +use v5.14; +use warnings; + +use Test::More; + +BEGIN { plan skip_all => '$ENV{RELEASE_TESTING} is false' unless $ENV{RELEASE_TESTING} } +plan tests => 1; + +use Test::Perl::Critic -profile => 't/perlcriticrc'; + +critic_ok 'lib/Gruntmaster/Data.pm'; diff --git a/t/perlcriticrc b/t/perlcriticrc new file mode 100644 index 0000000..c80009c --- /dev/null +++ b/t/perlcriticrc @@ -0,0 +1,32 @@ +severity = 1 + +[-BuiltinFunctions::ProhibitComplexMappings] +[-CodeLayout::RequireTidyCode] +[-ControlStructures::ProhibitPostfixControls] +[-ControlStructures::ProhibitUnlessBlocks] +[-Documentation::PodSpelling] +[-Documentation::RequirePodLinksIncludeText] +[-InputOutput::RequireBracedFileHandleWithPrint] +[-Modules::RequireExplicitPackage] +[-References::ProhibitDoubleSigils] +[-RegularExpressions::ProhibitEnumeratedClasses] +[-RegularExpressions::RequireLineBoundaryMatching] +[-Subroutines::RequireFinalReturn] +[-ValuesAndExpressions::ProhibitConstantPragma] +[-ValuesAndExpressions::ProhibitEmptyQuotes] +[-ValuesAndExpressions::ProhibitMagicNumbers] +[-ValuesAndExpressions::ProhibitNoisyQuotes] +[-Variables::ProhibitLocalVars] +[-Variables::ProhibitPackageVars] +[-Variables::ProhibitPunctuationVars] + +[RegularExpressions::RequireExtendedFormatting] +minimum_regex_length_to_complain_about = 20 + +[Documentation::RequirePodSections] +lib_sections = NAME | SYNOPSIS | DESCRIPTION | AUTHOR | COPYRIGHT AND LICENSE +script_sections = NAME | SYNOPSIS | DESCRIPTION | AUTHOR | COPYRIGHT AND LICENSE + +[Subroutines::RequireArgUnpacking] +short_subroutine_statements = 5 +allow_subscripts = 1 -- 2.39.2