6 use List::Util qw[ first ];
11 'application/octet-stream' => 'HTTP::Body::OctetStream',
12 'application/x-www-form-urlencoded' => 'HTTP::Body::UrlEncoded',
13 'multipart/form-data' => 'HTTP::Body::MultiPart'
18 HTTP::Body - HTTP Body Parser
35 my ( $class, $content_type, $content_length ) = @_;
38 Carp::croak( $class, '->new( $content_type, $content_length )' );
41 my $type = first { index( lc($content_type), $_ ) >= 0 } keys %{$TYPES};
42 my $body = $TYPES->{ $type || 'application/octet-stream' };
53 content_length => $content_length,
54 content_type => $content_type,
61 bless( $self, $body );
73 if ( defined $_[0] ) {
74 $self->{buffer} .= $_[0];
75 $self->{length} += length( $_[0] );
78 unless ( $self->state eq 'done' ) {
82 return ( $self->length - $self->content_length );
91 $self->{body} = shift if @_;
100 return shift->{buffer};
108 return shift->{content_length};
116 return shift->{content_type};
132 return shift->{length};
140 Carp::croak('Define abstract method spin() in implementation');
149 $self->{state} = shift if @_;
150 return $self->{state};
162 my ( $name, $value ) = @_;
164 if ( exists $self->{param}->{$name} ) {
165 for ( $self->{param}->{$name} ) {
166 $_ = [$_] unless ref($_) eq "ARRAY";
171 $self->{param}->{$name} = $value;
175 return $self->{param};
187 my ( $name, $upload ) = @_;
189 if ( exists $self->{upload}->{$name} ) {
190 for ( $self->{upload}->{$name} ) {
191 $_ = [$_] unless ref($_) eq "ARRAY";
192 push( @$_, $upload );
196 $self->{upload}->{$name} = $upload;
200 return $self->{upload};
207 Christian Hansen, C<ch@ngmedia.com>
208 Messed up by Sebastian Riedel
212 This library is free software . You can redistribute it and/or modify
213 it under the same terms as perl itself.