CGI-ProgressBar
view release on metacpan or search on metacpan
lib/CGI/ProgressBar.pm view on Meta::CPAN
)."
}
.pblib_block_off { border:1px solid white; background: white; }
.pblib_block_on { border:1px solid blue; background: navy; }
";
if ($self->{progress_bar}->{label}){
$CSS .=".pblib_number {
text-align: right;
border: 1px solid transparent;
}";
}
$self->{progress_bar}->{css} = $CSS;
}
=head1 BUGS, CAVEATS, TODO
=over 4
=item One bar per page
This may change.
=item Parameter passing doesn't match F<CGI.pm>
But it will in the next release if you ask me for it.
=item C<colors> not implimented
I'd like to see here something like the C<Tk::ProgressBar::colors>;
not because I've ever used it, but because it might be cool.
=item Horizontal orientation only
You can get around this by adjusting the CSS, but you'd rather not.
And even if you did, the use of C<-label> might not look very nice
unless you did something quite fancy. So the next version (or so)
will support an C<-orientation> option.
=item Inline CSS and JS
Because it's easiest for me. I suppose some kind of over-loading of
the C<CGI::start_html> would be possible, but then I'd have to check
it, and maybe update it, every time F<CGI.pm> was updated, which I
don't fancy.
=cut
1;
__END__
=head1 CGI UPLOAD HOOK
I'm not convinced it works yet, even in F<CGI.pm> verion 3.15.
If anyone knows otherwise, please mail me: I have spent an hour
on the below, and it seems that the hook is called more times
than necessary....
=head2 PROCESS
The script has to both upload and process a file.
The hook script is called when the object is constructed,
thus before any headers can be output. There the hook needs
to output its own headers, and we only output headers for
the 'select file' page when the hook has not been called.
The first tiem the hook is called, then, it outputs HTTP
headers and begins the page. This is fine.
The next time it is called, it outputs the JS call to
update the progress bar. This is fine.
The problem is that the hook seems to be called many more
times than necessary.
=back
=head2 SOURCE
#!/usr/local/bin/perl
use warnings;
use strict;
use CGI::ProgressBar qw/:standard/;
$| = 1; # Do not buffer output
my $data;
my $hook_called;
my $cgi = CGI->new(\&bar_hook, $data);
if (not $hook_called){
print $cgi->header,
$cgi->start_html( -title=>'A Simple Example', ),
$cgi->h1('Simple Upload-hook Example');
}
print $cgi->start_form( -enctype=>'application/x-www-form-urlencoded'),
$cgi->filefield( 'uploaded_file'),
$cgi->submit,
$cgi->end_form,p;
if ($cgi->param('uploaded_file')){
print 'uploaded_file: '.param('uploaded_file');
}
sub bar_hook {
my ($filename, $buffer, $bytes, $data) = @_;
if (not $hook_called){
print header,
start_html( -title=>'Simple Upload-hook Example', ),
h1('Uploading'),
p(
"Have to read <var>$ENV{CONTENT_LENGTH}</var> in blocks of <var>$bytes</var>, total blocks should be ",
($ENV{CONTENT_LENGTH}/$bytes)
),
progress_bar( -from=>1, -to=>($ENV{CONTENT_LENGTH}/$bytes), -debug=>1 );
$hook_called = 1;
} else {
# Called every $bytes, I would have thought.
# But calls seem to go on much longer than $ENV{CONTENT_LENGTH} led me to believe they ought:
print update_progress_bar;
print "$ENV{CONTENT_LENGTH} ... $total_bytes ... $hook_called ... div="
.($hook_called/$total_bytes)
."<br>"
}
sleep 1;
$hook_called += $total_bytes;
}
print $cgi->hide_progress_bar;
if ($hook_called){
print p('All done after '.$hook_called.' calls');
}
print $cgi->end_html;
exit;
=head1 AUTHOR
Lee Goddard C<lgoddard -in- cpan -dat- org>, C<cpan -ut- leegoddard -dut- net>
=head2 COPYRIGHT
Copyright (C) Lee Goddard, 2002, 2003, 2005. 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.
=head1 KEYWORDS
HTML, CGI, progress bar, widget
=head1 SEE ALSO
L<perl>. L<CGI>, L<Tk::ProgressBar>,
=head1 MODIFICATIONS
25 March 2004: Updated the POD.^
( run in 1.452 second using v1.01-cache-2.11-cpan-b16cb0d3907 )