From a5dd5c0dee4a02197fe6e9bc36424d2befdfb816 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Sat, 21 May 2016 18:38:37 +0100 Subject: [PATCH] Make perlcritic happy and add perlcritic test --- MANIFEST | 2 ++ lib/App/MusicExpo.pm | 17 ++++++++--------- t/perlcritic.t | 10 ++++++++++ t/perlcriticrc | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 t/perlcritic.t create mode 100644 t/perlcriticrc diff --git a/MANIFEST b/MANIFEST index 96e9c07..3890375 100644 --- a/MANIFEST +++ b/MANIFEST @@ -5,6 +5,8 @@ README t/App-MusicExpo.t t/musicexpo-cache.t t/musicexpo.t +t/perlcritic.t +t/perlcriticrc lib/App/MusicExpo.pm musicexpo musicexpo.css diff --git a/lib/App/MusicExpo.pm b/lib/App/MusicExpo.pm index 7cdf6e2..cf16468 100644 --- a/lib/App/MusicExpo.pm +++ b/lib/App/MusicExpo.pm @@ -1,5 +1,5 @@ package App::MusicExpo; -use v5.14; +use 5.014000; use strict; use warnings; @@ -29,9 +29,9 @@ our $cache=''; our $template=''; GetOptions ( - "template:s" => \$template, - "prefix:s" => \$prefix, - "cache:s" => \$cache, + 'template:s' => \$template, + 'prefix:s' => \$prefix, + 'cache:s' => \$cache, ); sub flacinfo{ @@ -54,7 +54,7 @@ sub flacinfo{ sub mp3info{ my $file=$_[0]; my %tag = map { encode 'UTF-8', $_ } %{get_mp3tag $file}; - my @trkn = split '/', $tag{TRACKNUM} // ''; + my @trkn = split m#/#s, $tag{TRACKNUM} // ''; freeze +{ format => 'MP3', @@ -86,7 +86,7 @@ sub vorbisinfo{ } } -sub mp4_format ($){ +sub mp4_format ($){ ## no critic (ProhibitSubroutinePrototypes) my $encoding = $_[0]; return 'AAC' if $encoding eq 'mp4a'; return 'ALAC' if $encoding eq 'alac'; @@ -128,9 +128,8 @@ sub normalizer{ sub make_fragment{ join '-', map { lc =~ y/a-z0-9/_/csr } @_ } sub run { - my %info = %info; if ($cache) { - tie my %cache, 'DB_File', $cache, O_RDWR|O_CREAT, 0644; + tie my %cache, 'DB_File', $cache, O_RDWR|O_CREAT, 0644; ## no critic (ProhibitTie) $info{$_} = memoize $info{$_}, INSTALL => undef, NORMALIZER => \&normalizer, LIST_CACHE => 'FAULT', SCALAR_CACHE => [HASH => \%cache] for keys %info; } @@ -164,7 +163,7 @@ sub run { @files = sort { $a->{title} cmp $b->{title} } @files; $ht->param(files => \@files, prefix => $prefix); - print $ht->output; + print $ht->output; ## no critic (RequireCheckedSyscalls) } $default_template = <<'HTML'; diff --git a/t/perlcritic.t b/t/perlcritic.t new file mode 100644 index 0000000..79e93dc --- /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 'lib' diff --git a/t/perlcriticrc b/t/perlcriticrc new file mode 100644 index 0000000..40b151e --- /dev/null +++ b/t/perlcriticrc @@ -0,0 +1,41 @@ +severity = 1 + +[-BuiltinFunctions::ProhibitComplexMappings] +[-CodeLayout::RequireTidyCode] +[-ControlStructures::ProhibitPostfixControls] +[-ControlStructures::ProhibitUnlessBlocks] +[-Documentation::PodSpelling] +[-Documentation::RequirePodLinksIncludeText] +[-InputOutput::RequireBracedFileHandleWithPrint] +[-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.30.2