CGI-ProgressBar
view release on metacpan or search on metacpan
lib/CGI/ProgressBar.pm view on Meta::CPAN
no strict 'refs';
foreach (qw/ progress_bar update_progress_bar hide_progress_bar/){
*{caller(0).'::'.$_} = \&{__PACKAGE__.'::'.$_};
}
use strict 'refs';
}
=head1 USE
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//;".
Make sure you are aware of your output buffer size: C<$|=$smothingsmall>.
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.
=head1 FUNCTIONS/METHODS
=head2 FUNCTION/METHOD progress_bar
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 (C<CGI>) object - specifically
in the field C<progress_bar>, which we create.
(TODO: Make this field an array to allow multiple bars per page.)
=over 4
=item from
=item to
Values which the progress bar spans.
Defaults: 0, 100.
=item orientation
If set to C<vertical> displays the bar as a strip down the screen; otherwise,
places it across the screen.
=item width
=item height
The width and height of the progress bar, in pixels. Cannot accept
percentages (yet). Defaults: 400, 20, unless you specify C<orientation>
as C<vertical>, in which case this is reversed.
=item blocks
The number of blocks to appear in the progress bar.
Default: 10. You probably want to link this to C<from> and C<to>
or better still, leave it well alone: it may have been a mistake to even include it.
C<steps> is an alias for this attribute.
=item label
Supply this parameter with a true value to have a numerical
display of progress. Default is not to display it.
=item layer_id
Most HTML elements on the page have C<id> attributes. These
can be accessed through the C<layer_id> field, which is a hash
with the follwoing keys relating to the C<id> value:
=item mycss
Custom CSS to be written inline (ugh) after any system CSS.
=over 4
=item form
The C<form> which contains everything we display.
=item container
The C<div> containing everything we display.
=item block
This value is used as a prefixed for the C<id> of each block of the bar,
with the suffix being a number incremented from C<1>.
=item number
The digits being updated as the bar progresses, if the option is enabled.
=back
=back
=cut
our $CSS = '';
sub progress_bar {
local $_;
my ($self,%args);
($self,@_) = &CGI::self_or_default(@_);
my $pb = bless {
_updates=> 0, debug => undef,
mycss => '', orientation => 'horizontal',
from => 1, to => 100, width => '400',
( run in 1.768 second using v1.01-cache-2.11-cpan-39bf76dae61 )