CGI::ProgressBar - CGI.pm sub-class with a progress bar object
use lib '..'; use CGI::ProgressBar qw/:standard/; $| = 1; # Do not buffer output my $steps = 10; print header, start_html('A Simple Example'), h1('A Simple Example'), p('This example will fill the screen with nonsense between updates to a progress bar.'), progress_bar( -from=>1, -to=>$steps, -blocks=>$steps ); for (1..$steps){ print update_progress_bar; # Simulate being busy/sleep 2; print rand>0.5 ? chr 47 : chr 92 for 0 .. 100000; } print hide_progress_bar; print p('All done.'); print end_html; exit;
This module provides a progress bar for web browsers.
It aims to require that the recipient client have a minimum of JavaScript 1.0, HTML 4.0, ancd CSS/1, but this has yet to be tested.
All feedback would be most welcome. Address at the end of the POD.
CGI
progress_bar update_progress_bar hide_progress_bar
The module sub-classes CGI.pm, providing three additional methods (or functions, depending on your taste), each of which are detailed below.
Simply replace your "use CGI qw//;" with "use CGI::ProgressBar qw//;".
Treat each new function as any other CGI.pm HTML-producing routine with the exception that the arguments should be supplied as in OOP form. In other words, the following are all the same:
my $html = $query->progress_bar; my $html = progress_bar; my $html = progress_bar(from=>1, to=>10); my $html = $query->progress_bar(from=>1, to=>10); my $html = $query->progress_bar(-to=>10);
This will probably change if someone would like it to.
Returns mark-up that instantiates a progress bar. Currently that is HTML and JS, but perhaps the JS ought to go into the head.
The progress bar itself is an object in this class, stored in the calling (CGI) object - specifically in the field progress_bar, which we create as an array.
progress_bar
Values which the progress bar spans. Defaults: 0, 100.
The number of blocks to appear in the progress bar. Default: 100. You probably want to link this to from and to.
from
to
The width and height of the progress bar, in pixels. Cannot accept percentages (yet). Defaults: 400, 20.
The amount of space between blocks, in pixels. Default: 1.
Supply this parameter with a true value to have a numerical display of progress.
Most HTML elements on the page have id attributes. These can be accessed through the layer_id field, which is a hash with the follwoing keys relating to the id value:
id
layer_id
The form which contains everything we display.
form
The div containing everything we display.
div
This value is used as a prefixed for the id of each block of the bar, with the suffix being a number incremented from 1.
1
The digits being updated as the bar progresses, if the option is enabled.
Updates the progress bar.
Hides the progress bar.
A DIV containing the whole progress bar, including any accessories (such as the label). The only attribute used by this module is width, which is set dynamically. The rest is up to you. A good start is:
DIV
width
padding: 2 px; border: solid black 1px; text-align: center;
An individual block within the status bar. The following attributes are set dynamically: width, height, margin-right.
height
margin-right
Formatting for the label text (part of which is actually an input type='text' element. border and text-align are used here, and the whole appears centred within a table.
label
input type='text'
border
text-align
table
This may change.
But it will in the next release if you ask me for it.
colors
I'd like to see here something like the Tk::ProgressBar::colors; not because I've ever used it, but because it might be cool.
Tk::ProgressBar::colors
You can get around this by adjusting the CSS, but you'd rather not. And even if you did, the use of -label might not look very nice. So the next version will support an -orientation option.
-label
-orientation
Because it's easiest for me. I suppose some kind of over-loading of the CGI::start_html would be possible, but then I'd have to check it, and maybe update it, every time CGI.pm was updated, which I don't fancy.
CGI::start_html
Lee Goddard <lgoddard -at- cpan -dot- org>
Copyright (C) Lee Goddard, 2002-2003. All Rights Reserved. This software is made available under the same terms as Perl itself. You may use and redistribute this software under the same terms as Perl itself.
HTML, CGI, progress bar, widget
perl. CGI, Tk::ProgressBar,
25 March 2004
Updated the POD
3 POD Errors
The following errors were encountered while parsing the POD:
'=item' outside of any '=over'
You forgot a '=back' before '=head1'
To install CGI::ProgressBar, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CGI::ProgressBar
CPAN shell
perl -MCPAN -e shell install CGI::ProgressBar
For more information on module installation, please visit the detailed CPAN module installation guide.