]> git.donarmstrong.com Git - debbugs.git/commitdiff
* Pull countbugs out to Debbugs::Bugs so things can use it without
authorDon Armstrong <don@donarmstrong.com>
Sun, 20 May 2007 07:09:43 +0000 (00:09 -0700)
committerDon Armstrong <don@donarmstrong.com>
Sun, 20 May 2007 07:09:43 +0000 (00:09 -0700)
   requiring cgi/common.pl; have common.pl call count_bugs.

Debbugs/Bugs.pm
cgi/common.pl

index 5a4156e7bf6dcc9baedea185b687c4f8e2598649..e46e70ea505a91e260c9ae0e1abd8f5f5e8c2a1d 100644 (file)
@@ -40,7 +40,7 @@ BEGIN{
 
      @EXPORT = ();
      %EXPORT_TAGS = ();
-     @EXPORT_OK = (qw(get_bugs));
+     @EXPORT_OK = (qw(get_bugs count_bugs));
      $EXPORT_TAGS{all} = [@EXPORT_OK];
 }
 
@@ -214,6 +214,52 @@ sub get_bugs{
      return @bugs;
 }
 
+=head2 count_bugs
+
+     count_bugs(function => sub {...})
+
+Uses a subroutine to classify bugs into categories and return the
+number of bugs which fall into those categories
+
+=cut
+
+sub count_bugs {
+     my %param = validate_with(params => \@_,
+                              spec   => {function => {type => CODEREF,
+                                                     },
+                                         archive  => {type => BOOLEAN,
+                                                      default => 0,
+                                                     },
+                                        },
+                             );
+     my $flatfile;
+     if ($param{archive}) {
+         $flatfile = IO::File->new("$config{spool_dir}/index.archive", 'r')
+              or die "Unable to open $config{spool_dir}/index.archive for reading: $!";
+     }
+     else {
+         $flatfile = IO::File->new("$config{spool_dir}/index.db", 'r')
+              or die "Unable to open $config{spool_dir}/index.db for reading: $!";
+     }
+     my %count = ();
+     while(<$flatfile>) {
+         if (m/^(\S+)\s+(\d+)\s+(\d+)\s+(\S+)\s+\[\s*([^]]*)\s*\]\s+(\w+)\s+(.*)$/) {
+              my @x = $param{function}->(pkg       => $1,
+                                         bug       => $2,
+                                         status    => $4,
+                                         submitter => $5,
+                                         severity  => $6,
+                                         tags      => $7,
+                                        );
+              local $_;
+              $count{$_}++ foreach @x;
+         }
+     }
+     close $flatfile;
+     return %count;
+}
+
+
 =head2 get_bugs_by_idx
 
 This routine uses the by-$index.idx indicies to try to speed up
index 5805907ce62eb18a055b644ac17ab968ff1c7014..4701006e378dbe7de0b5ec02c54806a11ba3b7b4 100644 (file)
@@ -19,6 +19,7 @@ use Debbugs::MIME qw(decode_rfc1522);
 use Debbugs::Common qw(:util);
 use Debbugs::Status qw(:status :read :versions);
 use Debbugs::CGI qw(:all);
+use Debbugs::Bugs qw(count_bugs);
 
 $MLDBM::RemoveTaint = 1;
 
@@ -586,27 +587,9 @@ sub htmlizebugs {
 }
 
 sub countbugs {
-    my $bugfunc = shift;
-    if ($common_archive) {
-        open I, "<$gSpoolDir/index.archive"
-            or &quitcgi("$gSpoolDir/index.archive: $!");
-    } else {
-        open I, "<$gSpoolDir/index.db"
-            or &quitcgi("$gSpoolDir/index.db: $!");
-    }
-
-    my %count = ();
-    while(<I>) 
-    {
-        if (m/^(\S+)\s+(\d+)\s+(\d+)\s+(\S+)\s+\[\s*([^]]*)\s*\]\s+(\w+)\s+(.*)$/) {
-            my @x = $bugfunc->(pkg => $1, bug => $2, status => $4, 
-                               submitter => $5, severity => $6, tags => $7);
-            local $_;
-            $count{$_}++ foreach @x;
-       }
-    }
-    close I;
-    return %count;
+     return count_bugs(function=>shift,
+                      archive => $commonarchive,
+                     );
 }
 
 sub getbugs {