@EXPORT = ();
%EXPORT_TAGS = ();
- @EXPORT_OK = (qw(get_bugs));
+ @EXPORT_OK = (qw(get_bugs count_bugs));
$EXPORT_TAGS{all} = [@EXPORT_OK];
}
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
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;
}
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 {