Skip to content

Commit

Permalink
Addresses #170 Clear up Perl::Critic gripes
Browse files Browse the repository at this point in the history
  • Loading branch information
moseshll committed Nov 5, 2024
1 parent ab2e6d6 commit bc2187b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 36 deletions.
44 changes: 20 additions & 24 deletions bin/criticize.pl
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ BEGIN
my $usage = <<END;
USAGE: $0
Runs Perl::Critic on all .pm, .pl, and extensionless files in cgi/ and bin/.
This is offered as a sort of sanity check and is not currently part of the
test suite.
Runs Perl::Critic on all .pm, .pl, and extensionless files in bin/, cgi/, lib/, and t/.
This is not currently part of the test suite.
-h Print this help message.
-v Emit verbose debugging information. May be repeated.
Expand All @@ -39,39 +38,36 @@ END
if ($help) { print $usage. "\n"; exit(0); }
print "Verbosity $verbose\n" if $verbose;


my $critic = Perl::Critic->new();

my @dirs = ($ENV{'SDRROOT'}. '/crms/cgi', $ENV{'SDRROOT'}. '/crms/bin');
my $exit_status = 0;
my @dirs = map { $ENV{SDRROOT} . $_; } ('/crms/bin', '/crms/cgi', '/crms/lib', '/crms/t');
my %seen;
while (my $pwd = shift @dirs)
{
opendir(DIR, "$pwd") or die "Can't open $pwd\n";
while (my $dir = shift @dirs) {
opendir(DIR, "$dir") or die "Can't open $dir\n";
my @files = readdir(DIR);
closedir(DIR);
foreach my $file (sort @files)
{
foreach my $file (sort @files) {
next if $file =~ /^\.\.?$/;
next if $file eq 'legacy';
my $path = "$pwd/$file";
if (-d $path)
{
my $path = "$dir/$file";
if (-d $path) {
next if $seen{$path};
$seen{$path} = 1;
push @dirs, $path;
}
my $desc = `file $path`;
chomp $desc;
next unless $desc =~ m/perl/i;
my @violations = $critic->critique($path);
if (scalar @violations)
{
print RED "$path\n";
print BOLD " $_" for @violations;
}
else
{
print GREEN "$path\n";
if ($desc =~ m/perl/i || $path =~ m/\.pm$/ || $path =~ m/\.t$/) {
my @violations = $critic->critique($path);
if (scalar @violations) {
print RED "$path\n";
print BOLD " $_" for @violations;
$exit_status = 1;
}
else {
print GREEN "$path\n" if $verbose;
}
}
}
}
exit($exit_status);
2 changes: 1 addition & 1 deletion bin/newyear.pl
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ sub SubmitNewYearReview
$record->title || '', $record->publication_date->text || '',
$record->country || '', "$acurr/$rcurr", $extracted_data,
$predictions, "$new_attr/$new_reason", $msg);
@values = map { local $_ = $_; $_ =~ s/\s+/ /g; $_; } @values;
@values = map { s/\s+/ /gr } @values;
printf $tsv_fh "%s\n", join("\t", @values);
}
}
Expand Down
12 changes: 6 additions & 6 deletions cgi/CRMS.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package CRMS;

use strict;
use warnings;
use utf8;

## ----------------------------------------------------------
## Object of shared code for the CRMS DB CGI and BIN scripts.
## ----------------------------------------------------------
Expand All @@ -10,10 +14,6 @@ BEGIN {
use lib $ENV{'SDRROOT'} . '/crms/lib';
}

use strict;
use warnings;
use utf8;

use CGI;
use Data::Dumper;
use Date::Calc qw(:all);
Expand Down Expand Up @@ -1105,7 +1105,7 @@ sub WriteRightsFile
}
my $temp = $perm . '.tmp';
if (-f $temp) { die "file already exists: $temp\n"; }
open (my $fh, '>:utf8', $temp) || die "failed to open rights file ($temp): $!\n";
open (my $fh, '>:encoding(UTF-8)', $temp) || die "failed to open rights file ($temp): $!\n";
print $fh $rights;
close $fh;
rename $temp, $perm;
Expand Down Expand Up @@ -1273,7 +1273,7 @@ sub CheckAndLoadItemIntoCandidates
$self->RemoveFromCandidates($id);
}
}
return undef;
return;
}

sub AddItemToCandidates
Expand Down
10 changes: 5 additions & 5 deletions cgi/Metadata.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package Metadata;

use strict;
use warnings;
use utf8;

BEGIN {
die "SDRROOT environment variable not set" unless defined $ENV{'SDRROOT'};
use lib $ENV{'SDRROOT'} . '/crms/lib';
Expand All @@ -16,10 +20,6 @@ BEGIN {

use vars qw(@ISA @EXPORT @EXPORT_OK);

use strict;
use warnings;
use utf8;

use Carp;
use DB_File;
use File::Slurp;
Expand Down Expand Up @@ -111,7 +111,7 @@ sub US_Cities {
if (!defined $US_CITIES) {
my %us_cities;
my $us_cities_db = $ENV{'SDRROOT'} . '/crms/post_zephir_processing/data/us_cities.db';
tie %us_cities, 'DB_File', $us_cities_db, O_RDONLY, 0644, $DB_BTREE or die "can't open db file $us_cities_db: $!";
tie %us_cities, 'DB_File', $us_cities_db, O_RDONLY, oct(644), $DB_BTREE or die "can't open db file $us_cities_db: $!";
$US_CITIES = \%us_cities;
}
return $US_CITIES;
Expand Down

0 comments on commit bc2187b

Please sign in to comment.