blib/lib/LWP/UserAgent/ProgressBar.pm

filter: Statementstmt 97.9% 48 / 49 Branchbran 58.3% 7 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 91.6% 66 / 72 CC 8 SCAR 11.3
CC
8
Cov
90%
_request_with_progress
5.1
__ANON__
4.3
BEGIN
1.0
CRAP 3.1
↑ Summary
1 2 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package LWP::UserAgent::ProgressBar;
6 2 our $VERSION = '1.100810';
7 # ABSTRACT: An LWP user agent that can display a progress bar
8 2 ▶use Term::ProgressBar;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use base 'LWP::UserAgent';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶sub post_with_progress {
Subroutine post_with_progress: called CC=1 SCAR=0.0
Pod documented
12 1 my ($self, $url, $form, %args) = @_;
13 1 $self->_request_with_progress('post', $url, $form, %args);
14 }
15  
16 1 ▶sub get_with_progress {
Subroutine get_with_progress: called CC=1 SCAR=0.0
Pod documented
17 1 my ($self, $url, %args) = @_;
18 1 $self->_request_with_progress('get', $url, undef, %args);
19 }
20  
21 2 ▶sub _request_with_progress {
Subroutine _request_with_progress: called CC=5 SCAR=16.2
22 2 my ($self, $req, $url, $form, %args) = @_;
23  
24 # don't buffer the prints to make the status update
25 2 local $| = 1;
26 2 my $bar_name;
27 2 ▶ if (defined $args{bar_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"bar_name"}) 2 0 2
28 2 $bar_name = $args{bar_name};
29 2 delete $args{bar_name};
30 }
31 2 ▶ my $progress = Term::ProgressBar->new(
Branch: 1 branch
BranchTrueFalseTotal
defined $bar_name ? : 2 0 2
32 { count => 1024,
33 (defined $bar_name ? (name => $bar_name) : ()),
34 ETA => 'linear',
35 }
36 );
37 2 $progress->minor(0); # turns off the floating asterisks.
38 2 $progress->max_update_rate(1); # only relevant when ETA is used.
39 2 my $did_set_target = 0;
40 2 my $received_size = 0;
41 2 my $next_update = 0;
42 2 my $content = '';
43 2 delete $args{$_} for qw(:content_cb :read_size_hint);
44 1 ▶ $args{':content_cb'} = sub {
Subroutine __ANON__: called CC=4 SCAR=14.6
45 1 my ($data, $cb_response, $protocol) = @_;
46 1 ▶ unless ($did_set_target) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($did_set_target) 1 0 1
47 1 ▶ if (my $content_length = $cb_response->content_length) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $content_length = $cb_response->content_length) { } 1 0 1
48 1 $progress->target($content_length);
49 1 $did_set_target = 1;
50 } else {
51 0 $progress->target($received_size + 2 * length $data);
52 }
53 }
54 1 $received_size += length $data;
55 1 $content .= $data;
56 1 ▶ $next_update = $progress->update($received_size)
Branch: 1 branch
BranchTrueFalseTotal
if $received_size >= $next_update 1 0 1
57 if $received_size >= $next_update;
58 2 };
59 2 $args{':read_size_hint'} = 8192;
60 2 ▶ my $response =
Branch: 1 branch
BranchTrueFalseTotal
$req eq 'get' ? : 1 1 2
61 $self->$req($url, $req eq 'get' ? (%$form, %args) : ($form, %args));
62 2 print "\n";
63 2 $response->content($content);
64 2 $response;
65 }
66 2 1;
67  
68  
69 __END__
↑ Summary