Changeset 21800 for lang/perl/LWP-UserAgent-ProgressBar/trunk
- Timestamp:
- 10/21/08 21:54:59 (5 years ago)
- Location:
- lang/perl/LWP-UserAgent-ProgressBar/trunk
- Files:
-
- 3 modified
-
Changes (modified) (1 diff)
-
lib/LWP/UserAgent/ProgressBar.pm (modified) (4 diffs)
-
t/01_misc.t (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/LWP-UserAgent-ProgressBar/trunk/Changes
r16488 r21800 1 1 Revision history for Perl extension LWP-UserAgent-ProgressBar 2 3 0.04 Thu Oct 21 21:36:48 JST 2008 (Ktat <ktat at cpan.org>) 4 - add post_with_progress method for POST request. 2 5 3 6 0.03 Thu Jul 25 15:27:43 CEST 2008 (Marcel Gruenauer <marcel@cpan.org>) -
lang/perl/LWP-UserAgent-ProgressBar/trunk/lib/LWP/UserAgent/ProgressBar.pm
r16588 r21800 9 9 10 10 11 our $VERSION = '0.0 3';11 our $VERSION = '0.04'; 12 12 13 sub post_with_progress { 14 my ($self, $url, $form, %args) = @_; 15 $self->_request_with_progress('post', $url, $form, %args); 16 } 13 17 14 18 sub get_with_progress { 15 19 my ($self, $url, %args) = @_; 20 $self->_request_with_progress('get', $url, undef, %args); 21 } 22 23 sub _request_with_progress { 24 my ($self, $req, $url, $form, %args) = @_; 16 25 17 26 # don't buffer the prints to make the status update … … 38 47 39 48 delete $args{$_} for qw(:content_cb :read_size_hint); 49 $args{':content_cb'} = sub { 50 my ($data, $cb_response, $protocol) = @_; 40 51 41 my $response = $self->get( 42 $url, 43 %args, 44 ':content_cb' => sub { 45 my ($data, $cb_response, $protocol) = @_; 52 unless ($did_set_target) { 53 if (my $content_length = $cb_response->content_length) { 54 $progress->target($content_length); 55 $did_set_target = 1; 56 } else { 57 $progress->target($received_size + 2 * length $data); 58 } 59 } 46 60 47 unless ($did_set_target) { 48 if (my $content_length = $cb_response->content_length) { 49 $progress->target($content_length); 50 $did_set_target = 1; 51 } else { 52 $progress->target($received_size + 2 * length $data); 53 } 54 } 61 $received_size += length $data; 62 $content .= $data; 55 63 56 $received_size += length $data;57 $ content .= $data;64 $next_update = $progress->update($received_size) if 65 $received_size >= $next_update; 58 66 59 $next_update = $progress->update($received_size) if60 $received_size >= $next_update;67 }; 68 $args{':read_size_hint'} = 8192; 61 69 62 }, 63 ':read_size_hint' => 8192, 64 ); 70 my $response = $self->$req($url, $req eq 'get' ? (%$form, %args) : ($form, %args)); 71 65 72 print "\n"; 66 73 $response->content($content); … … 100 107 101 108 Takes the same arguments as L<LWP::UserAgent>'s C<get()>, but overrides the 109 C<:content_cb> and C<:read_size_hint> arguments. During download, a progress 110 bar is displayed. 111 112 =item post_with_progress 113 114 Takes the same arguments as L<LWP::UserAgent>'s C<post()>, but overrides the 102 115 C<:content_cb> and C<:read_size_hint> arguments. During download, a progress 103 116 bar is displayed. … … 143 156 144 157 Marcel GrE<uuml>nauer, C<< <marcel@cpan.org> >> 158 Ktat C<< ktat at cpan.org >> 145 159 146 160 =head1 COPYRIGHT AND LICENSE -
lang/perl/LWP-UserAgent-ProgressBar/trunk/t/01_misc.t
r9783 r21800 6 6 use File::Spec; 7 7 use LWP::UserAgent::ProgressBar; 8 use Test::More tests => 2;8 use Test::More tests => 4; 9 9 use Test::Differences; 10 10 … … 25 25 eq_or_diff $content, $self_content, 'content matches'; 26 26 27 $self_url = 'http://search.cpan.org/search'; 28 $response = LWP::UserAgent::ProgressBar->new->post_with_progress( 29 $self_url, {query => 'LWP'}, bar_name => '# ' 30 ); 31 32 ok($response->is_success, 'successful download'); 33 ok($response->content, 'content is not empty'); 34
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)