ソースを参照

perl: Do not use the topic variable unnecessarily

Fixes BuiltinFunctions::ProhibitUselessTopic
and RegularExpressions::ProhibitUselessTopic.

Warned-by: perlcritic
Guillem Jover 12 年 前
コミット
fe60460326

+ 1 - 1
scripts/Dpkg/Checksums.pm

@@ -164,7 +164,7 @@ sub add_from_file {
     my $key = exists $opts{key} ? $opts{key} : $file;
     my @alg;
     if (exists $opts{checksums}) {
-	push @alg, map { lc($_) } @{$opts{checksums}};
+	push @alg, map { lc } @{$opts{checksums}};
     } else {
 	push @alg, checksums_get_list();
     }

+ 4 - 4
scripts/Dpkg/Control/HashCore.pm

@@ -235,8 +235,8 @@ sub parse {
 	} elsif (m/^$/ || ($expect_pgp_sig && m/^-----BEGIN PGP SIGNATURE-----$/)) {
 	    if ($expect_pgp_sig) {
 		# Skip empty lines
-		$_ = <$fh> while defined($_) && $_ =~ /^\s*$/;
-		unless (length $_) {
+		$_ = <$fh> while defined && m/^\s*$/;
+		unless (length) {
 		    $self->parse_error($desc, _g('expected OpenPGP signature, ' .
 		                                 'found EOF after blank line'));
 		}
@@ -250,7 +250,7 @@ sub parse {
 		    s/\s*\n$//;
 		    last if m/^-----END PGP SIGNATURE-----$/;
 		}
-		unless (defined($_)) {
+		unless (defined) {
 		    $self->parse_error($desc, _g('unfinished OpenPGP signature'));
                 }
 		# This does not mean the signature is correct, that needs to
@@ -500,7 +500,7 @@ sub DELETE {
     $key = lc($key);
     if (exists $self->[0]->{$key}) {
 	delete $self->[0]->{$key};
-	@$in_order = grep { lc($_) ne $key } @$in_order;
+	@{$in_order} = grep { lc ne $key } @{$in_order};
 	return 1;
     } else {
 	return 0;

+ 1 - 1
scripts/Dpkg/Deps.pm

@@ -163,7 +163,7 @@ joining them with ", " if appropriate, and always returning a valid string.
 sub deps_concat {
     my (@dep_list) = @_;
 
-    return join(', ', grep { defined $_ } @dep_list);
+    return join ', ', grep { defined } @dep_list;
 }
 
 =item my $dep = deps_parse($line, %options)

+ 1 - 1
scripts/Dpkg/Shlibs/Objdump.pm

@@ -191,7 +191,7 @@ sub parse_objdump_output {
     my ($self, $fh) = @_;
 
     my $section = 'none';
-    while (defined($_ = <$fh>)) {
+    while (<$fh>) {
 	chomp;
 	next if /^\s*$/;
 

+ 2 - 2
scripts/Dpkg/Shlibs/SymbolFile.pm

@@ -216,8 +216,8 @@ sub parse {
         $$obj_ref = undef;
     }
 
-    while (defined($_ = <$fh>)) {
-	chomp($_);
+    while (<$fh>) {
+	chomp;
 
 	if (/^(?:\s+|#(?:DEPRECATED|MISSING): ([^#]+)#\s*)(.*)/) {
 	    if (not defined ($$obj_ref)) {

+ 3 - 3
scripts/Dpkg/Source/Package/V2.pm

@@ -173,7 +173,7 @@ sub do_extract {
     # symlink
     my @exclude_symlinks;
     my $wanted = sub {
-        return if not -l $_;
+        return if not -l;
         my $fn = File::Spec->abs2rel($_, $newdirectory);
         push @exclude_symlinks, '--exclude', $fn;
     };
@@ -437,7 +437,7 @@ sub do_build {
     my $binaryfiles = Dpkg::Source::Package::V2::BinaryFiles->new($dir);
     my $unwanted_binaries = 0;
     my $check_binary = sub {
-        if (-f $_ and is_binary($_)) {
+        if (-f and is_binary($_)) {
             my $fn = File::Spec->abs2rel($_, $dir);
             $binaryfiles->new_binary_found($fn);
             unless ($include_binaries or $binaryfiles->binary_is_allowed($fn)) {
@@ -709,7 +709,7 @@ sub load_allowed_binaries {
     if (-f $incbin_file) {
         open(my $incbin_fh, '<', $incbin_file)
             or syserr(_g('cannot read %s'), $incbin_file);
-        while (defined($_ = <$incbin_fh>)) {
+        while (<$incbin_fh>) {
             chomp; s/^\s*//; s/\s*$//;
             next if /^#/ or /^$/;
             $self->{allowed_binaries}{$_} = 1;

+ 2 - 2
scripts/Dpkg/Source/Package/V3/Bzr.pm

@@ -68,8 +68,8 @@ sub sanity_check {
     }
     my $abs_srcdir = Cwd::abs_path($srcdir);
     find(sub {
-        if (-l $_) {
-            if (Cwd::abs_path(readlink($_)) !~ /^\Q$abs_srcdir\E(?:\/|$)/) {
+        if (-l) {
+            if (Cwd::abs_path(readlink) !~ /^\Q$abs_srcdir\E(?:\/|$)/) {
                 error(_g('%s is a symlink to outside %s'),
                       $File::Find::name, $srcdir);
             }

+ 2 - 2
scripts/Dpkg/Source/Quilt.pm

@@ -365,10 +365,10 @@ sub restore_quilt_backup_files {
     find({
         no_chdir => 1,
         wanted => sub {
-            return if -d $_;
+            return if -d;
             my $relpath_in_srcpkg = File::Spec->abs2rel($_, $patch_dir);
             my $target = File::Spec->catfile($self->{dir}, $relpath_in_srcpkg);
-            if (-s $_) {
+            if (-s) {
                 unlink($target);
                 make_path(dirname($target));
                 unless (link($_, $target)) {

+ 1 - 1
scripts/dpkg-buildpackage.pl

@@ -411,7 +411,7 @@ if ($changedby) {
 
 open my $arch_env, '-|', 'dpkg-architecture', "-a$targetarch",
     "-t$targetgnusystem", '-f' or subprocerr('dpkg-architecture');
-while ($_ = <$arch_env>) {
+while (<$arch_env>) {
     chomp;
     my ($key, $value) = split /=/, $_, 2;
     $ENV{$key} = $value;

+ 1 - 1
scripts/dpkg-gensymbols.pl

@@ -195,7 +195,7 @@ if (not scalar @files) {
 	opendir(my $libdir_dh, "$libdir")
 	    or syserr(_g("can't read directory %s: %s"), $libdir, $!);
 	push @files, grep {
-	    /(\.so\.|\.so$)/ && -f $_ &&
+	    /(\.so\.|\.so$)/ && -f &&
 	    Dpkg::Shlibs::Objdump::is_elf($_);
 	} map { "$libdir/$_" } readdir($libdir_dh);
 	closedir $libdir_dh;

+ 1 - 1
scripts/dpkg-scansources.pl

@@ -180,7 +180,7 @@ sub load_src_override {
 	next if /^\s*$/;
 	s/\s+$//;
 
-	my @data = split ' ', $_;
+	my @data = split ' ';
 	unless (@data == 2) {
 	    warning(_g('invalid source override entry at line %d (%d fields)'),
 	            $., 0 + @data);

+ 2 - 2
scripts/dpkg-shlibdeps.pl

@@ -851,8 +851,8 @@ sub find_packages {
 	exec('dpkg', '--search', '--', @files)
 	    or syserr(_g('unable to execute %s'), 'dpkg');
     }
-    while (defined($_ = <$dpkg_fh>)) {
-	chomp($_);
+    while (<$dpkg_fh>) {
+	chomp;
 	if (m/^local diversion |^diversion by/) {
 	    warning(_g('diversions involved - output may be incorrect'));
 	    print { *STDERR } " $_\n"

+ 2 - 0
test/critic.t

@@ -41,6 +41,7 @@ my @policies = qw(
     BuiltinFunctions::ProhibitStringySplit
     BuiltinFunctions::ProhibitUniversalCan
     BuiltinFunctions::ProhibitUniversalIsa
+    BuiltinFunctions::ProhibitUselessTopic
     BuiltinFunctions::ProhibitVoidGrep
     BuiltinFunctions::ProhibitVoidMap
     BuiltinFunctions::RequireBlockGrep
@@ -82,6 +83,7 @@ my @policies = qw(
     RegularExpressions::ProhibitSingleCharAlternation
     RegularExpressions::ProhibitUnusedCapture
     RegularExpressions::ProhibitUnusualDelimiters
+    RegularExpressions::ProhibitUselessTopic
     RegularExpressions::RequireBracesForMultiline
     Subroutines::ProhibitExplicitReturnUndef
     Subroutines::ProhibitNestedSubs