From: Andy Grundman Date: Mon, 10 Oct 2005 23:02:17 +0000 (+0000) Subject: Added prepare_body_chunk method for upload progress support X-Git-Tag: 5.7099_04~1228 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=4bd82c41837b80f57b4ca6a611a20d11d4830980;hp=58f510c2a9483b35d078e1929acf0704a52cd544 Added prepare_body_chunk method for upload progress support --- diff --git a/Changes b/Changes index b654a76..d1dcc66 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ Tis file documents the revision history for Perl extension Catalyst. 5.50 + - Added prepare_body_chunk method as a hook for upload progress. - Fixed bug in uri_for method when base has no path. 5.49_01 2005-10-10 10:15:00 diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 3a52ccf..7cde581 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -904,6 +904,17 @@ sub prepare_body { } } +=item $c->prepare_body_chunk( $chunk ) + +Prepare a chunk of data before sending it to HTTP::Body. + +=cut + +sub prepare_body_chunk { + my $c = shift; + $c->engine->prepare_body_chunk( $c, @_ ); +} + =item $c->prepare_body_parameters Prepare body parameters. diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index f378d57..4170a08 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -14,6 +14,9 @@ __PACKAGE__->mk_accessors( qw/read_position read_length/ ); # Stringify to class use overload '""' => sub { return ref shift }, fallback => 1; +# Amount of data to read from input on each pass +our $CHUNKSIZE = 4096; + =head1 NAME Catalyst::Engine - The Catalyst Engine @@ -243,11 +246,21 @@ sub prepare_body { if ( $self->read_length > 0 ) { while ( my $buffer = $self->read( $c ) ) { - $c->request->{_body}->add( $buffer ); + $c->prepare_body_chunk( $buffer ); } } } +=item $self->prepare_body_chunk($c) + +=cut + +sub prepare_body_chunk { + my ( $self, $c, $chunk ) = @_; + + $c->request->{_body}->add( $chunk ); +} + =item $self->prepare_body_parameters($c) =cut @@ -382,7 +395,7 @@ sub read { } my $remaining = $self->read_length - $self->read_position; - $maxlength ||= $self->read_length; + $maxlength ||= $CHUNKSIZE; # Are we done reading? if ( $remaining <= 0 ) {