From 3a63bf2b966adce2531457567c38e31f486e2efe Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Sun, 20 May 2007 00:09:43 -0700 Subject: [PATCH] * Pull countbugs out to Debbugs::Bugs so things can use it without requiring cgi/common.pl; have common.pl call count_bugs. --- Debbugs/Bugs.pm | 48 +++++++++++++++++++++++++++++++++++++++++++++++- cgi/common.pl | 25 ++++--------------------- 2 files changed, 51 insertions(+), 22 deletions(-) diff --git a/Debbugs/Bugs.pm b/Debbugs/Bugs.pm index 5a4156e7..e46e70ea 100644 --- a/Debbugs/Bugs.pm +++ b/Debbugs/Bugs.pm @@ -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 diff --git a/cgi/common.pl b/cgi/common.pl index 5805907c..4701006e 100644 --- a/cgi/common.pl +++ b/cgi/common.pl @@ -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() - { - 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 { -- 2.39.5