From 97773defa7e822b505d0b3fb1f7e177ddfe168db Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Sun, 14 May 2017 01:23:10 +0300 Subject: [PATCH] Add perlcritic tests and make code compliant --- MANIFEST | 2 ++ lib/Plack/Middleware/BasicStyle.pm | 10 +++---- t/perlcritic.t | 10 +++++++ t/perlcriticrc | 43 ++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 t/perlcritic.t create mode 100644 t/perlcriticrc diff --git a/MANIFEST b/MANIFEST index 96b6cd1..26ebf91 100644 --- a/MANIFEST +++ b/MANIFEST @@ -2,5 +2,7 @@ Changes Makefile.PL MANIFEST README +perlcritic.t +perlcriticrc t/Plack-Middleware-BasicStyle.t lib/Plack/Middleware/BasicStyle.pm diff --git a/lib/Plack/Middleware/BasicStyle.pm b/lib/Plack/Middleware/BasicStyle.pm index 1692c8a..f207b35 100644 --- a/lib/Plack/Middleware/BasicStyle.pm +++ b/lib/Plack/Middleware/BasicStyle.pm @@ -12,7 +12,7 @@ use Plack::Util; use Plack::Util::Accessor qw/style any_content_type even_if_styled use_link_header/; our $VERSION = '0.001'; -our $DEFAULT_STYLE = < body { margin:40px auto; @@ -43,15 +43,15 @@ sub _content_type_ok { my $content_type = Plack::Util::header_get($hdrs, 'Content-Type'); return '' unless $content_type; - $content_type =~ m,text/html,i; + $content_type =~ m,text/html,is; } -sub call { +sub call { ## no critic (Complexity) my ($self, $env) = @_; if ($self->use_link_header) { my $req = Plack::Request->new($env); if (lc $req->path eq lc $self->use_link_header) { - my $days30 = 30 * 86400; + my $days30 = 30 * 86_400; my @hdrs = ( 'Content-Length' => length $self->style, 'Content-Type' => 'text/css', @@ -77,7 +77,7 @@ sub call { $doctype_end //= $offset_end if $tagname eq 'doctype'; $styled = 1 if $tagname eq 'style'; $styled = 1 if $tagname eq 'link' - && ($attr->{rel} // '') =~ /stylesheet/i; + && ($attr->{rel} // '') =~ /stylesheet/is; }; my $p = HTML::Parser->new(api_version => 3); diff --git a/t/perlcritic.t b/t/perlcritic.t new file mode 100644 index 0000000..c0ba2bf --- /dev/null +++ b/t/perlcritic.t @@ -0,0 +1,10 @@ +#!/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'; +all_critic_ok; diff --git a/t/perlcriticrc b/t/perlcriticrc new file mode 100644 index 0000000..1e7f484 --- /dev/null +++ b/t/perlcriticrc @@ -0,0 +1,43 @@ +severity = 1 + +[-BuiltinFunctions::ProhibitComplexMappings] +[-CodeLayout::RequireTidyCode] +[-ControlStructures::ProhibitPostfixControls] +[-ControlStructures::ProhibitUnlessBlocks] +[-Documentation::PodSpelling] +[-Documentation::RequirePodLinksIncludeText] +[-InputOutput::RequireBracedFileHandleWithPrint] +[-InputOutput::RequireCheckedClose] +[-InputOutput::RequireCheckedSyscalls] +[-Modules::ProhibitAutomaticExportation] +[-References::ProhibitDoubleSigils] +[-RegularExpressions::ProhibitEnumeratedClasses] +[-RegularExpressions::ProhibitUnusualDelimiters] +[-RegularExpressions::RequireBracesForMultiline] +[-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 + +[TestingAndDebugging::ProhibitNoWarnings] +allow_with_category_restriction = 1 -- 2.39.2