Term-ProgressBar-Simple-0.03/0000755000076500007650000000000011150765404014460 5ustar evdbevdbTerm-ProgressBar-Simple-0.03/CHANGES0000644000076500007650000000025311150764563015460 0ustar evdbevdbRevision history for Perl module Term::ProgressBar::Simple: 0.03 2009-02-20 - added message 0.02 2008-10-17 - added += 0.01 2008-08-15 - initial release Term-ProgressBar-Simple-0.03/lib/0000755000076500007650000000000011150765404015226 5ustar evdbevdbTerm-ProgressBar-Simple-0.03/lib/Term/0000755000076500007650000000000011150765404016135 5ustar evdbevdbTerm-ProgressBar-Simple-0.03/lib/Term/ProgressBar/0000755000076500007650000000000011150765404020366 5ustar evdbevdbTerm-ProgressBar-Simple-0.03/lib/Term/ProgressBar/Simple.pm0000644000076500007650000001243311150764267022166 0ustar evdbevdbpackage Term::ProgressBar::Simple; use strict; use warnings; use Term::ProgressBar::Quiet; use overload # '++' => \&increment, # '+=' => \&increment; # # '--' => \&decrement; # add later our $VERSION = '0.03'; =head1 NAME Term::ProgressBar::Simple - simpler progress bars =head1 SYNOPSIS # create some things to loop over my @things = (...); my $number_of_things = scalar @things; # create the progress bar object my $progress = Term::ProgressBar::Simple->new( $number_of_things ); # loop foreach my $thing (@things) { # do some work $thing->do_something(); # increment the progress bar object to tell it a step has been taken. $progress++; } # See also use of '$progress += $number' later in pod =head1 DESCRIPTION Progress bars are handy - they tell you how much work has been done, how much is left to do and estimate how long it will take. But they can be fiddly! This module does the right thing in almost all cases in a really convenient way. =head1 FEATURES Lots - does all the best practice: Wraps L so there is no output unless the code is running interactively - lets you put them in cron scripts. Deals with minor updates - only refreshes the screen when it will change what the user sees so it is efficient. Completes the progress bar when the progress object is destroyed (explicitly or by going out of scope) - no more '99%' done. =head1 METHODS =head2 new # Either... my $progress = Term::ProgressBar::Simple->new($count); # ... or my $progress = Term::ProgressBar::Simple->new( { count => $count, # name => 'descriptive text', } ); Create a new progress bar. Either just pass in the number of things to do, or a config hash. See L for details. =cut sub new { my $class = shift; my $input = shift; # if we didn't get a hashref assume we got a count $input = { count => $input } unless ref $input; # create the T::PB::Q args with defaults. my $args = { ETA => 'linear', # only sensible choice name => 'progress', # seems reasonable %$input, }; my $tpq = Term::ProgressBar::Quiet->new($args); my $self = { args => $args, tpq => $tpq, count_so_far => 0, next_update => 0, }; return bless $self, $class; } =head2 increment ( ++ ) $progress++; Incrementing the object causes the progress display to be updated. It is smart about checking to see if the display needs to be updated. =head2 increment ( += ) $progress += $number_done; Sometimes you'll have done more than one step between updates. A good example is processing logfiles, where the time taken is relative to the size of the file. In this case code like this would give a better feel for the progress made: # Get the total size of all the files my $total_size = sum map { -s } @filenames; # Set up object with total size as steps to do my $progress = Term::ProgressBar::Simple->new($total_size); # process each file and increment by the size of each file foreach my $filename (@filenames) { process_the_file($filename); $progress += -s $filename; } =cut sub increment { my $self = shift; my $increment = shift || 1; $self->{count_so_far} += $increment; my $now = $self->{count_so_far}; if ( $now >= $self->{next_update} ) { $self->{next_update} = $self->{tpq}->update($now); } return $self; } =head2 message $progress->message('Copying $filename'); Output a message. This is very much like print, but we try not to disturb the terminal. =cut sub message { my($self, $message) = @_; $self->{tpq}->message($message); } # want to add this in a later version. # # while ( $progress-- ) { # # do something # } # # =head2 decrement # # # =cut # # sub _decrement { # my $self = shift; # # # increment and get the number done # my $number_done = $self->increment; # # # return number remaining, or zero if overshot # my $remaining = $self->{args}{count} - $number_done; # $remaining = 0 if $remaining < 0; # # return $self; # } sub DESTROY { my $self = shift; $self->{tpq}->update( $self->{args}{count} ) if $self->{tpq}; return; } =head1 SEE ALSO L & L =head1 GOTCHAS Not all operators are overloaded, so things might blow up in interesting ways. Patches welcome. =head1 THANKS Martyn J. Pearce for the orginal and great L. Leon Brocard for doing the hard work in L, and for submitting a patch with the code for C<+=>.. YAPC::EU::2008 for providing the venue and coffee whilst the first version of this module was written. =head1 AUTHOR Edmund von der Burg C<< >>. L =head1 BUGS There are no tests - there should be. The smart way would be to trap the output and check it is right. =head1 LICENCE AND COPYRIGHT Copyright (c) 2008, Edmund von der Burg C<< >>. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; Term-ProgressBar-Simple-0.03/Makefile.PL0000644000076500007650000000043611075714301016431 0ustar evdbevdbuse strict; use warnings; use ExtUtils::MakeMaker; WriteMakefile( 'NAME' => 'Term::ProgressBar::Simple', 'VERSION_FROM' => 'lib/Term/ProgressBar/Simple.pm', 'PREREQ_PM' => { # 'Term::ProgressBar::Quiet' => 0, }, ); Term-ProgressBar-Simple-0.03/MANIFEST0000644000076500007650000000030311150765404015605 0ustar evdbevdbCHANGES lib/Term/ProgressBar/Simple.pm Makefile.PL MANIFEST This list of files t/basic.t t/pod-coverage.t t/pod.t META.yml Module meta-data (added by MakeMaker) Term-ProgressBar-Simple-0.03/META.yml0000644000076500007650000000055211150765404015733 0ustar evdbevdb--- #YAML:1.0 name: Term-ProgressBar-Simple version: 0.03 abstract: ~ license: ~ generated_by: ExtUtils::MakeMaker version 6.32 distribution_type: module requires: Term::ProgressBar::Quiet: 0 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.2.html version: 1.2 Term-ProgressBar-Simple-0.03/t/0000755000076500007650000000000011150765404014723 5ustar evdbevdbTerm-ProgressBar-Simple-0.03/t/basic.t0000644000076500007650000000214411150764773016202 0ustar evdbevdb#!/usr/bin/perl -w use strict; use warnings; use lib 'lib'; use Test::More tests => 5; use Term::ProgressBar::Simple; use Time::HiRes qw( sleep ); { diag "Testing simple ++ increment"; my $progress = Term::ProgressBar::Simple->new(10_000); for ( 1 .. 10000 ) { $progress++; } pass 'tested ++'; } { diag "Testing ++ increment with early exit"; my $progress = Term::ProgressBar::Simple->new(10_000); for ( 1 .. 10000 ) { $progress++; } } pass 'tested ++ with early exit'; { diag "Testing += increment"; my @squares = map { $_**2 } 1 .. 20; my $total = 0; $total += $_ for @squares; my $progress = Term::ProgressBar::Simple->new($total); for (@squares) { sleep 0.2; $progress += $_; } pass 'tested +='; } { diag "Testing message"; my $progress = Term::ProgressBar::Simple->new(2); $progress->message('At the beginning'); $progress++; $progress->message('At the middle'); $progress++; $progress->message('At the end'); pass 'tested message'; } pass "made it to end of code"; Term-ProgressBar-Simple-0.03/t/pod-coverage.t0000644000076500007650000000046211075714301017461 0ustar evdbevdbuse strict; use warnings; use Test::More; eval "use Test::Pod::Coverage 1.00;"; plan skip_all => "Test::Pod::Coverage > 1.00 required" if $@; if ( $] >= 5.009 ) { eval "use Pod::Coverage 0.19;"; plan skip_all => "Pod::Coverage >= 0.19 required for perls >= 5.9" if $@; } all_pod_coverage_ok(); Term-ProgressBar-Simple-0.03/t/pod.t0000644000076500007650000000023411075714301015665 0ustar evdbevdbuse strict; use warnings; use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok();