Kaynağa Gözat

perl: Fix unused capture groups false positives

These are false positives, as when there's no match perl will leave
the subpattern variables untouched. We'll just use the opportunity to
unconfuse perlcritic, making some of those variable usages more clear
by using intermediate variables.

Fixes RegularExpressions::ProhibitUnusedCapture.

Warned-by: perlcritic
Guillem Jover 12 yıl önce
ebeveyn
işleme
1e5163809e

+ 2 - 2
dselect/methods/ftp/install

@@ -480,8 +480,8 @@ sub getdebinfo($) {
 	open(my $pkgfile_fh, '-|', "dpkg-split --info $fn")
 	open(my $pkgfile_fh, '-|', "dpkg-split --info $fn")
 	    or die "cannot create pipe for 'dpkg-split --info $fn'";
 	    or die "cannot create pipe for 'dpkg-split --info $fn'";
 	while (<$pkgfile_fh>) {
 	while (<$pkgfile_fh>) {
-	    /Part of package:\s*(\S+)/ and $pkg = $+;
-	    /\.\.\. version:\s*(\S+)/ and $ver = $+;
+	    /Part of package:\s*(\S+)/ and $pkg = $1;
+	    /\.\.\. version:\s*(\S+)/ and $ver = $1;
 	}
 	}
 	close($pkgfile_fh);
 	close($pkgfile_fh);
 	return $pkg, $ver;
 	return $pkg, $ver;

+ 6 - 5
scripts/Dpkg/Control/HashCore.pm

@@ -202,16 +202,17 @@ sub parse {
 	$paraborder = 0;
 	$paraborder = 0;
 	if (m/^(\S+?)\s*:\s*(.*)$/) {
 	if (m/^(\S+?)\s*:\s*(.*)$/) {
 	    $parabody = 1;
 	    $parabody = 1;
-	    if ($1 =~ m/^-/) {
+	    my ($name, $value) = ($1, $2);
+	    if ($name =~ m/^-/) {
 		$self->parse_error($desc, _g('field cannot start with a hyphen'));
 		$self->parse_error($desc, _g('field cannot start with a hyphen'));
 	    }
 	    }
-	    if (exists $self->{$1}) {
+	    if (exists $self->{$name}) {
 		unless ($$self->{allow_duplicate}) {
 		unless ($$self->{allow_duplicate}) {
-		    $self->parse_error($desc, _g('duplicate field %s found'), $1);
+		    $self->parse_error($desc, _g('duplicate field %s found'), $name);
 		}
 		}
 	    }
 	    }
-	    $self->{$1} = $2;
-	    $cf = $1;
+	    $self->{$name} = $value;
+	    $cf = $name;
 	} elsif (m/^\s(\s*\S.*)$/) {
 	} elsif (m/^\s(\s*\S.*)$/) {
 	    my $line = $1;
 	    my $line = $1;
 	    unless (defined($cf)) {
 	    unless (defined($cf)) {

+ 4 - 2
scripts/Dpkg/Shlibs/Objdump.pm

@@ -237,10 +237,12 @@ sub parse_objdump_output {
                 # RUNPATH takes precedence over RPATH but is
                 # RUNPATH takes precedence over RPATH but is
                 # considered after LD_LIBRARY_PATH while RPATH
                 # considered after LD_LIBRARY_PATH while RPATH
                 # is considered before (if RUNPATH is not set).
                 # is considered before (if RUNPATH is not set).
-                $self->{RPATH} = [ split (/:/, $1) ];
+                my $runpath = $1;
+                $self->{RPATH} = [ split /:/, $runpath ];
 	    } elsif (/^\s*RPATH\s+(\S+)/) {
 	    } elsif (/^\s*RPATH\s+(\S+)/) {
+                my $rpath = $1;
                 unless (scalar(@{$self->{RPATH}})) {
                 unless (scalar(@{$self->{RPATH}})) {
-                    $self->{RPATH} = [ split (/:/, $1) ];
+                    $self->{RPATH} = [ split /:/, $rpath ];
                 }
                 }
 	    }
 	    }
 	} elsif ($section eq 'none') {
 	} elsif ($section eq 'none') {

+ 6 - 3
scripts/dpkg-buildpackage.pl

@@ -210,7 +210,8 @@ while (@ARGV) {
     } elsif (/^-j(\d*)$/) {
     } elsif (/^-j(\d*)$/) {
 	$parallel = $1 || '';
 	$parallel = $1 || '';
     } elsif (/^-r(.*)$/) {
     } elsif (/^-r(.*)$/) {
-	@rootcommand = split /\s+/, $1;
+	my $arg = $1;
+	@rootcommand = split /\s+/, $arg;
     } elsif (/^--check-command=(.*)$/) {
     } elsif (/^--check-command=(.*)$/) {
 	$check_command = $1;
 	$check_command = $1;
     } elsif (/^--check-option=(.*)$/) {
     } elsif (/^--check-option=(.*)$/) {
@@ -242,7 +243,8 @@ while (@ARGV) {
     } elsif (/^-a(.*)$/) {
     } elsif (/^-a(.*)$/) {
 	$targetarch = $1;
 	$targetarch = $1;
     } elsif (/^-P(.*)$/) {
     } elsif (/^-P(.*)$/) {
-	@build_profiles = split /,/, $1;
+	my $arg = $1;
+	@build_profiles = split /,/, $arg;
     } elsif (/^-s[iad]$/) {
     } elsif (/^-s[iad]$/) {
 	push @changes_opts, $_;
 	push @changes_opts, $_;
     } elsif (/^-(?:s[insAkurKUR]|[zZ].*|i.*|I.*)$/) {
     } elsif (/^-(?:s[insAkurKUR]|[zZ].*|i.*|I.*)$/) {
@@ -306,7 +308,8 @@ while (@ARGV) {
 	# Deprecated option
 	# Deprecated option
 	warning(_g('-E and -W are deprecated, they are without effect'));
 	warning(_g('-E and -W are deprecated, they are without effect'));
     } elsif (/^-R(.*)$/) {
     } elsif (/^-R(.*)$/) {
-	@debian_rules = split /\s+/, $1;
+	my $arg = $1;
+	@debian_rules = split /\s+/, $arg;
     } else {
     } else {
 	usageerr(_g('unknown option or argument %s'), $_);
 	usageerr(_g('unknown option or argument %s'), $_);
     }
     }

+ 2 - 1
scripts/dpkg-shlibdeps.pl

@@ -860,7 +860,8 @@ sub find_packages {
 	    print { *STDERR } " $_\n"
 	    print { *STDERR } " $_\n"
 		or syserr(_g('write diversion info to stderr'));
 		or syserr(_g('write diversion info to stderr'));
 	} elsif (m/^([-a-z0-9+.:, ]+): (\/.*)$/) {
 	} elsif (m/^([-a-z0-9+.:, ]+): (\/.*)$/) {
-	    $cached_pkgmatch{$2} = $pkgmatch->{$2} = [ split(/, /, $1) ];
+	    my ($pkgs, $path) = ($1, $2);
+	    $cached_pkgmatch{$path} = $pkgmatch->{$path} = [ split /, /, $pkgs ];
 	} else {
 	} else {
 	    warning(_g("unknown output from dpkg --search: '%s'"), $_);
 	    warning(_g("unknown output from dpkg --search: '%s'"), $_);
 	}
 	}

+ 1 - 0
test/critic.t

@@ -80,6 +80,7 @@ my @policies = qw(
     NamingConventions::Capitalization
     NamingConventions::Capitalization
     Objects::ProhibitIndirectSyntax
     Objects::ProhibitIndirectSyntax
     RegularExpressions::ProhibitSingleCharAlternation
     RegularExpressions::ProhibitSingleCharAlternation
+    RegularExpressions::ProhibitUnusedCapture
     RegularExpressions::ProhibitUnusualDelimiters
     RegularExpressions::ProhibitUnusualDelimiters
     RegularExpressions::RequireBracesForMultiline
     RegularExpressions::RequireBracesForMultiline
     Subroutines::ProhibitExplicitReturnUndef
     Subroutines::ProhibitExplicitReturnUndef