]> git.donarmstrong.com Git - wannabuild.git/commitdiff
Use open in a modern way.
authorHilko Bengen <bengen@debian.org>
Wed, 30 Mar 2011 18:39:45 +0000 (20:39 +0200)
committerAndreas Barth <aba@not.so.argh.org>
Wed, 30 Mar 2011 19:42:19 +0000 (21:42 +0200)
Two perlcritic warnings triggered this change:
- Two-argument "open" used
- Bareword file handle opened

This should not cause any behavioral changes.

bin/wanna-build
bin/wanna-build-statistics
bin/wb-graph
lib/WB/QD.pm

index 27fb2126d65e8eaaa78312b8819fe5b109ec4636..5ebd6196a8f8b917f3b14e6fd897208e8689ecb9 100755 (executable)
@@ -2262,11 +2262,11 @@ sub read_db {
        my $file = shift;
 
        print "Reading ASCII database from $file..." if $verbose >= 1;
-       open( F, "<$file" ) or
+       open( my $fh, '<', $file ) or
                die "Can't open database $file: $!\n";
 
        local($/) = ""; # read in paragraph mode
-       while( <F> ) {
+       while( <$fh> ) {
                my( %thispkg, $name );
                s/[\s\n]+$//;
                s/\n[ \t]+/\376\377/g;  # fix continuation lines
@@ -2294,7 +2294,7 @@ sub read_db {
                                or die $dbh->errstr;
                 }
        }
-       close( F );
+       close( $fh );
        print "done\n" if $verbose >= 1;
 }
 
@@ -2334,7 +2334,7 @@ sub export_db {
        my($name,$pkg,$key);
 
        print "Writing ASCII database to $file..." if $verbose >= 1;
-       open( F, ">$file" ) or
+       open( my $fh, '>', $file ) or
                die "Can't open export $file: $!\n";
 
         my $db = get_all_source_info();
@@ -2347,11 +2347,11 @@ sub export_db {
                        $val =~ s/\n*$//;
                        $val =~ s/^/ /mg;
                        $val =~ s/^ +$/ ./mg;
-                       print F "$key: $val\n";
+                       print $fh "$key: $val\n";
                }
-               print F "\n";
+               print $fh "\n";
        }
-       close( F );
+       close( $fh );
        print "done\n" if $verbose >= 1;
 }
 
@@ -2428,13 +2428,13 @@ sub send_mail {
        $to .= '@' . $domain if $to !~ /\@/;
        $text =~ s/^\.$/../mg;
        local $SIG{'PIPE'} = 'IGNORE';
-       open( PIPE,  "| $conf::mailprog -oem $to" )
+       open( my $pipe,  '|-', "$conf::mailprog -oem $to" )
                or die "Can't open pipe to $conf::mailprog: $!\n";
        chomp $text;
-       print PIPE "From: $from\n";
-       print PIPE "Subject: $subject\n\n";
-       print PIPE "$text\n";
-       close( PIPE );
+       print $pipe "From: $from\n";
+       print $pipe "Subject: $subject\n\n";
+       print $pipe "$text\n";
+       close( $pipe );
 }
 
 # for parsing input to dep-wait
@@ -2508,8 +2508,8 @@ sub wb_edos_builddebcheck {
 
     my $packagearch="";
     foreach my $packagefile (@$packagefiles) {
-        open(P,$packagefile);
-        while (<P>) {
+        open(my $fh,'<', $packagefile);
+        while (<$fh>) {
             next unless /^Architecture/;
             next if /^Architecture:\s*all/;
             /Architecture:\s*([^\s]*)/;
@@ -2519,7 +2519,7 @@ sub wb_edos_builddebcheck {
                return "Package file contains different architectures: $packagearch, $1";
             }
         }
-        close P;
+        close $fh;
     }
 
     if ( $architecture eq "" ) {
@@ -2537,14 +2537,14 @@ sub wb_edos_builddebcheck {
     }
 
     print "calling: edos-debcheck $edosoptions < $sourcesfile ".join('', map {" '-base FILE' ".$_ } @$packagefiles)."\n";
-    open(RESULT, '-|',
+    open(my $result_cmd, '-|',
         "edos-debcheck $edosoptions < $sourcesfile ".join('', map {" '-base FILE' ".$_ } @$packagefiles));
 
     my $explanation="";
     my $result={};
     my $binpkg="";
 
-    while (<RESULT>) {
+    while (<$result_cmd>) {
 # source---pulseaudio (= 0.9.15-4.1~bpo50+1): FAILED
 #   source---pulseaudio (= 0.9.15-4.1~bpo50+1) depends on missing:
 #   - libltdl-dev (>= 2.2.6a-2)
@@ -2573,7 +2573,7 @@ sub wb_edos_builddebcheck {
         }
     }
 
-    close RESULT;
+    close $result_cmd;
     $result->{$binpkg} = $explanation if $binpkg;
     return $result;
 
index 3d7b0d10b070e2e31ba148abc258d59294d30c16..6719306c8e76e9cb0b741dd2aaa82d9cd8313357 100755 (executable)
@@ -69,9 +69,9 @@ while( @ARGV && $ARGV[0] =~ /^-/ ) {
 }
 
 my($lastmsg, %n_state, $total, %n_builder);
-open( PIPE, "wanna-build --database=$database --dist=$dist --list=all 2>&1 |" )
+open( my $pipe, '-|', "wanna-build --database=$database --dist=$dist --list=all 2>&1" )
        or die "Cannot spawn wanna-build: $!\n";
-while( <PIPE> ) {
+while( <$pipe> ) {
        if (/^Database for $dist doesn't exist$/) {
                exit 1;
        }
@@ -86,7 +86,7 @@ while( <PIPE> ) {
        }
        $lastmsg = $_;
 }
-close( PIPE );
+close( $pipe );
 if ($?) {
        print "$lastmsg";
        die "Bad exit status $? from wanna-build\n";
index 2a952d004b2374ef05cbc525c459917cf5d8e1a9..fb326e8e433edc62fdf3402e895f27ae53bcba3b 100755 (executable)
@@ -43,9 +43,9 @@ foreach $arch (@archs) {
 my($lastmsg, %n_state, $total, %n_builder, $pu_total);
 $pu_total = 0;
 $n_state{"Installed"} = 0;
-open( PIPE, "wanna-build --database=$arch/build-db --dist=$dist --list=all |" )
+open( my $pipe, '-|', "wanna-build --database=$arch/build-db --dist=$dist --list=all" )
        or die "Cannot spawn wanna-build: $!\n";
-while( <PIPE> ) {
+while( <$pipe> ) {
        if (/^Database for $dist doesn't exist$/) {
                last;
        }
@@ -64,7 +64,7 @@ while( <PIPE> ) {
        }
        $lastmsg = $_;
 }
-close( PIPE );
+close( $pipe );
 if ($?) {
        print ", 0, 0";
 } else {
index 58b452788f39a0b813434908449c46bfecee5794..8391fc3066d05f3547c35d01e78524b71f564b25 100644 (file)
@@ -15,15 +15,15 @@ sub readsourcebins {
 
     my $pas = {};
     local($/) = "\n";
-    open(PAS, '<', $pasfile);
-    while(<PAS>) {
+    open(my $pas, '<', $pasfile);
+    while(<$pas>) {
         chomp;
         s,\s*#.*,,;
         next unless $_;
         my ($p, $c) = split(/:\s*/);
         $pas->{$p} = { arch => [ split(/\s+/, $c) ], mode => substr($c, 0, 1) ne '!' };
     }
-    close PAS;
+    close $pas;
 
     my $srcs = {};
     local($/) = ""; # read in paragraph mode