package Fusion::Countdown; use strict; my $buffer_flusher = < EOT sub New { my $package = shift; my $text_only_input = shift; die "bad text_only_input ($text_only_input)" if ( defined($text_only_input) and $text_only_input ne "textonly" ); my $text_only = $text_only_input eq "textonly"; my $self = { count => 0, text_only => $text_only, destroyed => 0, }; bless $self, $package; _print_javascript_code() if ( not $text_only ); return $self; } sub start_count { my $self = shift; my $name = shift; if ( $self->{text_only} ) { print qq[$name -- 1\n]; $self->{count} = 1; } else { print "\n"; } print $buffer_flusher; } sub count { my $self = shift; if ( $self->{text_only} ) { my $number = ++$self->{count}; print qq[$number\n]; } else { print "\n"; } print $buffer_flusher; } sub done { my $self = shift; my $message = shift; if ( $self->{text_only} ) { print " -- $message
"; } else { print "\n"; } print $buffer_flusher; }; sub done_all_counts { my $self = shift; if ( $self->{text_only} ) { ; # do nothing } else { print "\n"; } $self->{destroyed} = 1; }; sub DESTROY { my $self = shift; $self->done_all_counts() if ( ! $self->{destroyed} ); } sub mark_error { my $self = shift; if ( $self->{text_only} ) { ; # do nothing } else { print "\n"; } } ############################### sub _javascript_literal_string { my $text = shift; # compress spaces $text =~ s/\n/ /g; $text =~ s/\s+/ /g; # turn into javascript code return Fusion::Toolbox::javascript_literal_string($text); } sub _print_javascript_code { print <<'EOT'; EOT }