Просмотр исходного кода

Dpkg::Shlibs::Objdump: Add an optional objdump argument to get_format

This gets rid of the localized $OBJDUMP variable, by explicitly passing
the overriden value to the recursive call.

Fixes Variables::ProhibitLocalVars.
Guillem Jover лет назад: 13
Родитель
Сommit
46bc7b2ee0
2 измененных файлов с 8 добавлено и 6 удалено
  1. 7 6
      scripts/Dpkg/Shlibs/Objdump.pm
  2. 1 0
      test/100_critic.t

+ 7 - 6
scripts/Dpkg/Shlibs/Objdump.pm

@@ -85,16 +85,18 @@ sub has_object {
 {
     my %format; # Cache of result
     sub get_format {
-	my ($file) = @_;
+	my ($file, $objdump) = @_;
+
+	$objdump //= $OBJDUMP;
 
 	if (exists $format{$file}) {
 	    return $format{$file};
 	} else {
 	    my ($output, %opts, $pid, $res);
-	    if ($OBJDUMP ne 'objdump') {
+	    if ($objdump ne 'objdump') {
 		$opts{error_to_file} = '/dev/null';
 	    }
-	    $pid = spawn(exec => [ $OBJDUMP, '-a', '--', $file ],
+	    $pid = spawn(exec => [ $objdump, '-a', '--', $file ],
 			 env => { LC_ALL => 'C' },
 			 to_pipe => \$output, %opts);
 	    while (<$output>) {
@@ -108,9 +110,8 @@ sub has_object {
 	    close($output);
 	    wait_child($pid, nocheck => 1);
 	    if ($?) {
-		subprocerr('objdump') if $OBJDUMP eq 'objdump';
-		local $OBJDUMP = 'objdump';
-		$res = get_format($file);
+		subprocerr('objdump') if $objdump eq 'objdump';
+		$res = get_format($file, 'objdump');
 	    }
 	    return $res;
 	}

+ 1 - 0
test/100_critic.t

@@ -100,6 +100,7 @@ my @policies = qw(
     ValuesAndExpressions::RequireUpperCaseHeredocTerminator
     Variables::ProhibitAugmentedAssignmentInDeclaration
     Variables::ProhibitConditionalDeclarations
+    Variables::ProhibitLocalVars
     Variables::ProhibitPerl4PackageNames
     Variables::ProhibitUnusedVariables
     Variables::ProtectPrivateVars