5 use vars
qw($VERSION @ISA @EXPORT @EXPORT_OK);
10 @EXPORT_OK = qw($output);
14 $output = '_output'->new;
20 my $stdout_isatty = -t STDOUT;
21 my $stderr_isatty = -t STDERR;
25 my $class = ref($proto) || $proto;
27 bless ($self, $class);
29 my $progress_enabled = \${$self->{PROGRESS_ENABLED}};
30 my $progress = \${$self->{PROGRESS}};
31 my $last_progress = \${$self->{LAST_PROGRESS}};
32 my $last_time = \${$self->{LAST_TIME}};
33 my $progress_count = \${$self->{PROGRESS_COUNT}};
34 my $prefix = \${$self->{PREFIX}};
35 my $prefix_callback = \${$self->{PREFIX_CALLBACK}};
37 $$progress_enabled = 1;
43 $$prefix_callback = undef;
56 my $progress_enabled = \${$self->{PROGRESS_ENABLED}};
58 $$progress_enabled = 1;
61 sub disable_progress {
63 my $progress_enabled = \${$self->{PROGRESS_ENABLED}};
65 $$progress_enabled = 0;
70 my $progress_enabled = \${$self->{PROGRESS_ENABLED}};
71 my $progress = \${$self->{PROGRESS}};
72 my $last_progress = \${$self->{LAST_PROGRESS}};
73 my $progress_count = \${$self->{PROGRESS_COUNT}};
77 if($$progress_enabled) {
78 if($$progress_count > 0 && $$progress && $stderr_isatty) {
79 print STDERR $$progress;
80 $$last_progress = $$progress;
87 my $progress_enabled = \${$self->{PROGRESS_ENABLED}};
88 my $progress = \${$self->{PROGRESS}};
89 my $last_progress = \${$self->{LAST_PROGRESS}};
90 my $progress_count = \${$self->{PROGRESS_COUNT}};
94 if($$progress_enabled) {
95 if($$last_progress && $stderr_isatty) {
97 for (1..length($$last_progress)) {
100 print STDERR $message;
101 undef $$last_progress;
106 sub update_progress {
108 my $progress_enabled = \${$self->{PROGRESS_ENABLED}};
109 my $progress = \${$self->{PROGRESS}};
110 my $last_progress = \${$self->{LAST_PROGRESS}};
112 if($$progress_enabled) {
115 if($$last_progress) {
116 for (1..length($$last_progress)) {
120 my $diff = length($$last_progress)-length($$progress);
130 print STDERR $prefix . $$progress . $suffix;
131 $$last_progress = $$progress;
137 my $progress = \${$self->{PROGRESS}};
138 my $last_time = \${$self->{LAST_TIME}};
140 my $new_progress = shift;
141 if(defined($new_progress)) {
142 if(!defined($$progress) || $new_progress ne $$progress) {
143 $$progress = $new_progress;
145 $self->update_progress;
155 my $progress = \${$self->{PROGRESS}};
156 my $last_time = \${$self->{LAST_TIME}};
161 if($time - $$last_time > 0) {
162 $self->update_progress;
169 my $prefix = \${$self->{PREFIX}};
170 my $prefix_callback = \${$self->{PREFIX_CALLBACK}};
172 my $new_prefix = shift;
173 if(defined($new_prefix)) {
174 if(!defined($$prefix) || $new_prefix ne $$prefix) {
175 $$prefix = $new_prefix;
176 $$prefix_callback = undef;
183 sub prefix_callback {
186 my $prefix = \${$self->{PREFIX}};
187 my $prefix_callback = \${$self->{PREFIX_CALLBACK}};
190 $$prefix_callback = shift;
198 my $prefix = \${$self->{PREFIX}};
199 my $prefix_callback = \${$self->{PREFIX_CALLBACK}};
201 $self->hide_progress if $stdout_isatty;
202 if(defined($$prefix)) {
203 print $$prefix . $message;
204 } elsif(defined($$prefix_callback)) {
205 print &{$$prefix_callback}() . $message;
209 $self->show_progress if $stdout_isatty;