"Fossies" - the Fresh Open Source Software Archive

Member "libwww-perl-6.43/xt/author/misc/get-callback" (26 Nov 2019, 586 Bytes) of package /linux/www/libwww-perl-6.43.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/perl
    2 use strict;
    3 use warnings;
    4 
    5 use LWP::UserAgent;
    6 
    7 my $url = shift || "";
    8 $url = "http://localhost:8080/$url" unless $url =~ /:/;
    9 
   10 my $tot = 0;
   11 my $ct_len;
   12 my $ua = LWP::UserAgent->new;
   13 my $res = $ua->request(HTTP::Request->new("GET", $url), \&data);
   14 
   15 sub data {
   16     my ($data, $response) = @_;
   17     my $len = length $data;
   18     $tot += $len;
   19     print "Got $len bytes";
   20     unless ($ct_len) {
   21         $ct_len = $response->header("Content-Length");
   22     }
   23     if ($ct_len) {
   24         printf " (%.1f%% done)", $tot/$ct_len*100.0;
   25     }
   26     print "\n";
   27 }
   28 
   29 print $res->as_string;