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}};
142 $self->update_progress;
148 my $progress = \${$self->{PROGRESS}};
149 my $last_time = \${$self->{LAST_TIME}};
154 if($time - $$last_time > 0) {
155 $self->update_progress;
162 my $prefix = \${$self->{PREFIX}};
163 my $prefix_callback = \${$self->{PREFIX_CALLBACK}};
166 $$prefix_callback = undef;
169 sub prefix_callback {
172 my $prefix = \${$self->{PREFIX}};
173 my $prefix_callback = \${$self->{PREFIX_CALLBACK}};
176 $$prefix_callback = shift;
184 my $prefix = \${$self->{PREFIX}};
185 my $prefix_callback = \${$self->{PREFIX_CALLBACK}};
187 $self->hide_progress if $stdout_isatty;
188 if(defined($$prefix)) {
189 print $$prefix . $message;
190 } elsif(defined($$prefix_callback)) {
191 print &{$$prefix_callback}() . $message;
195 $self->show_progress if $stdout_isatty;