1 # This module is part of debbugs, and is released
2 # under the terms of the GPL version 2, or any later
3 # version at your option.
4 # See the file README and COPYING for more information.
6 # Copyright 2014 by Don Armstrong <don@donarmstrong.com>.
8 package Debbugs::BugWalker;
12 Debbugs::BugWalker -- Walk through all known bugs
16 use Debbugs::BugWalker;
17 my $w = Debbugs::BugWalker->new();
21 This module contains routines to walk through all known bugs (and
22 return specific files or bug numbers).
32 use vars qw($VERSION $DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT);
33 use base qw(Exporter);
37 $DEBUG = 0 unless defined $DEBUG;
42 $EXPORT_TAGS{all} = [@EXPORT_OK];
45 use Debbugs::Config qw(:config);
46 use Debbugs::Common qw(make_list);
55 =item C<Debbugs::BugWalker-E<gt>new()>
57 Create a new bugwalker object to walk through available bugs.
59 Takes the following options
65 L<Term::ProgressBar> to update progress on a terminal dynamically
73 if (not defined $_[0] or
76 die "Progress must support ->update";
83 Directories to use to search for bugs; defaults to
94 What files/directories to return. Defaults to bug, but must be one of
95 summary, bug, log, or status.
102 die "Must be one of summary, bug, log, status, version, or debinfo"
103 unless $_[0] =~ /^(?:summary|bug|log|status|version|debinfo)$/;
116 if (not defined $self->{_dirs}) {
117 $self->{_dirs} = [make_list($self->dirs())];
118 $self->{_done_dirs} = 0;
119 $self->{_done_files} = 0;
120 $self->{_avg_subfiles} = 0;
122 if (not defined $self->{_files}) {
123 $self->{_files} = [];
125 while (not @{$self->{_files}}) {
126 my $next_dir = shift @{$self->{_dirs}};
127 my $nd = IO::Dir->new($next_dir) or
128 die "Unable to open $next_dir for reading: $!";
130 while (defined ($f = $nd->read)) {
131 my $fn = File::Spec->catfile($next_dir,$f);
133 push @{$self->{_dirs}},$fn;
134 $self->{_total_dirs}++;
136 if ($self->{what} eq 'bug') {
137 next unless $fn =~ /(\d+)\.status$/;
138 push @{$self->{_files}}, $1;
140 next unless $fn =~ /\.$self->{what}$/;
141 push @{$self->{_files}}, $fn;
145 if (defined $self->progress) {
146 $self->progress->target($self->{_avg_subfiles}*$self->{_dirs}+
147 $self->{_done_files}+@{$self->{_files}});
148 $self->{_avg_subfiles} =
149 ($self->{_avg_subfiles}*$self->{_done_dirs}+@{$self->{_files}})/
150 ($self->{_done_dirs}+1);
152 $self->{_done_dirs}++;
154 if (@{$self->{_files}}) {
155 $self->progress->update($self->{done_files}++);
156 return shift @{$self->{_files}};