1 # This module is part of IO, and is released
2 # under the terms of the GPL version 3, or any later version at your option. See the
3 # file README and COPYING for more information.
4 # Copyright 2014 by Don Armstrong <don@donarmstrong.com>.
6 package Term::ProgressBar::IO;
10 Term::ProgressBar::IO -- Display a progress bar while reading from a seekable filehandle
14 my $pb = Term::ProgressBar::IO->new($fh);
22 Displays a progress bar using L<Term::ProgressBar> which corresponds
23 to reading from a filehandle.
33 use vars qw($VERSION $DEBUG);
35 use parent qw(Term::ProgressBar);
41 $DEBUG = 0 unless defined $DEBUG;
51 sprintf("Term::ProgressBar::IO::new We don't handle this many arguments: %d",
56 if ( UNIVERSAL::isa ($_[0], 'HASH') ) {
57 ($count) = @{$_[0]}{qw(count)};
62 if (ref($count) and $count->can("seek")) {
63 $self->{__filehandle} = $count;
64 $count = $self->__determine_max();
66 $config{count} = $count;
67 $self->SUPER::init(\%config);
72 my $count = $self->__determine_count();
73 $self->SUPER::update(scalar @_? @_ : $count);
78 # is this an IO::Uncompress handle?
80 if ($self->{__filehandle}->can('getHeaderInfo')) {
81 $self->{__filehandle} = *$self->{__filehandle}{FH};
84 my $cur_pos = $self->{__filehandle}->tell;
85 $self->{__filehandle}->seek(0,SEEK_END);
86 $max = $self->{__filehandle}->tell;
87 $self->{__filehandle}->seek($cur_pos,SEEK_SET);
92 sub __determine_count {
96 $count = $self->{__filehandle}->tell;