5 use base 'Class::Accessor::Fast';
7 use Params::Validate qw[];
8 use HTTP::Body::Context qw[];
9 use HTTP::Body::Parser qw[];
11 __PACKAGE__->mk_accessors( qw[ context parser ] );
17 HTTP::Body - HTTP Body Parser
23 sub handler : method {
24 my ( $class, $r ) = @_;
26 my $content_type = $r->headers_in->get('Content-Type');
27 my $content_length = $r->headers_in->get('Content-Length');
29 my $body = HTTP::Body->new( $content_type, $content_length );
30 my $length = $content_length;
34 $r->read( my $buffer, ( $length < 8192 ) ? $length : 8192 );
36 $length -= length($buffer);
41 my $uploads = $body->upload; # hashref
42 my $params = $body->param; # hashref
43 my $body = $body->body; # IO::Handle
56 Constructor taking arugments as a hashref. Requires a C<context> argument which
57 isa L<HTTP::Body::Context> object, and optional C<bufsize> (integer) and
58 C<parser> (L<HTTP::Body::Parser>) arguments.
60 If called with two arguments C<($content_type, $content_length),
61 L<HTTP::Body::Compat> will be used instead to maintain compatability with
67 my $class = ref $_[0] ? ref shift : shift;
69 # bring in compat for old API <= 0.6
71 require HTTP::Body::Compat;
72 return HTTP::Body::Compat->new(@_);
75 my $params = Params::Validate::validate_with(
79 type => Params::Validate::SCALAR,
84 type => Params::Validate::OBJECT,
85 isa => 'HTTP::Body::Context',
89 type => Params::Validate::OBJECT,
90 isa => 'HTTP::Body::Parser',
94 called => "$class\::new"
97 return bless( {}, $class )->initialize($params);
101 my ( $self, $params ) = @_;
103 my $bufsize = delete $params->{bufsize} || 65536;
105 $params->{parser} ||= HTTP::Body::Parser->new(
107 context => $params->{context}
110 while ( my ( $param, $value ) = each( %{ $params } ) ) {
111 $self->$param($value);
122 return shift->parser->eos;
130 return shift->parser->put(@_);
137 Christian Hansen, C<ch@ngmedia.com>
139 This pod written by Ash Berlin, C<ash@cpan.org>.
143 This library is free software. You can redistribute it and/or modify
144 it under the same terms as perl itself.