From 8450d84869b5fc63bdee710bab77a6514d45a9cf Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Sat, 14 Nov 2015 18:48:42 +0000 Subject: [PATCH] Add perlcritic test and make code comply --- MANIFEST | 2 ++ lib/POE/Component/IRC/Plugin/Infobot.pm | 27 ++++++++-------- t/perlcritic.t | 10 ++++++ t/perlcriticrc | 41 +++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 13 deletions(-) create mode 100644 t/perlcritic.t create mode 100644 t/perlcriticrc diff --git a/MANIFEST b/MANIFEST index 7000280..ea690b5 100644 --- 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 diff --git a/lib/POE/Component/IRC/Plugin/Infobot.pm b/lib/POE/Component/IRC/Plugin/Infobot.pm index c2969b6..69de38c 100644 --- a/lib/POE/Component/IRC/Plugin/Infobot.pm +++ b/lib/POE/Component/IRC/Plugin/Infobot.pm @@ -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 (/^ (.+)$/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 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