From ca8f39c8fbd0124ff04ad7c31e1bc9cf2377abc0 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Sat, 16 May 2015 21:59:16 +0300 Subject: [PATCH] Add perlcritic test and appease perlcritic --- MANIFEST | 2 ++ lib/App/RemoteGnokii.pm | 11 +++++------ t/perlcritic.t | 11 +++++++++++ t/perlcriticrc | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 t/perlcritic.t create mode 100644 t/perlcriticrc diff --git a/MANIFEST b/MANIFEST index a8c0927..e7d8f3d 100644 --- a/MANIFEST +++ b/MANIFEST @@ -8,3 +8,5 @@ rg-action rg-psgi rg-smsd t/App-RemoteGnokii.t +t/perlcritic.t +t/perlcriticrc diff --git a/lib/App/RemoteGnokii.pm b/lib/App/RemoteGnokii.pm index c03ff92..718ac93 100644 --- a/lib/App/RemoteGnokii.pm +++ b/lib/App/RemoteGnokii.pm @@ -4,7 +4,6 @@ use 5.014000; use strict; use warnings; our $VERSION = '0.000_001'; -$VERSION = eval $VERSION; use Config::Any; use File::Copy qw/move/; @@ -13,7 +12,7 @@ use Plack::Request; my $cfg; -sub cfg ($){ +sub cfg ($){ ## no critic (ProhibitSubroutinePrototypes) unless ($cfg) { $cfg = Config::Any->load_stems({stems => [$ENV{RGCONFIG} // '/etc/rg'], use_ext => 1, flatten_to_hash => 1}); my @cfg = values %$cfg; @@ -26,8 +25,8 @@ sub cfg ($){ sub sendsms { my ($number, $text) = @_; my ($fh, $file) = tempfile 'smsXXXX', TMPDIR => 1; - print $fh "$number\n$text"; - close $fh; + print $fh "$number\n$text" or warn "print: $!"; ## no critic (RequireCarping) + close $fh or warn "close: $!"; ## no critic (RequireCarping) move $file, cfg 'spool'; } @@ -36,7 +35,7 @@ sub sendsms { sub action { my ($number, $date, $text) = @_; my $password = cfg 'password'; - sendsms cfg 'number', <new(shift); - my @numbers = split ',', $r->param('numbers'); + my @numbers = split /,/s, $r->param('numbers'); my $password = $r->param('password'); return [403, ['Content-Type', 'text/plain'], ['Bad password']] unless $password eq $correct_password; my $text = $r->param('text'); diff --git a/t/perlcritic.t b/t/perlcritic.t new file mode 100644 index 0000000..3e24085 --- /dev/null +++ b/t/perlcritic.t @@ -0,0 +1,11 @@ +#!/usr/bin/perl +use v5.14; +use warnings; + +use Test::More; + +BEGIN { plan skip_all => '$ENV{RELEASE_TESTING} is false' unless $ENV{RELEASE_TESTING} } +use Test::Perl::Critic -profile => 't/perlcriticrc'; +use Test::More tests => 1; + +critic_ok 'lib/App/RemoteGnokii.pm'; diff --git a/t/perlcriticrc b/t/perlcriticrc new file mode 100644 index 0000000..5815f07 --- /dev/null +++ b/t/perlcriticrc @@ -0,0 +1,36 @@ +severity = 1 + +[-BuiltinFunctions::ProhibitComplexMappings] +[-CodeLayout::RequireTidyCode] +[-ControlStructures::ProhibitPostfixControls] +[-ControlStructures::ProhibitUnlessBlocks] +[-Documentation::PodSpelling] +[-Documentation::RequirePodLinksIncludeText] +[-InputOutput::RequireBracedFileHandleWithPrint] +[-Modules::ProhibitAutomaticExportation] +[-References::ProhibitDoubleSigils] +[-RegularExpressions::ProhibitEnumeratedClasses] +[-RegularExpressions::RequireLineBoundaryMatching] +[-Subroutines::RequireFinalReturn] +[-ValuesAndExpressions::ProhibitConstantPragma] +[-ValuesAndExpressions::ProhibitEmptyQuotes] +[-ValuesAndExpressions::ProhibitLeadingZeros] +[-ValuesAndExpressions::ProhibitMagicNumbers] +[-ValuesAndExpressions::ProhibitNoisyQuotes] +[-Variables::ProhibitLocalVars] +[-Variables::ProhibitPackageVars] +[-Variables::ProhibitPunctuationVars] + +[BuiltinFunctions::ProhibitStringyEval] +allow_includes = 1 + +[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