diff options
author | Greg Sabino Mullane | 2012-01-18 00:43:24 +0000 |
---|---|---|
committer | Greg Sabino Mullane | 2012-01-18 00:43:24 +0000 |
commit | dfb5ad446f24a7c0f26570cfd3a6f0518be90bd3 (patch) | |
tree | a53dcb9d86028b55969073eee223e58c527f7059 | |
parent | 61ada623c4199ffab2f07b77c4cb4fc1116e9952 (diff) |
Perl::Critic inspired changes
-rwxr-xr-x | check_postgres.pl | 56 | ||||
-rw-r--r-- | perlcriticrc | 12 | ||||
-rw-r--r-- | t/00_release.t | 4 | ||||
-rw-r--r-- | t/02_custom_query.t | 2 | ||||
-rw-r--r-- | t/02_same_schema.t | 6 | ||||
-rw-r--r-- | t/02_settings_checksum.t | 2 | ||||
-rw-r--r-- | t/CP_Testing.pm | 4 |
7 files changed, 45 insertions, 41 deletions
diff --git a/check_postgres.pl b/check_postgres.pl index d6af95ccd..c546c99e7 100755 --- a/check_postgres.pl +++ b/check_postgres.pl @@ -904,7 +904,7 @@ if (defined $rcfile) { $name = "dbname$1"; } elsif ($name =~ /^u(\d+)$/o) { - $name = 'dbuser$1'; + $name = "dbuser$1"; } ## These options are multiples ('@s') @@ -1634,7 +1634,7 @@ sub finishup { or ($DEBUGOUTPUT =~ /u/io and $type eq 'u'); } for (sort keys %$info) { - printf "%s %s%s ", + printf '%s %s%s ', $_, $showdebug ? "[DEBUG: $DEBUG_INFO] " : '', join $SEP => map { $_->[0] } @{$info->{$_}}; @@ -2414,31 +2414,31 @@ sub run_command { ## Transform psql output into an arrayref of hashes my @stuff; - my $num = 0; + my $lnum = 0; my $lastval; for my $line (split /\n/ => $db->{slurp}) { if (index($line,'-')==0) { - $num++; + $lnum++; next; } if ($line =~ /^([\?\w]+)\s+\| (.*)/) { - $stuff[$num]{$1} = $2; + $stuff[$lnum]{$1} = $2; $lastval = $1; } elsif ($line =~ /^QUERY PLAN\s+\| (.*)/) { - $stuff[$num]{queryplan} = $1; + $stuff[$lnum]{queryplan} = $1; $lastval = 'queryplan'; } elsif ($line =~ /^\s+: (.*)/) { - $stuff[$num]{$lastval} .= "\n$1"; + $stuff[$lnum]{$lastval} .= "\n$1"; } elsif ($line =~ /^\s+\| (.+)/) { - $stuff[$num]{$lastval} .= "\n$1"; + $stuff[$lnum]{$lastval} .= "\n$1"; } ## No content: can happen in the source of functions, for example elsif ($line =~ /^\s+\|\s+$/) { - $stuff[$num]{$lastval} .= "\n"; + $stuff[$lnum]{$lastval} .= "\n"; } else { my $msg = msg('no-parse-psql'); @@ -2457,8 +2457,8 @@ sub run_command { if (! $opt{stop_looping}) { ## Just in case... $opt{stop_looping} = 1; - my $info = run_command('SELECT version() AS version'); - (my $v = $info->{db}[0]{slurp}[0]{version}) =~ s/(\w+ \S+).+/$1/; + my $linfo = run_command('SELECT version() AS version'); + (my $v = $linfo->{db}[0]{slurp}[0]{version}) =~ s/(\w+ \S+).+/$1/; warn "Postgres version: $v\n"; } exit 1; @@ -4710,7 +4710,7 @@ sub check_hot_standby_delay { if (1 == $slave) { ($slave, $master) = (2, 1); for my $k (qw(host port dbname dbuser dbpass)) { - ($opt{$k}, $opt{$k . 2}) = ($opt{$k . 2}, $opt{$k}); + ($opt{$k}, $opt{$k . 2}) = ($opt{$k . 2}, $opt{$k}); ## no critic (ProhibitMismatchedOperators) } } @@ -4903,7 +4903,7 @@ FROM (SELECT nspname, relname, $criteria AS v add_unknown ( $found ? $type eq 'vacuum' ? msg('vac-nomatch-v') : msg('vac-nomatch-a') - : msg('no-match-table') + : msg('no-match-table') ## no critic (RequireTrailingCommaAtNewline) ); } elsif ($maxtime < 0) { @@ -5536,7 +5536,7 @@ sub check_pgbouncer_backends { } ## Grab information from the config - $SQL = qq{SHOW CONFIG}; + $SQL = 'SHOW CONFIG'; my $info = run_command($SQL, { regex => qr{\d+}, emptyok => 1 } ); @@ -5552,7 +5552,7 @@ sub check_pgbouncer_backends { } ## Grab information from pools - $SQL = qq{SHOW POOLS}; + $SQL = 'SHOW POOLS'; $info = run_command($SQL, { regex => qr{\d+}, emptyok => 1 } ); @@ -5897,7 +5897,7 @@ FROM pg_class c, pg_namespace n WHERE (relkind = %s) AND n.oid = c.relnamespace my $nicename = $kind eq 'r' ? "$schema.$name" : $name; - $db->{perf} .= sprintf "%s%s=%sB;%s;%s", + $db->{perf} .= sprintf '%s%s=%sB;%s;%s', $VERBOSE==1 ? "\n" : ' ', perfname($nicename), $size, $warning, $critical; ($max=$size, $pmax=$psize, $kmax=$kind, $nmax=$name, $smax=$schema) if $size > $max; @@ -6479,13 +6479,13 @@ sub check_same_schema { } if (exists $tdiff->{list}{$col}{exists}) { - my $e = $tdiff->{list}{$col}{exists}; - for my $name (sort keys %$e) { + my $ex = $tdiff->{list}{$col}{exists}; + for my $name (sort keys %$ex) { push @msg => sprintf qq{ "%s":\n %s\n}, $col, msg('ss-notset', $name); - my $isthere = join ', ' => sort { $a<=>$b } keys %{ $e->{$name}{isthere} }; - my $nothere = join ', ' => sort { $a<=>$b } keys %{ $e->{$name}{nothere} }; + my $isthere = join ', ' => sort { $a<=>$b } keys %{ $ex->{$name}{isthere} }; + my $nothere = join ', ' => sort { $a<=>$b } keys %{ $ex->{$name}{nothere} }; push @msg => sprintf " %-*s %s\n %-*s %s\n", $maxsize, $msg_exists, $isthere, @@ -6661,7 +6661,7 @@ sub read_audit_file { close $fh or warn qq{Could not close "$filename": $!\n}; my $POSTGRES1; - eval $data; + eval $data; ## no critic (ProhibitStringyEval) if ($@) { die qq{Failed to parse file "$filename": $@\n}; } @@ -7000,6 +7000,7 @@ sub check_sequence { (my $c = $critical) =~ s/\D//; ## Gather up all sequence names + ## no critic my $SQL = q{ SELECT DISTINCT ON (nspname, seqname) nspname, seqname, quote_ident(nspname) || '.' || quote_ident(seqname) AS safename, typname @@ -7040,6 +7041,7 @@ FROM ( ) AS seqs ORDER BY nspname, seqname, typname }; + ## use critic my $info = run_command($SQL, {regex => qr{\w}, emptyok => 1} ); @@ -7222,7 +7224,7 @@ sub check_slony_status { } my $SLSQL = -qq{SELECT +q{SELECT ROUND(EXTRACT(epoch FROM st_lag_time)) AS lagtime, st_origin, st_received, @@ -7363,19 +7365,19 @@ sub check_txn_idle { ## We don't GROUP BY because we want details on every connection ## Someday we may even break things down by database - if ($type ne "qtime") { + if ($type ne 'qtime') { $SQL = q{SELECT datname, datid, procpid, usename, client_addr, xact_start, current_query, }. q{CASE WHEN client_port < 0 THEN 0 ELSE client_port END AS client_port, }. qq{COALESCE(ROUND(EXTRACT(epoch FROM now()-$start)),0) AS seconds }. qq{FROM pg_stat_activity WHERE $clause$USERWHERECLAUSE }. - qq{ORDER BY xact_start, query_start, procpid DESC}; + q{ORDER BY xact_start, query_start, procpid DESC}; } else { $SQL = q{SELECT datname, datid, procpid, usename, client_addr, current_query, }. q{CASE WHEN client_port < 0 THEN 0 ELSE client_port END AS client_port, }. qq{COALESCE(ROUND(EXTRACT(epoch FROM now()-$start)),0) AS seconds }. qq{FROM pg_stat_activity WHERE $clause$USERWHERECLAUSE }. - qq{ORDER BY query_start, procpid DESC}; + q{ORDER BY query_start, procpid DESC}; } my $info = run_command($SQL, { emptyok => 1 } ); @@ -7391,7 +7393,7 @@ sub check_txn_idle { my $count = 0; ## Info about the top offender - my $whodunit = ""; + my $whodunit = ''; if ($MRTG) { if (defined $db->{dbname}) { $whodunit = "DB: $db->{dbname}"; @@ -7422,7 +7424,7 @@ sub check_txn_idle { } ## Detect other cases where pg_stat_activity is not fully populated - if ($type ne "qtime" and length $r->{xact_start} and $r->{xact_start} !~ /\d/o) { + if ($type ne 'qtime' and length $r->{xact_start} and $r->{xact_start} !~ /\d/o) { add_unknown msg('psa-noexact'); return; } diff --git a/perlcriticrc b/perlcriticrc index b75796586..980df99a4 100644 --- a/perlcriticrc +++ b/perlcriticrc @@ -4,15 +4,13 @@ verbose = 8 profile-strictness = quiet [Documentation::PodSpelling] -stop_words = Mullane Nagios Slony Slony's nols salesrep psql dbname postgres USERNAME usernames dbuser pgpass nagios stderr showperf symlinked timesync criticals quirm lancre exabytes sami includeuser excludeuser flagg tardis WAL tablespaces tablespace perflimit burrick mallory grimm oskar ExclusiveLock garrett artemus queryname speedtest checksum checksums morpork klatch pluto faceoff slon greg watson franklin wilkins scott Sabino Seklecki dbpass autovacuum Astill refactoring NAGIOS localhost cronjob symlink symlinks backends snazzo logfile syslog parens plugin Cwd Ioannis Tambouras schemas SQL MRTG mrtg uptime datallowconn dbhost dbport ok contrib pageslots robert dylan emma fsm minvalue nextval dbstats del ret upd Bucardo noidle bucardo petabytes zettabytes tuples noobjectnames noposition nofuncbody slony noperms nolanguage battlestar pgbouncer pgBouncer - - - +stop_words = Mullane Nagios Slony Slony's nols salesrep psql dbname postgres USERNAME usernames dbuser pgpass nagios stderr showperf symlinked timesync criticals quirm lancre exabytes sami includeuser excludeuser flagg tardis WAL tablespaces tablespace perflimit burrick mallory grimm oskar ExclusiveLock garrett artemus queryname speedtest checksum checksums morpork klatch pluto faceoff slon greg watson franklin wilkins scott Sabino Seklecki dbpass autovacuum Astill refactoring NAGIOS localhost cronjob symlink symlinks backends snazzo logfile syslog parens plugin Cwd Ioannis Tambouras schemas SQL MRTG mrtg uptime datallowconn dbhost dbport ok contrib pageslots robert dylan emma fsm minvalue nextval dbstats del ret upd Bucardo noidle bucardo petabytes zettabytes tuples noobjectnames noposition nofuncbody slony noperms nolanguage battlestar pgbouncer pgBouncer datadir wget PostgreSQL commitratio idxscan idxtupread idxtupfetch idxblksread idxblkshit seqscan seqtupread hitratio xlog boxinfo pgbouncer's login maxwait noname noschema noperm filenames GSM [-Bangs::ProhibitFlagComments] [-Bangs::ProhibitNumberedNames] [-Bangs::ProhibitVagueNames] +[-BuiltinFunctions::ProhibitBooleanGrep] [-BuiltinFunctions::ProhibitComplexMappings] [-BuiltinFunctions::ProhibitReverseSortBlock] @@ -22,6 +20,8 @@ stop_words = Mullane Nagios Slony Slony's nols salesrep psql dbname postgres USE [-CodeLayout::RequireTidyCode] [-CodeLayout::RequireUseUTF8] +[-Compatibility::PodMinimumVersion] + [-ControlStructures::ProhibitCascadingIfElse] [-ControlStructures::ProhibitDeepNests] [-ControlStructures::ProhibitMutatingListFunctions] @@ -79,6 +79,7 @@ stop_words = Mullane Nagios Slony Slony's nols salesrep psql dbname postgres USE [-Tics::ProhibitLongLines] [-ValuesAndExpressions::ProhibitAccessOfPrivateData] +[-ValuesAndExpressions::ProhibitCommaSeparatedStatements] [-ValuesAndExpressions::ProhibitEmptyQuotes] [-ValuesAndExpressions::ProhibitImplicitNewlines] [-ValuesAndExpressions::ProhibitMagicNumbers] @@ -86,11 +87,14 @@ stop_words = Mullane Nagios Slony Slony's nols salesrep psql dbname postgres USE [-ValuesAndExpressions::ProhibitNoisyQuotes] [-ValuesAndExpressions::ProhibitVersionStrings] [-ValuesAndExpressions::RequireNumberSeparators] +[-ValuesAndExpressions::RequireNumericVersion] [-ValuesAndExpressions::RestrictLongStrings] +[-Variables::ProhibitLocalVars] [-Variables::ProhibitPackageVars] [-Variables::ProhibitPunctuationVars] [-Variables::ProhibitUselessInitialization] [-Variables::RequireInitializationForLocalVars] [-Variables::RequireLexicalLoopIterators] [-Variables::RequireLocalizedPunctuationVars] + diff --git a/t/00_release.t b/t/00_release.t index 82f316100..36604b700 100644 --- a/t/00_release.t +++ b/t/00_release.t @@ -111,11 +111,9 @@ for my $mfile (@mfiles) { file_is_clean($mfile); } -exit; - sub file_is_clean { - my $file = shift or die; + my $file = shift or die; ## no critic (ProhibitReusedNames) if (!open $fh, '<', $file) { fail qq{Could not open "$file": $!\n}; diff --git a/t/02_custom_query.t b/t/02_custom_query.t index 276f62dad..a6b2d4fb6 100644 --- a/t/02_custom_query.t +++ b/t/02_custom_query.t @@ -40,7 +40,7 @@ like ($cp->run(qq{--query="$good_query" --valtype=string --warning=abc}), qr{$label OK}, $t); $t = qq{$S handles 'string' type for match}; -like ($cp->run(qq{--query="SELECT 'abc' AS result" --valtype=string --warning=abc}), +like ($cp->run(q{--query="SELECT 'abc' AS result" --valtype=string --warning=abc}), qr{$label WARNING}, $t); $t = qq{$S handles 'time' type}; diff --git a/t/02_same_schema.t b/t/02_same_schema.t index 3a205c79e..ec70f5f6d 100644 --- a/t/02_same_schema.t +++ b/t/02_same_schema.t @@ -224,7 +224,7 @@ Schema "schema_a": $t = qq{$S reports when schemas have different acls}; $dbh1->do(q{ALTER SCHEMA schema_a OWNER TO check_postgres_testing}); -$dbh1->do(qq{GRANT USAGE ON SCHEMA schema_a TO check_postgres_testing}); +$dbh1->do(q{GRANT USAGE ON SCHEMA schema_a TO check_postgres_testing}); like ($cp1->run($connect2), qr{^$label CRITICAL.*Items not matched: 1 .* Schema "schema_a": @@ -287,7 +287,7 @@ Table "public.berri": $dbh1->do(q{ALTER TABLE berri SET WITHOUT OIDS}); $t = qq{$S reports simple table acl differences}; -$dbh1->do(qq{GRANT SELECT ON TABLE berri TO alternate_owner}); +$dbh1->do(q{GRANT SELECT ON TABLE berri TO alternate_owner}); ## No anchoring here as check_postgres_testing implicit perms are set too! like ($cp1->run($connect2), qr{^$label CRITICAL.*Items not matched: 1 .* @@ -299,7 +299,7 @@ Table "public.berri": $t); $t = qq{$S reports complex table acl differences}; -$dbh2->do(qq{GRANT UPDATE,DELETE ON TABLE berri TO alternate_owner}); +$dbh2->do(q{GRANT UPDATE,DELETE ON TABLE berri TO alternate_owner}); like ($cp1->run($connect2), qr{^$label CRITICAL.*Items not matched: 1 .* Table "public.berri": diff --git a/t/02_settings_checksum.t b/t/02_settings_checksum.t index a5649754b..a4df6b305 100644 --- a/t/02_settings_checksum.t +++ b/t/02_settings_checksum.t @@ -53,7 +53,7 @@ $t = qq{$S accepts matching checksum}; like ($cp->run("-w $true_checksum"), qr/OK.*\Qchecksum: $true_checksum\E/, $t); $t=qq{$S returns the expected output for MRTG(failure)}; -like ($cp->run(qq{--mrtg 123 --output=MRTG}), +like ($cp->run(q{--mrtg 123 --output=MRTG}), qr{^0\n0\n\n\d+}, $t); $t=qq{$S returns the expected output for MRTG(success)}; diff --git a/t/CP_Testing.pm b/t/CP_Testing.pm index 05d6a1bff..6279322f0 100644 --- a/t/CP_Testing.pm +++ b/t/CP_Testing.pm @@ -229,7 +229,7 @@ sub test_database_handle { if ($res !~ /$newuser/) { $COM = qq{psql -d template1 -q -h "$host" -c "CREATE USER $newuser"}; system $COM; - $SQL = q{UPDATE pg_shadow SET usesuper='t' WHERE usename = '$newuser'}; + $SQL = qq{UPDATE pg_shadow SET usesuper='t' WHERE usename = '$newuser'}; $COM = qq{psql -d postgres -q -h "$host" -c "$SQL"}; system $COM; } @@ -240,7 +240,7 @@ sub test_database_handle { if ($res !~ /$newuser/) { $COM = qq{psql -d template1 -q -h "$host" -c "CREATE USER $newuser"}; system $COM; - $SQL = q{UPDATE pg_shadow SET usesuper='t' WHERE usename = '$newuser'}; + $SQL = qq{UPDATE pg_shadow SET usesuper='t' WHERE usename = '$newuser'}; $COM = qq{psql -d postgres -q -h "$host" -c "$SQL"}; system $COM; } |