How can I create a progress bar using Term :: ProgressBar method with LWP :: UserAgent post method?
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common;
use HTML::TreeBuilder;
use Cwd 'realpath';
use warnings;
use strict;
my $ua = LWP::UserAgent->new();
my $response = $ua->request(
POST 'http://mydomain.com/upload.php',
'Content-Type' => 'multipart/form-data',
'Content' => [ 'fileup' => [realpath(shift)] ],
);
my $tree = HTML::TreeBuilder->new_from_content($response->decoded_content);
my $image = $tree->look_down('_tag','a',sub { $_[0]->{href} =~ /http:\/\/images.mydomain.com\/images\/[^\?]/ if $_[0]->{href}})->{href};
print "\n".$image."\n\n";
How do I create a progress bar for this script showing the loading ?: content_cb allows for progress bars for the response after the image is loaded, so how can I do that for the loading itself?
+2
a source to share
1 answer
This doesn't answer your original question, but maybe you can use the built-in progress bar:
$ua->show_progress
$ua->show_progress( $boolean )
Get/set a value indicating whether a progress bar should be displayed on on the
terminal as requests are processed. The default is FALSE.
(from LWP :: UserAgent POD)
0
a source to share