Skip to content

Commit dfb5ad4

Browse files
author
Greg Sabino Mullane
committed
Perl::Critic inspired changes
1 parent 61ada62 commit dfb5ad4

File tree

7 files changed

+45
-41
lines changed

7 files changed

+45
-41
lines changed

check_postgres.pl

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ package check_postgres;
904904
$name = "dbname$1";
905905
}
906906
elsif ($name =~ /^u(\d+)$/o) {
907-
$name = 'dbuser$1';
907+
$name = "dbuser$1";
908908
}
909909

910910
## These options are multiples ('@s')
@@ -1634,7 +1634,7 @@ sub finishup {
16341634
or ($DEBUGOUTPUT =~ /u/io and $type eq 'u');
16351635
}
16361636
for (sort keys %$info) {
1637-
printf "%s %s%s ",
1637+
printf '%s %s%s ',
16381638
$_,
16391639
$showdebug ? "[DEBUG: $DEBUG_INFO] " : '',
16401640
join $SEP => map { $_->[0] } @{$info->{$_}};
@@ -2414,31 +2414,31 @@ sub run_command {
24142414

24152415
## Transform psql output into an arrayref of hashes
24162416
my @stuff;
2417-
my $num = 0;
2417+
my $lnum = 0;
24182418
my $lastval;
24192419
for my $line (split /\n/ => $db->{slurp}) {
24202420

24212421
if (index($line,'-')==0) {
2422-
$num++;
2422+
$lnum++;
24232423
next;
24242424
}
24252425
if ($line =~ /^([\?\w]+)\s+\| (.*)/) {
2426-
$stuff[$num]{$1} = $2;
2426+
$stuff[$lnum]{$1} = $2;
24272427
$lastval = $1;
24282428
}
24292429
elsif ($line =~ /^QUERY PLAN\s+\| (.*)/) {
2430-
$stuff[$num]{queryplan} = $1;
2430+
$stuff[$lnum]{queryplan} = $1;
24312431
$lastval = 'queryplan';
24322432
}
24332433
elsif ($line =~ /^\s+: (.*)/) {
2434-
$stuff[$num]{$lastval} .= "\n$1";
2434+
$stuff[$lnum]{$lastval} .= "\n$1";
24352435
}
24362436
elsif ($line =~ /^\s+\| (.+)/) {
2437-
$stuff[$num]{$lastval} .= "\n$1";
2437+
$stuff[$lnum]{$lastval} .= "\n$1";
24382438
}
24392439
## No content: can happen in the source of functions, for example
24402440
elsif ($line =~ /^\s+\|\s+$/) {
2441-
$stuff[$num]{$lastval} .= "\n";
2441+
$stuff[$lnum]{$lastval} .= "\n";
24422442
}
24432443
else {
24442444
my $msg = msg('no-parse-psql');
@@ -2457,8 +2457,8 @@ sub run_command {
24572457
if (! $opt{stop_looping}) {
24582458
## Just in case...
24592459
$opt{stop_looping} = 1;
2460-
my $info = run_command('SELECT version() AS version');
2461-
(my $v = $info->{db}[0]{slurp}[0]{version}) =~ s/(\w+ \S+).+/$1/;
2460+
my $linfo = run_command('SELECT version() AS version');
2461+
(my $v = $linfo->{db}[0]{slurp}[0]{version}) =~ s/(\w+ \S+).+/$1/;
24622462
warn "Postgres version: $v\n";
24632463
}
24642464
exit 1;
@@ -4710,7 +4710,7 @@ sub check_hot_standby_delay {
47104710
if (1 == $slave) {
47114711
($slave, $master) = (2, 1);
47124712
for my $k (qw(host port dbname dbuser dbpass)) {
4713-
($opt{$k}, $opt{$k . 2}) = ($opt{$k . 2}, $opt{$k});
4713+
($opt{$k}, $opt{$k . 2}) = ($opt{$k . 2}, $opt{$k}); ## no critic (ProhibitMismatchedOperators)
47144714
}
47154715
}
47164716

@@ -4903,7 +4903,7 @@ sub check_last_vacuum_analyze {
49034903
add_unknown (
49044904
$found ? $type eq 'vacuum' ? msg('vac-nomatch-v')
49054905
: msg('vac-nomatch-a')
4906-
: msg('no-match-table')
4906+
: msg('no-match-table') ## no critic (RequireTrailingCommaAtNewline)
49074907
);
49084908
}
49094909
elsif ($maxtime < 0) {
@@ -5536,7 +5536,7 @@ sub check_pgbouncer_backends {
55365536
}
55375537

55385538
## Grab information from the config
5539-
$SQL = qq{SHOW CONFIG};
5539+
$SQL = 'SHOW CONFIG';
55405540

55415541
my $info = run_command($SQL, { regex => qr{\d+}, emptyok => 1 } );
55425542

@@ -5552,7 +5552,7 @@ sub check_pgbouncer_backends {
55525552
}
55535553

55545554
## Grab information from pools
5555-
$SQL = qq{SHOW POOLS};
5555+
$SQL = 'SHOW POOLS';
55565556

55575557
$info = run_command($SQL, { regex => qr{\d+}, emptyok => 1 } );
55585558

@@ -5897,7 +5897,7 @@ sub check_relation_size {
58975897

58985898
my $nicename = $kind eq 'r' ? "$schema.$name" : $name;
58995899

5900-
$db->{perf} .= sprintf "%s%s=%sB;%s;%s",
5900+
$db->{perf} .= sprintf '%s%s=%sB;%s;%s',
59015901
$VERBOSE==1 ? "\n" : ' ',
59025902
perfname($nicename), $size, $warning, $critical;
59035903
($max=$size, $pmax=$psize, $kmax=$kind, $nmax=$name, $smax=$schema) if $size > $max;
@@ -6479,13 +6479,13 @@ sub check_same_schema {
64796479
}
64806480

64816481
if (exists $tdiff->{list}{$col}{exists}) {
6482-
my $e = $tdiff->{list}{$col}{exists};
6483-
for my $name (sort keys %$e) {
6482+
my $ex = $tdiff->{list}{$col}{exists};
6483+
for my $name (sort keys %$ex) {
64846484
push @msg => sprintf qq{ "%s":\n %s\n},
64856485
$col,
64866486
msg('ss-notset', $name);
6487-
my $isthere = join ', ' => sort { $a<=>$b } keys %{ $e->{$name}{isthere} };
6488-
my $nothere = join ', ' => sort { $a<=>$b } keys %{ $e->{$name}{nothere} };
6487+
my $isthere = join ', ' => sort { $a<=>$b } keys %{ $ex->{$name}{isthere} };
6488+
my $nothere = join ', ' => sort { $a<=>$b } keys %{ $ex->{$name}{nothere} };
64896489
push @msg => sprintf " %-*s %s\n %-*s %s\n",
64906490
$maxsize, $msg_exists,
64916491
$isthere,
@@ -6661,7 +6661,7 @@ sub read_audit_file {
66616661
close $fh or warn qq{Could not close "$filename": $!\n};
66626662

66636663
my $POSTGRES1;
6664-
eval $data;
6664+
eval $data; ## no critic (ProhibitStringyEval)
66656665
if ($@) {
66666666
die qq{Failed to parse file "$filename": $@\n};
66676667
}
@@ -7000,6 +7000,7 @@ sub check_sequence {
70007000
(my $c = $critical) =~ s/\D//;
70017001

70027002
## Gather up all sequence names
7003+
## no critic
70037004
my $SQL = q{
70047005
SELECT DISTINCT ON (nspname, seqname) nspname, seqname,
70057006
quote_ident(nspname) || '.' || quote_ident(seqname) AS safename, typname
@@ -7040,6 +7041,7 @@ sub check_sequence {
70407041
) AS seqs
70417042
ORDER BY nspname, seqname, typname
70427043
};
7044+
## use critic
70437045

70447046
my $info = run_command($SQL, {regex => qr{\w}, emptyok => 1} );
70457047

@@ -7222,7 +7224,7 @@ sub check_slony_status {
72227224
}
72237225

72247226
my $SLSQL =
7225-
qq{SELECT
7227+
q{SELECT
72267228
ROUND(EXTRACT(epoch FROM st_lag_time)) AS lagtime,
72277229
st_origin,
72287230
st_received,
@@ -7363,19 +7365,19 @@ sub check_txn_idle {
73637365

73647366
## We don't GROUP BY because we want details on every connection
73657367
## Someday we may even break things down by database
7366-
if ($type ne "qtime") {
7368+
if ($type ne 'qtime') {
73677369
$SQL = q{SELECT datname, datid, procpid, usename, client_addr, xact_start, current_query, }.
73687370
q{CASE WHEN client_port < 0 THEN 0 ELSE client_port END AS client_port, }.
73697371
qq{COALESCE(ROUND(EXTRACT(epoch FROM now()-$start)),0) AS seconds }.
73707372
qq{FROM pg_stat_activity WHERE $clause$USERWHERECLAUSE }.
7371-
qq{ORDER BY xact_start, query_start, procpid DESC};
7373+
q{ORDER BY xact_start, query_start, procpid DESC};
73727374
}
73737375
else {
73747376
$SQL = q{SELECT datname, datid, procpid, usename, client_addr, current_query, }.
73757377
q{CASE WHEN client_port < 0 THEN 0 ELSE client_port END AS client_port, }.
73767378
qq{COALESCE(ROUND(EXTRACT(epoch FROM now()-$start)),0) AS seconds }.
73777379
qq{FROM pg_stat_activity WHERE $clause$USERWHERECLAUSE }.
7378-
qq{ORDER BY query_start, procpid DESC};
7380+
q{ORDER BY query_start, procpid DESC};
73797381
}
73807382

73817383
my $info = run_command($SQL, { emptyok => 1 } );
@@ -7391,7 +7393,7 @@ sub check_txn_idle {
73917393
my $count = 0;
73927394

73937395
## Info about the top offender
7394-
my $whodunit = "";
7396+
my $whodunit = '';
73957397
if ($MRTG) {
73967398
if (defined $db->{dbname}) {
73977399
$whodunit = "DB: $db->{dbname}";
@@ -7422,7 +7424,7 @@ sub check_txn_idle {
74227424
}
74237425

74247426
## Detect other cases where pg_stat_activity is not fully populated
7425-
if ($type ne "qtime" and length $r->{xact_start} and $r->{xact_start} !~ /\d/o) {
7427+
if ($type ne 'qtime' and length $r->{xact_start} and $r->{xact_start} !~ /\d/o) {
74267428
add_unknown msg('psa-noexact');
74277429
return;
74287430
}

perlcriticrc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ verbose = 8
44
profile-strictness = quiet
55

66
[Documentation::PodSpelling]
7-
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
8-
9-
10-
7+
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
118

129
[-Bangs::ProhibitFlagComments]
1310
[-Bangs::ProhibitNumberedNames]
1411
[-Bangs::ProhibitVagueNames]
1512

13+
[-BuiltinFunctions::ProhibitBooleanGrep]
1614
[-BuiltinFunctions::ProhibitComplexMappings]
1715
[-BuiltinFunctions::ProhibitReverseSortBlock]
1816

@@ -22,6 +20,8 @@ stop_words = Mullane Nagios Slony Slony's nols salesrep psql dbname postgres USE
2220
[-CodeLayout::RequireTidyCode]
2321
[-CodeLayout::RequireUseUTF8]
2422

23+
[-Compatibility::PodMinimumVersion]
24+
2525
[-ControlStructures::ProhibitCascadingIfElse]
2626
[-ControlStructures::ProhibitDeepNests]
2727
[-ControlStructures::ProhibitMutatingListFunctions]
@@ -79,18 +79,22 @@ stop_words = Mullane Nagios Slony Slony's nols salesrep psql dbname postgres USE
7979
[-Tics::ProhibitLongLines]
8080

8181
[-ValuesAndExpressions::ProhibitAccessOfPrivateData]
82+
[-ValuesAndExpressions::ProhibitCommaSeparatedStatements]
8283
[-ValuesAndExpressions::ProhibitEmptyQuotes]
8384
[-ValuesAndExpressions::ProhibitImplicitNewlines]
8485
[-ValuesAndExpressions::ProhibitMagicNumbers]
8586
[-ValuesAndExpressions::ProhibitMixedBooleanOperators]
8687
[-ValuesAndExpressions::ProhibitNoisyQuotes]
8788
[-ValuesAndExpressions::ProhibitVersionStrings]
8889
[-ValuesAndExpressions::RequireNumberSeparators]
90+
[-ValuesAndExpressions::RequireNumericVersion]
8991
[-ValuesAndExpressions::RestrictLongStrings]
9092

93+
[-Variables::ProhibitLocalVars]
9194
[-Variables::ProhibitPackageVars]
9295
[-Variables::ProhibitPunctuationVars]
9396
[-Variables::ProhibitUselessInitialization]
9497
[-Variables::RequireInitializationForLocalVars]
9598
[-Variables::RequireLexicalLoopIterators]
9699
[-Variables::RequireLocalizedPunctuationVars]
100+

t/00_release.t

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,9 @@ for my $mfile (@mfiles) {
111111
file_is_clean($mfile);
112112
}
113113

114-
exit;
115-
116114
sub file_is_clean {
117115

118-
my $file = shift or die;
116+
my $file = shift or die; ## no critic (ProhibitReusedNames)
119117

120118
if (!open $fh, '<', $file) {
121119
fail qq{Could not open "$file": $!\n};

t/02_custom_query.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ like ($cp->run(qq{--query="$good_query" --valtype=string --warning=abc}),
4040
qr{$label OK}, $t);
4141

4242
$t = qq{$S handles 'string' type for match};
43-
like ($cp->run(qq{--query="SELECT 'abc' AS result" --valtype=string --warning=abc}),
43+
like ($cp->run(q{--query="SELECT 'abc' AS result" --valtype=string --warning=abc}),
4444
qr{$label WARNING}, $t);
4545

4646
$t = qq{$S handles 'time' type};

t/02_same_schema.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ Schema "schema_a":
224224

225225
$t = qq{$S reports when schemas have different acls};
226226
$dbh1->do(q{ALTER SCHEMA schema_a OWNER TO check_postgres_testing});
227-
$dbh1->do(qq{GRANT USAGE ON SCHEMA schema_a TO check_postgres_testing});
227+
$dbh1->do(q{GRANT USAGE ON SCHEMA schema_a TO check_postgres_testing});
228228
like ($cp1->run($connect2),
229229
qr{^$label CRITICAL.*Items not matched: 1 .*
230230
Schema "schema_a":
@@ -287,7 +287,7 @@ Table "public.berri":
287287
$dbh1->do(q{ALTER TABLE berri SET WITHOUT OIDS});
288288

289289
$t = qq{$S reports simple table acl differences};
290-
$dbh1->do(qq{GRANT SELECT ON TABLE berri TO alternate_owner});
290+
$dbh1->do(q{GRANT SELECT ON TABLE berri TO alternate_owner});
291291
## No anchoring here as check_postgres_testing implicit perms are set too!
292292
like ($cp1->run($connect2),
293293
qr{^$label CRITICAL.*Items not matched: 1 .*
@@ -299,7 +299,7 @@ Table "public.berri":
299299
$t);
300300

301301
$t = qq{$S reports complex table acl differences};
302-
$dbh2->do(qq{GRANT UPDATE,DELETE ON TABLE berri TO alternate_owner});
302+
$dbh2->do(q{GRANT UPDATE,DELETE ON TABLE berri TO alternate_owner});
303303
like ($cp1->run($connect2),
304304
qr{^$label CRITICAL.*Items not matched: 1 .*
305305
Table "public.berri":

t/02_settings_checksum.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ $t = qq{$S accepts matching checksum};
5353
like ($cp->run("-w $true_checksum"), qr/OK.*\Qchecksum: $true_checksum\E/, $t);
5454

5555
$t=qq{$S returns the expected output for MRTG(failure)};
56-
like ($cp->run(qq{--mrtg 123 --output=MRTG}),
56+
like ($cp->run(q{--mrtg 123 --output=MRTG}),
5757
qr{^0\n0\n\n\d+}, $t);
5858

5959
$t=qq{$S returns the expected output for MRTG(success)};

t/CP_Testing.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ sub test_database_handle {
229229
if ($res !~ /$newuser/) {
230230
$COM = qq{psql -d template1 -q -h "$host" -c "CREATE USER $newuser"};
231231
system $COM;
232-
$SQL = q{UPDATE pg_shadow SET usesuper='t' WHERE usename = '$newuser'};
232+
$SQL = qq{UPDATE pg_shadow SET usesuper='t' WHERE usename = '$newuser'};
233233
$COM = qq{psql -d postgres -q -h "$host" -c "$SQL"};
234234
system $COM;
235235
}
@@ -240,7 +240,7 @@ sub test_database_handle {
240240
if ($res !~ /$newuser/) {
241241
$COM = qq{psql -d template1 -q -h "$host" -c "CREATE USER $newuser"};
242242
system $COM;
243-
$SQL = q{UPDATE pg_shadow SET usesuper='t' WHERE usename = '$newuser'};
243+
$SQL = qq{UPDATE pg_shadow SET usesuper='t' WHERE usename = '$newuser'};
244244
$COM = qq{psql -d postgres -q -h "$host" -c "$SQL"};
245245
system $COM;
246246
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy