Add perlcritic test and make code comply
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 14 Nov 2015 18:48:42 +0000 (18:48 +0000)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 14 Nov 2015 18:48:42 +0000 (18:48 +0000)
MANIFEST
lib/POE/Component/IRC/Plugin/Infobot.pm
t/perlcritic.t [new file with mode: 0644]
t/perlcriticrc [new file with mode: 0644]

index 7000280784ed992d8d902a5df361268c1104785e..ea690b5371c3fe861bb94248e53aaa19b392fa47 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -3,4 +3,6 @@ Makefile.PL
 MANIFEST
 README
 t/POE-Component-IRC-Plugin-Infobot.t
+t/perlcritic.t
+t/perlcriticrc
 lib/POE/Component/IRC/Plugin/Infobot.pm
index c2969b63b321d00dda1ddc6235f2bae2f444390a..69de38c5f0d2895edbf022d3a16b218c441f7b66 100644 (file)
@@ -3,6 +3,7 @@ package POE::Component::IRC::Plugin::Infobot;
 use 5.014000;
 use strict;
 use warnings;
+use re '/s';
 
 our $VERSION = '0.001002';
 
@@ -11,13 +12,13 @@ use DB_File;
 use IRC::Utils qw/parse_user/;
 use POE::Component::IRC::Plugin qw/PCI_EAT_NONE/;
 
-use constant +{
+use constant +{ ## no critic (Capitalization)
        OK => [ 'sure, %s', 'ok, %s', 'gotcha, %s'],
        A_IS_B => [ '%s is %s', 'I think %s is %s', 'hmmm... %s is %s', 'it has been said that %s is %s', '%s is probably %s', 'rumour has it %s is %s', 'i heard %s was %s', 'somebody said %s is %s', 'i guess %s is %s', 'well, %s is %s', '%s is, like, %s', 'methinks %s is %s'],
        I_DONT_KNOW => [ 'I don\'t know, %s', 'Dunno, %s', 'No idea, %s', '%s: huh?', 'nem tudom, %s', 'anlamıyorum, %s', 'bilmiyorum, %s', 'nu ştiu d\'astea, %s', 'Je ne sais pas, %s', 'Я не знаю, %s'],
 };
 
-sub new {
+sub new { ## no critic (RequireArgUnpacking)
        my $class = shift;
        my $self = {
                filename => 'factoids.db',
@@ -25,7 +26,7 @@ sub new {
        };
 
        my %db;
-       $self->{dbobj} = tie %db, DB_File => $self->{filename} if defined $self->{filename};
+       $self->{dbobj} = tie %db, DB_File => $self->{filename} if defined $self->{filename}; ## no critic (ProhibitTie)
        $self->{db} = \%db;
        bless $self, $class
 }
@@ -36,7 +37,7 @@ sub getstr {
        sprintf $strings[int rand $#strings], @_
 }
 
-sub infobot_add {
+sub infobot_add { ## no critic (ProhibitManyArgs)
        my ($self, $irc, $key, $value, $to, $nick) = @_;
        if (exists $self->{db}->{$key}) {
                $irc->yield(privmsg => $to => "I already had it that way, $nick") if $value eq $self->{db}->{$key};
@@ -48,10 +49,10 @@ sub infobot_add {
        }
 }
 
-sub infobot_query {
+sub infobot_query { ## no critic (ProhibitManyArgs)
        my ($self, $irc, $key, $to, $nick, $addressed) = @_;
        if (exists $self->{db}->{$key}) {
-               my @answers = split /\s+\|\s+/, $self->{db}->{$key};
+               my @answers = split /\s+[|]\s+/, $self->{db}->{$key};
                local $_ = $answers[int rand $#answers];
 
                if (/^<action> (.+)$/i) {
@@ -77,29 +78,29 @@ sub infobot_forget {
        }
 }
 
-sub runcmd{
+sub runcmd{  ## no critic (ProhibitManyArgs)
        my ($self, $irc, $to, $nick, $message, $addressed) = @_;
 
        local $_= $message;
 
-       if (/^(.+)\s+is\s+(.*[^?])$/) {
+       if (/^(.+)\s+is\s+(.*[^?])$/x) {
                infobot_add $self, $irc, $1, $2, $to, $nick if $addressed
-       } elsif (/^(.+)\?$/) {
+       } elsif (/^(.+)[?]$/) {
                infobot_query $self, $irc, $1, $to, $nick, $addressed
        } elsif ($addressed && /^!?forget\s+(.*)$/ || /^!forget\s+(.*)$/) {
                infobot_forget $self, $irc, $1, $to, $nick
        }
 }
 
-sub PCI_register {
+sub PCI_register { ## no critic (Capitalization)
        my ($self, $irc) = @_;
        $irc->plugin_register($self, SERVER => qw/public msg/);
        1
 }
 
-sub PCI_unregister{ 1 }
+sub PCI_unregister{ 1 } ## no critic (Capitalization)
 
-sub S_public {
+sub S_public { ## no critic (Capitalization)
        my ($self, $irc, $rfullname, $rchannels, $rmessage) = @_;
        my $nick = parse_user $$rfullname;
 
@@ -119,7 +120,7 @@ sub S_public {
        PCI_EAT_NONE
 }
 
-sub S_msg{
+sub S_msg{ ## no critic (Capitalization)
        my ($self, $irc, $rfullname, $rtargets, $rmessage) = @_;
        my $nick = parse_user $$rfullname;
 
diff --git a/t/perlcritic.t b/t/perlcritic.t
new file mode 100644 (file)
index 0000000..79e93dc
--- /dev/null
@@ -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 (file)
index 0000000..40b151e
--- /dev/null
@@ -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
This page took 0.015556 seconds and 4 git commands to generate.