/usr/share/perl5/Term/ProgressBar/IO.pm is in libterm-progressbar-perl 2.16-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | package Term::ProgressBar::IO;
use strict;
use warnings;
our $VERSION = '2.16';
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
# Copyright 2014 by Don Armstrong <don@donarmstrong.com>.
=head1 NAME
Term::ProgressBar::IO -- Display a progress bar while reading from a seekable filehandle
=head1 SYNOPSIS
my $pb = Term::ProgressBar::IO->new($fh);
while (<$fh>) {
# do something
$pb->update();
}
=head1 DESCRIPTION
Displays a progress bar using L<Term::ProgressBar> which corresponds
to reading from a filehandle.
This module inherits from L<Term::ProgressBar> and has all of its
options.
=head1 BUGS
None known.
=cut
use parent qw(Term::ProgressBar);
use Carp;
use Fcntl qw(:seek);
=head1 METHODS
=head2 new
Create and return a new Term::ProgressBar::IO instance.
=over
=item ARGUMENTS
=over
=item count
A valid filehandle or item count. L<IO::Uncompress> filehandles are
also properly handled.
=item OTHER ARGUMENTS
All other arguments are documented in L<Term::ProgressBar>
=back
=back
=cut
sub init {
my $self = shift;
my $count;
if (@_==2) {
$count = $_[1];
} else {
croak
sprintf("Term::ProgressBar::IO::new We don't handle this many arguments: %d",
scalar @_)
if @_ != 1;
}
my %config;
if ( UNIVERSAL::isa ($_[0], 'HASH') ) {
($count) = @{$_[0]}{qw(count)};
%config = %{$_[0]};
} else {
($count) = @_;
}
if (ref($count) and $count->can("seek")) {
$self->{__filehandle} = $count;
$count = $self->__determine_max();
}
$config{count} = $count;
$self->SUPER::init(\%config);
}
=head2 update
Automatically update the progress bar based on the position of the
filehandle given at construction time.
=over
=item ARGUMENTS
=over
=item so_far
Current progress point; this defaults to the current position of the
filehandle. [You probably don't actually want to ever give this.]
=back
=back
=cut
sub update {
my $self = shift;
my $count = $self->__determine_count();
$self->SUPER::update(scalar @_? @_ : $count);
}
sub __determine_max {
my $self = shift;
# is this an IO::Uncompress handle?
my $max = 0;
if ($self->{__filehandle}->can('getHeaderInfo')) {
$self->{__filehandle} = *$self->{__filehandle}{FH};
}
eval {
my $cur_pos = $self->{__filehandle}->tell;
$self->{__filehandle}->seek(0,SEEK_END);
$max = $self->{__filehandle}->tell;
$self->{__filehandle}->seek($cur_pos,SEEK_SET);
};
return $max;
}
sub __determine_count {
my $self = shift;
my $count = 0;
eval {
$count = $self->{__filehandle}->tell;
};
return $count;
}
1;
__END__
|