Subject: | Adding += |
Thanks for an excellent module!
Sometimes the list of things to do does not accurate reflect the amount
of time per thing. For example, when crunching logfiles, it takes a
different amount of time per log file with the size being a good guess.
The attached patch makes += work for this exact case:
my $total_size = sum map { -s } @filenames;
my $progress = Term::ProgressBar::Simple->new($total_size);
foreach my $filename (@filenames) {
...
$progress += -s $filename;
}
Please consider patching your module, thanks! Leon
Subject: | increment.diff |
diff -r 601905e8e8d9 lib/Term/ProgressBar/Simple.pm
--- a/lib/Term/ProgressBar/Simple.pm Tue Oct 14 14:43:00 2008 +0100
+++ b/lib/Term/ProgressBar/Simple.pm Tue Oct 14 14:51:57 2008 +0100
@@ -6,10 +6,11 @@ use Term::ProgressBar::Quiet;
use Term::ProgressBar::Quiet;
use overload #
- '++' => \&increment; #
+ '++' => \&increment, #
+ '+=' => \&increment; #
# '--' => \&decrement; # add later
-our $VERSION = '0.01';
+our $VERSION = '0.02';
=head1 NAME
@@ -114,8 +115,9 @@ about checking to see if the display nee
sub increment {
my $self = shift;
+ my $increment = shift || 1;
- $self->{count_so_far}++;
+ $self->{count_so_far} += $increment;
my $now = $self->{count_so_far};
if ( $now >= $self->{next_update} ) {
diff -r 601905e8e8d9 t/basic.pl
--- a/t/basic.pl Tue Oct 14 14:43:00 2008 +0100
+++ b/t/basic.pl Tue Oct 14 14:51:57 2008 +0100
@@ -18,5 +18,15 @@ use Time::HiRes qw( sleep );
}
+{
+use lib 'lib';
+ my $progress = Term::ProgressBar::Simple->new(20_000);
+
+ for ( 1 .. 10_000 ) {
+ $progress += 2;
+ }
+
+}
+
warn "progress destroyed";
ok 1;